Skip to content

Commit 8cc0d2c

Browse files
committed
Dialog: Simplify overlay code.
1 parent c1cda18 commit 8cc0d2c

File tree

1 file changed

+9
-110
lines changed

1 file changed

+9
-110
lines changed

ui/jquery.ui.dialog.js

Lines changed: 9 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,6 @@ $.widget("ui.dialog", {
217217
self._trigger( "close", event );
218218
}
219219

220-
$.ui.dialog.overlay.resize();
221-
222220
// adjust the maxZ to allow other modal dialogs to continue to work (see #4309)
223221
if ( self.options.modal ) {
224222
maxZ = 0;
@@ -255,11 +253,6 @@ $.widget("ui.dialog", {
255253
if ( options.zIndex > $.ui.dialog.maxZ ) {
256254
$.ui.dialog.maxZ = options.zIndex;
257255
}
258-
if ( self.overlay ) {
259-
$.ui.dialog.maxZ += 1;
260-
$.ui.dialog.overlay.maxZ = $.ui.dialog.maxZ;
261-
self.overlay.$el.css( "z-index", $.ui.dialog.overlay.maxZ );
262-
}
263256

264257
// Save and then restore scroll
265258
// Opera 9.5+ resets when parent z-index is changed.
@@ -402,7 +395,6 @@ $.widget("ui.dialog", {
402395
$( this )
403396
.removeClass( "ui-dialog-dragging" );
404397
self._trigger( "dragStop", event, filteredUi( ui ) );
405-
$.ui.dialog.overlay.resize();
406398
}
407399
});
408400
},
@@ -448,7 +440,6 @@ $.widget("ui.dialog", {
448440
options.height = $( this ).height();
449441
options.width = $( this ).width();
450442
self._trigger( "resizeStop", event, filteredUi( ui ) );
451-
$.ui.dialog.overlay.resize();
452443
}
453444
})
454445
.css( "position", position )
@@ -676,9 +667,8 @@ $.extend( $.ui.dialog.overlay, {
676667
instances: [],
677668
// reuse old instances due to IE memory leak with alpha transparency (see #5185)
678669
oldInstances: [],
679-
maxZ: 0,
680670
events: $.map(
681-
"focus,mousedown,mouseup,keydown,keypress,click".split( "," ),
671+
"focus mousedown click keydown keypress".split( " " ),
682672
function( event ) {
683673
return event + ".dialog-overlay";
684674
}
@@ -692,34 +682,23 @@ $.extend( $.ui.dialog.overlay, {
692682
// handle $(el).dialog().dialog('close') (see #4065)
693683
if ( $.ui.dialog.overlay.instances.length ) {
694684
$( document ).bind( $.ui.dialog.overlay.events, function( event ) {
695-
// stop events if the z-index of the target is < the z-index of the overlay
696-
// we cannot return true when we don't want to cancel the event (#3523)
697-
if ( $( event.target ).zIndex() < $.ui.dialog.overlay.maxZ ) {
698-
return false;
685+
if ( !$( event.target ).closest( ".ui-dialog").length ) {
686+
event.preventDefault();
687+
// TODO: focus top-most dialog
688+
$( ".ui-dialog" ).focus( 1 );
699689
}
700690
});
701691
}
702692
}, 1 );
703-
704-
// allow closing by pressing the escape key
705-
$( document ).bind( "keydown.dialog-overlay", function( event ) {
706-
if ( dialog.options.closeOnEscape && !event.isDefaultPrevented() && event.keyCode &&
707-
event.keyCode === $.ui.keyCode.ESCAPE ) {
708-
709-
dialog.close( event );
710-
event.preventDefault();
711-
}
712-
});
713-
714-
// handle window resize
715-
$( window ).bind( "resize.dialog-overlay", $.ui.dialog.overlay.resize );
716693
}
717694

718695
var $el = ( this.oldInstances.pop() || $( "<div>" ).addClass( "ui-widget-overlay" ) )
719696
.appendTo( document.body )
720697
.css({
721-
width: this.width(),
722-
height: this.height()
698+
width: "100%",
699+
height: "100%",
700+
position: "fixed",
701+
zIndex: $.ui.dialog.maxZ
723702
});
724703

725704
if ( $.fn.bgiframe ) {
@@ -741,86 +720,6 @@ $.extend( $.ui.dialog.overlay, {
741720
}
742721

743722
$el.height( 0 ).width( 0 ).remove();
744-
745-
// adjust the maxZ to allow other modal dialogs to continue to work (see #4309)
746-
var maxZ = 0;
747-
$.each( this.instances, function() {
748-
maxZ = Math.max( maxZ, this.css( "z-index" ) );
749-
});
750-
this.maxZ = maxZ;
751-
},
752-
753-
height: function() {
754-
var scrollHeight,
755-
offsetHeight;
756-
// handle IE
757-
if ( $.browser.msie ) {
758-
scrollHeight = Math.max(
759-
document.documentElement.scrollHeight,
760-
document.body.scrollHeight
761-
);
762-
offsetHeight = Math.max(
763-
document.documentElement.offsetHeight,
764-
document.body.offsetHeight
765-
);
766-
767-
if ( scrollHeight < offsetHeight ) {
768-
return $( window ).height() + "px";
769-
} else {
770-
return scrollHeight + "px";
771-
}
772-
// handle "good" browsers
773-
} else {
774-
return $( document ).height() + "px";
775-
}
776-
},
777-
778-
width: function() {
779-
var scrollWidth,
780-
offsetWidth;
781-
// handle IE
782-
if ( $.browser.msie ) {
783-
scrollWidth = Math.max(
784-
document.documentElement.scrollWidth,
785-
document.body.scrollWidth
786-
);
787-
offsetWidth = Math.max(
788-
document.documentElement.offsetWidth,
789-
document.body.offsetWidth
790-
);
791-
792-
if ( scrollWidth < offsetWidth ) {
793-
return $( window ).width() + "px";
794-
} else {
795-
return scrollWidth + "px";
796-
}
797-
// handle "good" browsers
798-
} else {
799-
return $( document ).width() + "px";
800-
}
801-
},
802-
803-
resize: function() {
804-
/* If the dialog is draggable and the user drags it past the
805-
* right edge of the window, the document becomes wider so we
806-
* need to stretch the overlay. If the user then drags the
807-
* dialog back to the left, the document will become narrower,
808-
* so we need to shrink the overlay to the appropriate size.
809-
* This is handled by shrinking the overlay before setting it
810-
* to the full document size.
811-
*/
812-
var $overlays = $( [] );
813-
$.each( $.ui.dialog.overlay.instances, function() {
814-
$overlays = $overlays.add( this );
815-
});
816-
817-
$overlays.css({
818-
width: 0,
819-
height: 0
820-
}).css({
821-
width: $.ui.dialog.overlay.width(),
822-
height: $.ui.dialog.overlay.height()
823-
});
824723
}
825724
});
826725

0 commit comments

Comments
 (0)