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