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