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