]> source.dussan.org Git - jquery-ui.git/commitdiff
Dialog: Refactored moveToTop, greatly improving performance for opening dialogs in...
authorScott González <scott.gonzalez@gmail.com>
Thu, 19 Feb 2009 01:49:33 +0000 (01:49 +0000)
committerScott González <scott.gonzalez@gmail.com>
Thu, 19 Feb 2009 01:49:33 +0000 (01:49 +0000)
ui/ui.dialog.js

index 4cec0f7f35ad9edc1a0e2e8933e1068763c6098a..4448f34f31f2ed6d9c2b5b9a4e14c66aea9787d1 100644 (file)
@@ -177,21 +177,22 @@ $.widget("ui.dialog", {
        // position on open
        moveToTop: function(force, event) {
 
-               if ((this.options.modal && !force)
+               if ($.ui.dialog.topMostDialog == this
+                       || (this.options.modal && !force)
                        || (!this.options.stack && !this.options.modal)) {
                        return this._trigger('focus', event);
                }
-
-               var maxZ = this.options.zIndex, options = this.options;
-               $('.ui-dialog:visible').each(function() {
-                       maxZ = Math.max(maxZ, parseInt($(this).css('z-index'), 10) || options.zIndex);
-               });
-               (this.overlay && this.overlay.$el.css('z-index', ++maxZ));
+               
+               if (this.options.zIndex > $.ui.dialog.maxZ) {
+                       $.ui.dialog.maxZ = this.options.zIndex;
+               }
+               $.ui.dialog.topMostDialog = this;
+               (this.overlay && this.overlay.$el.css('z-index', ++$.ui.dialog.maxZ));
 
                //Save and then restore scroll since Opera 9.5+ resets when parent z-Index is changed.
                //  http://ui.jquery.com/bugs/ticket/3193
                var saveScroll = { scrollTop: this.element.attr('scrollTop'), scrollLeft: this.element.attr('scrollLeft') };
-               this.uiDialog.css('z-index', ++maxZ);
+               this.uiDialog.css('z-index', ++$.ui.dialog.maxZ);
                this.element.attr(saveScroll);
                this._trigger('focus', event);
        },
@@ -501,6 +502,8 @@ $.extend($.ui.dialog, {
        getter: 'isOpen',
 
        uuid: 0,
+       maxZ: 0,
+       topMostDialog: null,
 
        getTitleId: function($el) {
                return 'ui-dialog-title-' + ($el.attr('id') || ++this.uuid);