annotate jquery-ui/development-bundle/ui/jquery.ui.dialog.js @ 51:5d636ba6b9cb default tip

Merge with b5d89c03f9585013d464f0240f6d82751b77186f
author dwinter
date Thu, 05 Dec 2013 13:24:57 +0100
parents b2e4605f20b2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
1 /*
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
2 * jQuery UI Dialog 1.8.11
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
3 *
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
4 * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
5 * Dual licensed under the MIT or GPL Version 2 licenses.
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
6 * http://jquery.org/license
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
7 *
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
8 * http://docs.jquery.com/UI/Dialog
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
9 *
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
10 * Depends:
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
11 * jquery.ui.core.js
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
12 * jquery.ui.widget.js
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
13 * jquery.ui.button.js
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
14 * jquery.ui.draggable.js
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
15 * jquery.ui.mouse.js
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
16 * jquery.ui.position.js
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
17 * jquery.ui.resizable.js
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
18 */
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
19 (function( $, undefined ) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
20
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
21 var uiDialogClasses =
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
22 'ui-dialog ' +
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
23 'ui-widget ' +
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
24 'ui-widget-content ' +
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
25 'ui-corner-all ',
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
26 sizeRelatedOptions = {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
27 buttons: true,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
28 height: true,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
29 maxHeight: true,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
30 maxWidth: true,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
31 minHeight: true,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
32 minWidth: true,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
33 width: true
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
34 },
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
35 resizableRelatedOptions = {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
36 maxHeight: true,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
37 maxWidth: true,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
38 minHeight: true,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
39 minWidth: true
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
40 };
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
41
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
42 $.widget("ui.dialog", {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
43 options: {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
44 autoOpen: true,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
45 buttons: {},
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
46 closeOnEscape: true,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
47 closeText: 'close',
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
48 dialogClass: '',
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
49 draggable: true,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
50 hide: null,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
51 height: 'auto',
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
52 maxHeight: false,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
53 maxWidth: false,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
54 minHeight: 150,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
55 minWidth: 150,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
56 modal: false,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
57 position: {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
58 my: 'center',
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
59 at: 'center',
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
60 collision: 'fit',
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
61 // ensure that the titlebar is never outside the document
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
62 using: function(pos) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
63 var topOffset = $(this).css(pos).offset().top;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
64 if (topOffset < 0) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
65 $(this).css('top', pos.top - topOffset);
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
66 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
67 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
68 },
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
69 resizable: true,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
70 show: null,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
71 stack: true,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
72 title: '',
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
73 width: 300,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
74 zIndex: 1000
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
75 },
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
76
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
77 _create: function() {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
78 this.originalTitle = this.element.attr('title');
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
79 // #5742 - .attr() might return a DOMElement
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
80 if ( typeof this.originalTitle !== "string" ) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
81 this.originalTitle = "";
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
82 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
83
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
84 this.options.title = this.options.title || this.originalTitle;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
85 var self = this,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
86 options = self.options,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
87
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
88 title = options.title || '&#160;',
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
89 titleId = $.ui.dialog.getTitleId(self.element),
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
90
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
91 uiDialog = (self.uiDialog = $('<div></div>'))
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
92 .appendTo(document.body)
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
93 .hide()
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
94 .addClass(uiDialogClasses + options.dialogClass)
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
95 .css({
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
96 zIndex: options.zIndex
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
97 })
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
98 // setting tabIndex makes the div focusable
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
99 // setting outline to 0 prevents a border on focus in Mozilla
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
100 .attr('tabIndex', -1).css('outline', 0).keydown(function(event) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
101 if (options.closeOnEscape && event.keyCode &&
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
102 event.keyCode === $.ui.keyCode.ESCAPE) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
103
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
104 self.close(event);
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
105 event.preventDefault();
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
106 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
107 })
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
108 .attr({
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
109 role: 'dialog',
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
110 'aria-labelledby': titleId
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
111 })
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
112 .mousedown(function(event) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
113 self.moveToTop(false, event);
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
114 }),
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
115
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
116 uiDialogContent = self.element
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
117 .show()
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
118 .removeAttr('title')
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
119 .addClass(
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
120 'ui-dialog-content ' +
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
121 'ui-widget-content')
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
122 .appendTo(uiDialog),
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
123
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
124 uiDialogTitlebar = (self.uiDialogTitlebar = $('<div></div>'))
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
125 .addClass(
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
126 'ui-dialog-titlebar ' +
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
127 'ui-widget-header ' +
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
128 'ui-corner-all ' +
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
129 'ui-helper-clearfix'
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
130 )
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
131 .prependTo(uiDialog),
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
132
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
133 uiDialogTitlebarClose = $('<a href="#"></a>')
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
134 .addClass(
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
135 'ui-dialog-titlebar-close ' +
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
136 'ui-corner-all'
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
137 )
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
138 .attr('role', 'button')
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
139 .hover(
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
140 function() {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
141 uiDialogTitlebarClose.addClass('ui-state-hover');
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
142 },
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
143 function() {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
144 uiDialogTitlebarClose.removeClass('ui-state-hover');
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
145 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
146 )
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
147 .focus(function() {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
148 uiDialogTitlebarClose.addClass('ui-state-focus');
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
149 })
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
150 .blur(function() {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
151 uiDialogTitlebarClose.removeClass('ui-state-focus');
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
152 })
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
153 .click(function(event) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
154 self.close(event);
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
155 return false;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
156 })
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
157 .appendTo(uiDialogTitlebar),
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
158
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
159 uiDialogTitlebarCloseText = (self.uiDialogTitlebarCloseText = $('<span></span>'))
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
160 .addClass(
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
161 'ui-icon ' +
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
162 'ui-icon-closethick'
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
163 )
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
164 .text(options.closeText)
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
165 .appendTo(uiDialogTitlebarClose),
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
166
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
167 uiDialogTitle = $('<span></span>')
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
168 .addClass('ui-dialog-title')
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
169 .attr('id', titleId)
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
170 .html(title)
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
171 .prependTo(uiDialogTitlebar);
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
172
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
173 //handling of deprecated beforeclose (vs beforeClose) option
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
174 //Ticket #4669 http://dev.jqueryui.com/ticket/4669
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
175 //TODO: remove in 1.9pre
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
176 if ($.isFunction(options.beforeclose) && !$.isFunction(options.beforeClose)) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
177 options.beforeClose = options.beforeclose;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
178 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
179
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
180 uiDialogTitlebar.find("*").add(uiDialogTitlebar).disableSelection();
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
181
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
182 if (options.draggable && $.fn.draggable) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
183 self._makeDraggable();
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
184 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
185 if (options.resizable && $.fn.resizable) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
186 self._makeResizable();
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
187 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
188
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
189 self._createButtons(options.buttons);
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
190 self._isOpen = false;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
191
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
192 if ($.fn.bgiframe) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
193 uiDialog.bgiframe();
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
194 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
195 },
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
196
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
197 _init: function() {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
198 if ( this.options.autoOpen ) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
199 this.open();
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
200 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
201 },
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
202
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
203 destroy: function() {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
204 var self = this;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
205
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
206 if (self.overlay) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
207 self.overlay.destroy();
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
208 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
209 self.uiDialog.hide();
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
210 self.element
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
211 .unbind('.dialog')
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
212 .removeData('dialog')
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
213 .removeClass('ui-dialog-content ui-widget-content')
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
214 .hide().appendTo('body');
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
215 self.uiDialog.remove();
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
216
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
217 if (self.originalTitle) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
218 self.element.attr('title', self.originalTitle);
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
219 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
220
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
221 return self;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
222 },
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
223
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
224 widget: function() {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
225 return this.uiDialog;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
226 },
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
227
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
228 close: function(event) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
229 var self = this,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
230 maxZ, thisZ;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
231
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
232 if (false === self._trigger('beforeClose', event)) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
233 return;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
234 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
235
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
236 if (self.overlay) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
237 self.overlay.destroy();
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
238 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
239 self.uiDialog.unbind('keypress.ui-dialog');
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
240
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
241 self._isOpen = false;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
242
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
243 if (self.options.hide) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
244 self.uiDialog.hide(self.options.hide, function() {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
245 self._trigger('close', event);
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
246 });
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
247 } else {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
248 self.uiDialog.hide();
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
249 self._trigger('close', event);
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
250 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
251
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
252 $.ui.dialog.overlay.resize();
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
253
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
254 // adjust the maxZ to allow other modal dialogs to continue to work (see #4309)
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
255 if (self.options.modal) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
256 maxZ = 0;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
257 $('.ui-dialog').each(function() {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
258 if (this !== self.uiDialog[0]) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
259 thisZ = $(this).css('z-index');
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
260 if(!isNaN(thisZ)) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
261 maxZ = Math.max(maxZ, thisZ);
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
262 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
263 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
264 });
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
265 $.ui.dialog.maxZ = maxZ;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
266 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
267
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
268 return self;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
269 },
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
270
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
271 isOpen: function() {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
272 return this._isOpen;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
273 },
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
274
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
275 // the force parameter allows us to move modal dialogs to their correct
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
276 // position on open
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
277 moveToTop: function(force, event) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
278 var self = this,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
279 options = self.options,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
280 saveScroll;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
281
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
282 if ((options.modal && !force) ||
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
283 (!options.stack && !options.modal)) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
284 return self._trigger('focus', event);
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
285 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
286
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
287 if (options.zIndex > $.ui.dialog.maxZ) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
288 $.ui.dialog.maxZ = options.zIndex;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
289 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
290 if (self.overlay) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
291 $.ui.dialog.maxZ += 1;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
292 self.overlay.$el.css('z-index', $.ui.dialog.overlay.maxZ = $.ui.dialog.maxZ);
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
293 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
294
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
295 //Save and then restore scroll since Opera 9.5+ resets when parent z-Index is changed.
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
296 // http://ui.jquery.com/bugs/ticket/3193
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
297 saveScroll = { scrollTop: self.element.attr('scrollTop'), scrollLeft: self.element.attr('scrollLeft') };
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
298 $.ui.dialog.maxZ += 1;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
299 self.uiDialog.css('z-index', $.ui.dialog.maxZ);
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
300 self.element.attr(saveScroll);
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
301 self._trigger('focus', event);
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
302
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
303 return self;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
304 },
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
305
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
306 open: function() {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
307 if (this._isOpen) { return; }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
308
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
309 var self = this,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
310 options = self.options,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
311 uiDialog = self.uiDialog;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
312
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
313 self.overlay = options.modal ? new $.ui.dialog.overlay(self) : null;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
314 self._size();
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
315 self._position(options.position);
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
316 uiDialog.show(options.show);
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
317 self.moveToTop(true);
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
318
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
319 // prevent tabbing out of modal dialogs
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
320 if (options.modal) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
321 uiDialog.bind('keypress.ui-dialog', function(event) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
322 if (event.keyCode !== $.ui.keyCode.TAB) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
323 return;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
324 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
325
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
326 var tabbables = $(':tabbable', this),
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
327 first = tabbables.filter(':first'),
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
328 last = tabbables.filter(':last');
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
329
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
330 if (event.target === last[0] && !event.shiftKey) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
331 first.focus(1);
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
332 return false;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
333 } else if (event.target === first[0] && event.shiftKey) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
334 last.focus(1);
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
335 return false;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
336 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
337 });
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
338 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
339
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
340 // set focus to the first tabbable element in the content area or the first button
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
341 // if there are no tabbable elements, set focus on the dialog itself
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
342 $(self.element.find(':tabbable').get().concat(
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
343 uiDialog.find('.ui-dialog-buttonpane :tabbable').get().concat(
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
344 uiDialog.get()))).eq(0).focus();
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
345
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
346 self._isOpen = true;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
347 self._trigger('open');
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
348
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
349 return self;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
350 },
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
351
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
352 _createButtons: function(buttons) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
353 var self = this,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
354 hasButtons = false,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
355 uiDialogButtonPane = $('<div></div>')
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
356 .addClass(
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
357 'ui-dialog-buttonpane ' +
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
358 'ui-widget-content ' +
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
359 'ui-helper-clearfix'
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
360 ),
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
361 uiButtonSet = $( "<div></div>" )
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
362 .addClass( "ui-dialog-buttonset" )
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
363 .appendTo( uiDialogButtonPane );
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
364
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
365 // if we already have a button pane, remove it
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
366 self.uiDialog.find('.ui-dialog-buttonpane').remove();
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
367
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
368 if (typeof buttons === 'object' && buttons !== null) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
369 $.each(buttons, function() {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
370 return !(hasButtons = true);
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
371 });
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
372 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
373 if (hasButtons) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
374 $.each(buttons, function(name, props) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
375 props = $.isFunction( props ) ?
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
376 { click: props, text: name } :
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
377 props;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
378 var button = $('<button type="button"></button>')
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
379 .attr( props, true )
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
380 .unbind('click')
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
381 .click(function() {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
382 props.click.apply(self.element[0], arguments);
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
383 })
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
384 .appendTo(uiButtonSet);
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
385 if ($.fn.button) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
386 button.button();
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
387 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
388 });
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
389 uiDialogButtonPane.appendTo(self.uiDialog);
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
390 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
391 },
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
392
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
393 _makeDraggable: function() {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
394 var self = this,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
395 options = self.options,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
396 doc = $(document),
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
397 heightBeforeDrag;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
398
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
399 function filteredUi(ui) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
400 return {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
401 position: ui.position,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
402 offset: ui.offset
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
403 };
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
404 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
405
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
406 self.uiDialog.draggable({
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
407 cancel: '.ui-dialog-content, .ui-dialog-titlebar-close',
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
408 handle: '.ui-dialog-titlebar',
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
409 containment: 'document',
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
410 start: function(event, ui) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
411 heightBeforeDrag = options.height === "auto" ? "auto" : $(this).height();
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
412 $(this).height($(this).height()).addClass("ui-dialog-dragging");
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
413 self._trigger('dragStart', event, filteredUi(ui));
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
414 },
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
415 drag: function(event, ui) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
416 self._trigger('drag', event, filteredUi(ui));
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
417 },
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
418 stop: function(event, ui) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
419 options.position = [ui.position.left - doc.scrollLeft(),
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
420 ui.position.top - doc.scrollTop()];
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
421 $(this).removeClass("ui-dialog-dragging").height(heightBeforeDrag);
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
422 self._trigger('dragStop', event, filteredUi(ui));
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
423 $.ui.dialog.overlay.resize();
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
424 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
425 });
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
426 },
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
427
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
428 _makeResizable: function(handles) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
429 handles = (handles === undefined ? this.options.resizable : handles);
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
430 var self = this,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
431 options = self.options,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
432 // .ui-resizable has position: relative defined in the stylesheet
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
433 // but dialogs have to use absolute or fixed positioning
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
434 position = self.uiDialog.css('position'),
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
435 resizeHandles = (typeof handles === 'string' ?
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
436 handles :
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
437 'n,e,s,w,se,sw,ne,nw'
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
438 );
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
439
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
440 function filteredUi(ui) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
441 return {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
442 originalPosition: ui.originalPosition,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
443 originalSize: ui.originalSize,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
444 position: ui.position,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
445 size: ui.size
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
446 };
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
447 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
448
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
449 self.uiDialog.resizable({
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
450 cancel: '.ui-dialog-content',
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
451 containment: 'document',
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
452 alsoResize: self.element,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
453 maxWidth: options.maxWidth,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
454 maxHeight: options.maxHeight,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
455 minWidth: options.minWidth,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
456 minHeight: self._minHeight(),
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
457 handles: resizeHandles,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
458 start: function(event, ui) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
459 $(this).addClass("ui-dialog-resizing");
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
460 self._trigger('resizeStart', event, filteredUi(ui));
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
461 },
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
462 resize: function(event, ui) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
463 self._trigger('resize', event, filteredUi(ui));
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
464 },
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
465 stop: function(event, ui) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
466 $(this).removeClass("ui-dialog-resizing");
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
467 options.height = $(this).height();
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
468 options.width = $(this).width();
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
469 self._trigger('resizeStop', event, filteredUi(ui));
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
470 $.ui.dialog.overlay.resize();
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
471 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
472 })
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
473 .css('position', position)
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
474 .find('.ui-resizable-se').addClass('ui-icon ui-icon-grip-diagonal-se');
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
475 },
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
476
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
477 _minHeight: function() {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
478 var options = this.options;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
479
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
480 if (options.height === 'auto') {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
481 return options.minHeight;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
482 } else {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
483 return Math.min(options.minHeight, options.height);
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
484 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
485 },
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
486
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
487 _position: function(position) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
488 var myAt = [],
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
489 offset = [0, 0],
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
490 isVisible;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
491
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
492 if (position) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
493 // deep extending converts arrays to objects in jQuery <= 1.3.2 :-(
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
494 // if (typeof position == 'string' || $.isArray(position)) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
495 // myAt = $.isArray(position) ? position : position.split(' ');
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
496
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
497 if (typeof position === 'string' || (typeof position === 'object' && '0' in position)) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
498 myAt = position.split ? position.split(' ') : [position[0], position[1]];
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
499 if (myAt.length === 1) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
500 myAt[1] = myAt[0];
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
501 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
502
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
503 $.each(['left', 'top'], function(i, offsetPosition) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
504 if (+myAt[i] === myAt[i]) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
505 offset[i] = myAt[i];
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
506 myAt[i] = offsetPosition;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
507 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
508 });
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
509
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
510 position = {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
511 my: myAt.join(" "),
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
512 at: myAt.join(" "),
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
513 offset: offset.join(" ")
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
514 };
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
515 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
516
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
517 position = $.extend({}, $.ui.dialog.prototype.options.position, position);
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
518 } else {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
519 position = $.ui.dialog.prototype.options.position;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
520 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
521
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
522 // need to show the dialog to get the actual offset in the position plugin
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
523 isVisible = this.uiDialog.is(':visible');
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
524 if (!isVisible) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
525 this.uiDialog.show();
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
526 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
527 this.uiDialog
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
528 // workaround for jQuery bug #5781 http://dev.jquery.com/ticket/5781
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
529 .css({ top: 0, left: 0 })
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
530 .position($.extend({ of: window }, position));
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
531 if (!isVisible) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
532 this.uiDialog.hide();
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
533 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
534 },
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
535
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
536 _setOptions: function( options ) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
537 var self = this,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
538 resizableOptions = {},
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
539 resize = false;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
540
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
541 $.each( options, function( key, value ) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
542 self._setOption( key, value );
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
543
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
544 if ( key in sizeRelatedOptions ) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
545 resize = true;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
546 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
547 if ( key in resizableRelatedOptions ) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
548 resizableOptions[ key ] = value;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
549 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
550 });
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
551
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
552 if ( resize ) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
553 this._size();
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
554 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
555 if ( this.uiDialog.is( ":data(resizable)" ) ) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
556 this.uiDialog.resizable( "option", resizableOptions );
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
557 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
558 },
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
559
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
560 _setOption: function(key, value){
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
561 var self = this,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
562 uiDialog = self.uiDialog;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
563
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
564 switch (key) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
565 //handling of deprecated beforeclose (vs beforeClose) option
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
566 //Ticket #4669 http://dev.jqueryui.com/ticket/4669
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
567 //TODO: remove in 1.9pre
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
568 case "beforeclose":
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
569 key = "beforeClose";
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
570 break;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
571 case "buttons":
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
572 self._createButtons(value);
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
573 break;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
574 case "closeText":
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
575 // ensure that we always pass a string
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
576 self.uiDialogTitlebarCloseText.text("" + value);
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
577 break;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
578 case "dialogClass":
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
579 uiDialog
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
580 .removeClass(self.options.dialogClass)
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
581 .addClass(uiDialogClasses + value);
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
582 break;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
583 case "disabled":
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
584 if (value) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
585 uiDialog.addClass('ui-dialog-disabled');
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
586 } else {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
587 uiDialog.removeClass('ui-dialog-disabled');
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
588 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
589 break;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
590 case "draggable":
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
591 var isDraggable = uiDialog.is( ":data(draggable)" );
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
592 if ( isDraggable && !value ) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
593 uiDialog.draggable( "destroy" );
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
594 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
595
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
596 if ( !isDraggable && value ) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
597 self._makeDraggable();
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
598 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
599 break;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
600 case "position":
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
601 self._position(value);
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
602 break;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
603 case "resizable":
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
604 // currently resizable, becoming non-resizable
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
605 var isResizable = uiDialog.is( ":data(resizable)" );
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
606 if (isResizable && !value) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
607 uiDialog.resizable('destroy');
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
608 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
609
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
610 // currently resizable, changing handles
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
611 if (isResizable && typeof value === 'string') {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
612 uiDialog.resizable('option', 'handles', value);
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
613 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
614
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
615 // currently non-resizable, becoming resizable
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
616 if (!isResizable && value !== false) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
617 self._makeResizable(value);
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
618 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
619 break;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
620 case "title":
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
621 // convert whatever was passed in o a string, for html() to not throw up
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
622 $(".ui-dialog-title", self.uiDialogTitlebar).html("" + (value || '&#160;'));
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
623 break;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
624 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
625
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
626 $.Widget.prototype._setOption.apply(self, arguments);
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
627 },
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
628
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
629 _size: function() {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
630 /* If the user has resized the dialog, the .ui-dialog and .ui-dialog-content
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
631 * divs will both have width and height set, so we need to reset them
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
632 */
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
633 var options = this.options,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
634 nonContentHeight,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
635 minContentHeight,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
636 isVisible = this.uiDialog.is( ":visible" );
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
637
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
638 // reset content sizing
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
639 this.element.show().css({
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
640 width: 'auto',
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
641 minHeight: 0,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
642 height: 0
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
643 });
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
644
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
645 if (options.minWidth > options.width) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
646 options.width = options.minWidth;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
647 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
648
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
649 // reset wrapper sizing
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
650 // determine the height of all the non-content elements
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
651 nonContentHeight = this.uiDialog.css({
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
652 height: 'auto',
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
653 width: options.width
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
654 })
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
655 .height();
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
656 minContentHeight = Math.max( 0, options.minHeight - nonContentHeight );
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
657
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
658 if ( options.height === "auto" ) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
659 // only needed for IE6 support
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
660 if ( $.support.minHeight ) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
661 this.element.css({
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
662 minHeight: minContentHeight,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
663 height: "auto"
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
664 });
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
665 } else {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
666 this.uiDialog.show();
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
667 var autoHeight = this.element.css( "height", "auto" ).height();
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
668 if ( !isVisible ) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
669 this.uiDialog.hide();
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
670 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
671 this.element.height( Math.max( autoHeight, minContentHeight ) );
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
672 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
673 } else {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
674 this.element.height( Math.max( options.height - nonContentHeight, 0 ) );
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
675 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
676
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
677 if (this.uiDialog.is(':data(resizable)')) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
678 this.uiDialog.resizable('option', 'minHeight', this._minHeight());
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
679 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
680 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
681 });
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
682
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
683 $.extend($.ui.dialog, {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
684 version: "1.8.11",
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
685
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
686 uuid: 0,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
687 maxZ: 0,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
688
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
689 getTitleId: function($el) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
690 var id = $el.attr('id');
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
691 if (!id) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
692 this.uuid += 1;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
693 id = this.uuid;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
694 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
695 return 'ui-dialog-title-' + id;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
696 },
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
697
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
698 overlay: function(dialog) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
699 this.$el = $.ui.dialog.overlay.create(dialog);
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
700 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
701 });
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
702
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
703 $.extend($.ui.dialog.overlay, {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
704 instances: [],
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
705 // reuse old instances due to IE memory leak with alpha transparency (see #5185)
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
706 oldInstances: [],
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
707 maxZ: 0,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
708 events: $.map('focus,mousedown,mouseup,keydown,keypress,click'.split(','),
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
709 function(event) { return event + '.dialog-overlay'; }).join(' '),
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
710 create: function(dialog) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
711 if (this.instances.length === 0) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
712 // prevent use of anchors and inputs
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
713 // we use a setTimeout in case the overlay is created from an
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
714 // event that we're going to be cancelling (see #2804)
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
715 setTimeout(function() {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
716 // handle $(el).dialog().dialog('close') (see #4065)
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
717 if ($.ui.dialog.overlay.instances.length) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
718 $(document).bind($.ui.dialog.overlay.events, function(event) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
719 // stop events if the z-index of the target is < the z-index of the overlay
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
720 // we cannot return true when we don't want to cancel the event (#3523)
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
721 if ($(event.target).zIndex() < $.ui.dialog.overlay.maxZ) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
722 return false;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
723 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
724 });
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
725 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
726 }, 1);
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
727
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
728 // allow closing by pressing the escape key
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
729 $(document).bind('keydown.dialog-overlay', function(event) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
730 if (dialog.options.closeOnEscape && event.keyCode &&
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
731 event.keyCode === $.ui.keyCode.ESCAPE) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
732
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
733 dialog.close(event);
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
734 event.preventDefault();
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
735 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
736 });
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
737
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
738 // handle window resize
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
739 $(window).bind('resize.dialog-overlay', $.ui.dialog.overlay.resize);
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
740 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
741
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
742 var $el = (this.oldInstances.pop() || $('<div></div>').addClass('ui-widget-overlay'))
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
743 .appendTo(document.body)
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
744 .css({
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
745 width: this.width(),
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
746 height: this.height()
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
747 });
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
748
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
749 if ($.fn.bgiframe) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
750 $el.bgiframe();
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
751 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
752
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
753 this.instances.push($el);
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
754 return $el;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
755 },
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
756
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
757 destroy: function($el) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
758 var indexOf = $.inArray($el, this.instances);
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
759 if (indexOf != -1){
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
760 this.oldInstances.push(this.instances.splice(indexOf, 1)[0]);
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
761 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
762
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
763 if (this.instances.length === 0) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
764 $([document, window]).unbind('.dialog-overlay');
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
765 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
766
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
767 $el.remove();
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
768
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
769 // adjust the maxZ to allow other modal dialogs to continue to work (see #4309)
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
770 var maxZ = 0;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
771 $.each(this.instances, function() {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
772 maxZ = Math.max(maxZ, this.css('z-index'));
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
773 });
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
774 this.maxZ = maxZ;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
775 },
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
776
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
777 height: function() {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
778 var scrollHeight,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
779 offsetHeight;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
780 // handle IE 6
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
781 if ($.browser.msie && $.browser.version < 7) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
782 scrollHeight = Math.max(
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
783 document.documentElement.scrollHeight,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
784 document.body.scrollHeight
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
785 );
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
786 offsetHeight = Math.max(
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
787 document.documentElement.offsetHeight,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
788 document.body.offsetHeight
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
789 );
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
790
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
791 if (scrollHeight < offsetHeight) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
792 return $(window).height() + 'px';
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
793 } else {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
794 return scrollHeight + 'px';
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
795 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
796 // handle "good" browsers
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
797 } else {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
798 return $(document).height() + 'px';
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
799 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
800 },
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
801
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
802 width: function() {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
803 var scrollWidth,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
804 offsetWidth;
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
805 // handle IE 6
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
806 if ($.browser.msie && $.browser.version < 7) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
807 scrollWidth = Math.max(
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
808 document.documentElement.scrollWidth,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
809 document.body.scrollWidth
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
810 );
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
811 offsetWidth = Math.max(
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
812 document.documentElement.offsetWidth,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
813 document.body.offsetWidth
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
814 );
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
815
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
816 if (scrollWidth < offsetWidth) {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
817 return $(window).width() + 'px';
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
818 } else {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
819 return scrollWidth + 'px';
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
820 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
821 // handle "good" browsers
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
822 } else {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
823 return $(document).width() + 'px';
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
824 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
825 },
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
826
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
827 resize: function() {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
828 /* If the dialog is draggable and the user drags it past the
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
829 * right edge of the window, the document becomes wider so we
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
830 * need to stretch the overlay. If the user then drags the
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
831 * dialog back to the left, the document will become narrower,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
832 * so we need to shrink the overlay to the appropriate size.
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
833 * This is handled by shrinking the overlay before setting it
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
834 * to the full document size.
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
835 */
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
836 var $overlays = $([]);
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
837 $.each($.ui.dialog.overlay.instances, function() {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
838 $overlays = $overlays.add(this);
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
839 });
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
840
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
841 $overlays.css({
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
842 width: 0,
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
843 height: 0
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
844 }).css({
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
845 width: $.ui.dialog.overlay.width(),
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
846 height: $.ui.dialog.overlay.height()
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
847 });
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
848 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
849 });
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
850
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
851 $.extend($.ui.dialog.overlay.prototype, {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
852 destroy: function() {
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
853 $.ui.dialog.overlay.destroy(this.$el);
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
854 }
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
855 });
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
856
b2e4605f20b2 beta version
dwinter
parents:
diff changeset
857 }(jQuery));