Dialog: Refactored moveToTop, greatly improving performance for opening dialogs in IE. Partial fix for #2807 - dialog UI + modal mode = slow.

This commit is contained in:
Scott González 2009-02-19 01:49:33 +00:00
parent 967074f811
commit 06a513b753

View File

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