From d1505e3434ef99e0068347a5e8179a0ffd737676 Mon Sep 17 00:00:00 2001 From: Kris Borchers Date: Wed, 30 Jan 2013 12:30:37 -0600 Subject: Dialog: Move call to _focusTabbable and triggering of open and focus events into the _show callback. Fixes #6756 - Dialog: show: "blind" with link in content doesn't animate properly. Fixes #8051 - Dialog: 'Explode' dialog animation causes crash in IE 6, 7 and 8. Fixes #4421 - Dialog: Focus lost from dialog which uses show-effect --- ui/jquery.ui.dialog.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'ui/jquery.ui.dialog.js') diff --git a/ui/jquery.ui.dialog.js b/ui/jquery.ui.dialog.js index ec4032ff3..77bf68dd1 100644 --- a/ui/jquery.ui.dialog.js +++ b/ui/jquery.ui.dialog.js @@ -207,6 +207,7 @@ $.widget( "ui.dialog", { }, open: function() { + var that = this; if ( this._isOpen ) { if ( this._moveToTop() ) { this._focusTabbable(); @@ -220,13 +221,13 @@ $.widget( "ui.dialog", { this._position(); this._createOverlay(); this._moveToTop( null, true ); - this._show( this.uiDialog, this.options.show ); - - this._focusTabbable(); + this._show( this.uiDialog, this.options.show, function() { + that._focusTabbable(); + that._trigger("focus"); + }); this._isOpen = true; this._trigger("open"); - this._trigger("focus"); }, _focusTabbable: function() { -- cgit v1.2.3 From 62cda1f95d0e7040153f0b5fe5745d199a0a094e Mon Sep 17 00:00:00 2001 From: Scott González Date: Thu, 31 Jan 2013 17:20:19 -0500 Subject: Dialog: Set the _isOpen flag immediately in open(). Fixes #8958 - Dialog: Double ui-widget-overlay when opening modal dialog triggers an event opening same dialog. --- tests/unit/dialog/dialog_methods.js | 29 +++++++++++++++++++++++++++++ ui/jquery.ui.dialog.js | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-) (limited to 'ui/jquery.ui.dialog.js') diff --git a/tests/unit/dialog/dialog_methods.js b/tests/unit/dialog/dialog_methods.js index 2c3495ca2..6de185513 100644 --- a/tests/unit/dialog/dialog_methods.js +++ b/tests/unit/dialog/dialog_methods.js @@ -193,6 +193,35 @@ test("#6137: dialog('open') causes form elements to reset on IE7", function() { d1.remove(); }); +asyncTest( "#8958: dialog can be opened while opening", function() { + expect( 1 ); + + var element = $( "
" ).dialog({ + autoOpen: false, + modal: true, + open: function() { + equal( $( ".ui-widget-overlay" ).length, 1 ); + start(); + } + }); + + $( "#favorite-animal" ) + // We focus the input to start the test. Once it receives focus, the + // dialog will open. Opening the dialog, will cause an element inside + // the dialog to gain focus, thus blurring the input. + .bind( "focus", function() { + element.dialog( "open" ); + }) + // When the input blurs, the dialog is in the process of opening. We + // try to open the dialog again, to make sure that dialogs properly + // handle a call to the open() method during the process of the dialog + // being opened. + .bind( "blur", function() { + element.dialog( "open" ); + }) + .focus(); +}); + test("#5531: dialog width should be at least minWidth on creation", function () { expect( 4 ); var element = $("
").dialog({ diff --git a/ui/jquery.ui.dialog.js b/ui/jquery.ui.dialog.js index 77bf68dd1..b6ac7aed7 100644 --- a/ui/jquery.ui.dialog.js +++ b/ui/jquery.ui.dialog.js @@ -215,6 +215,7 @@ $.widget( "ui.dialog", { return; } + this._isOpen = true; this.opener = $( this.document[0].activeElement ); this._size(); @@ -226,7 +227,6 @@ $.widget( "ui.dialog", { that._trigger("focus"); }); - this._isOpen = true; this._trigger("open"); }, -- cgit v1.2.3 From 7bbda71a32cc4953715ed34eab2ab48c5e736154 Mon Sep 17 00:00:00 2001 From: Scott González Date: Fri, 1 Feb 2013 08:59:55 -0500 Subject: Dialog: Check for empty array in addition to empty object when checking if there are buttons. Fixes #9043 - Dialog: Buttonpane shown with no buttons when modifying native prototypes. --- demos/dialog/default.html | 1 + tests/unit/dialog/dialog_options.js | 10 ++++++++++ ui/jquery.ui.dialog.js | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) (limited to 'ui/jquery.ui.dialog.js') diff --git a/demos/dialog/default.html b/demos/dialog/default.html index e781e18f8..98f248b81 100644 --- a/demos/dialog/default.html +++ b/demos/dialog/default.html @@ -16,6 +16,7 @@ diff --git a/tests/unit/dialog/dialog_options.js b/tests/unit/dialog/dialog_options.js index a295b904d..07c2d6860 100644 --- a/tests/unit/dialog/dialog_options.js +++ b/tests/unit/dialog/dialog_options.js @@ -174,6 +174,16 @@ test("buttons - advanced", function() { element.remove(); }); +test("#9043: buttons with Array.prototype modification", function() { + expect( 1 ); + Array.prototype.test = $.noop; + var element = $( "
" ).dialog(); + equal( element.dialog( "widget" ).find( ".ui-dialog-buttonpane" ).length, 0, + "no button pane" ); + element.remove(); + delete Array.prototype.test; +}); + test("closeOnEscape", function() { expect( 6 ); var element = $("
").dialog({ closeOnEscape: false }); diff --git a/ui/jquery.ui.dialog.js b/ui/jquery.ui.dialog.js index b6ac7aed7..cb62155e5 100644 --- a/ui/jquery.ui.dialog.js +++ b/ui/jquery.ui.dialog.js @@ -396,7 +396,7 @@ $.widget( "ui.dialog", { this.uiDialogButtonPane.remove(); this.uiButtonSet.empty(); - if ( $.isEmptyObject( buttons ) ) { + if ( $.isEmptyObject( buttons ) || ($.isArray( buttons ) && !buttons.length) ) { this.uiDialog.removeClass("ui-dialog-buttons"); return; } -- cgit v1.2.3 From 8724092e5070125e2610e8b0e6ee9ada126cf504 Mon Sep 17 00:00:00 2001 From: Scott González Date: Sat, 2 Feb 2013 19:32:42 -0500 Subject: Dialog: Don't use ._on() for modal event handlers. Fixes #9048 - Dialog: broken focusin event handler when beforeclose event of a modal opens another modal. --- tests/unit/dialog/dialog_core.js | 13 +++++++++++++ ui/jquery.ui.dialog.js | 20 +++++++++----------- 2 files changed, 22 insertions(+), 11 deletions(-) (limited to 'ui/jquery.ui.dialog.js') diff --git a/tests/unit/dialog/dialog_core.js b/tests/unit/dialog/dialog_core.js index 9292eca9f..e85759dc9 100644 --- a/tests/unit/dialog/dialog_core.js +++ b/tests/unit/dialog/dialog_core.js @@ -147,4 +147,17 @@ asyncTest( "Prevent tabbing out of dialogs", function() { }); }); +asyncTest( "#9048: multiple modal dialogs opened and closed in different order", function() { + expect( 1 ); + $( "#dialog1, #dialog2" ).dialog({ autoOpen: false, modal:true }); + $( "#dialog1" ).dialog( "open" ); + $( "#dialog2" ).dialog( "open" ); + $( "#dialog1" ).dialog( "close" ); + setTimeout(function() { + $( "#dialog2" ).dialog( "close" ); + $( "#favorite-animal" ).focus(); + ok( true, "event handlers cleaned up (no errors thrown)" ); + start(); + }); +}); })(jQuery); diff --git a/ui/jquery.ui.dialog.js b/ui/jquery.ui.dialog.js index cb62155e5..f2bc906fd 100644 --- a/ui/jquery.ui.dialog.js +++ b/ui/jquery.ui.dialog.js @@ -678,16 +678,14 @@ $.widget( "ui.dialog", { this._delay(function() { // Handle .dialog().dialog("close") (#4065) if ( $.ui.dialog.overlayInstances ) { - this._on( this.document, { - focusin: function( event ) { - if ( !$( event.target ).closest(".ui-dialog").length && - // TODO: Remove hack when datepicker implements - // the .ui-front logic (#8989) - !$( event.target ).closest(".ui-datepicker").length ) { - event.preventDefault(); - $(".ui-dialog:visible:last .ui-dialog-content") - .data("ui-dialog")._focusTabbable(); - } + this.document.bind( "focusin.dialog", function( event ) { + if ( !$( event.target ).closest(".ui-dialog").length && + // TODO: Remove hack when datepicker implements + // the .ui-front logic (#8989) + !$( event.target ).closest(".ui-datepicker").length ) { + event.preventDefault(); + $(".ui-dialog:visible:last .ui-dialog-content") + .data("ui-dialog")._focusTabbable(); } }); } @@ -712,7 +710,7 @@ $.widget( "ui.dialog", { $.ui.dialog.overlayInstances--; if ( !$.ui.dialog.overlayInstances ) { - this._off( this.document, "focusin" ); + this.document.unbind( "focusin.dialog" ); } this.overlay.remove(); this.overlay = null; -- cgit v1.2.3 From a7353e7c9ba18e017813195c885115338800e13d Mon Sep 17 00:00:00 2001 From: Scott González Date: Sun, 3 Feb 2013 08:55:34 -0500 Subject: Dailog: Cover iframes during drag and resize. Fixes #7650 - Dialog cannot be dragged properly with IFRAME. --- ui/jquery.ui.dialog.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'ui/jquery.ui.dialog.js') diff --git a/ui/jquery.ui.dialog.js b/ui/jquery.ui.dialog.js index f2bc906fd..85dbddda2 100644 --- a/ui/jquery.ui.dialog.js +++ b/ui/jquery.ui.dialog.js @@ -444,6 +444,7 @@ $.widget( "ui.dialog", { containment: "document", start: function( event, ui ) { $( this ).addClass("ui-dialog-dragging"); + that._blockFrames(); that._trigger( "dragStart", event, filteredUi( ui ) ); }, drag: function( event, ui ) { @@ -455,6 +456,7 @@ $.widget( "ui.dialog", { ui.position.top - that.document.scrollTop() ]; $( this ).removeClass("ui-dialog-dragging"); + that._unblockFrames(); that._trigger( "dragStop", event, filteredUi( ui ) ); } }); @@ -491,6 +493,7 @@ $.widget( "ui.dialog", { handles: resizeHandles, start: function( event, ui ) { $( this ).addClass("ui-dialog-resizing"); + that._blockFrames(); that._trigger( "resizeStart", event, filteredUi( ui ) ); }, resize: function( event, ui ) { @@ -500,6 +503,7 @@ $.widget( "ui.dialog", { options.height = $( this ).height(); options.width = $( this ).width(); $( this ).removeClass("ui-dialog-resizing"); + that._unblockFrames(); that._trigger( "resizeStop", event, filteredUi( ui ) ); } }) @@ -666,6 +670,28 @@ $.widget( "ui.dialog", { } }, + _blockFrames: function() { + this.iframeBlocks = this.document.find( "iframe" ).map(function() { + var iframe = $( this ); + + return $( "
" ) + .css({ + position: "absolute", + width: iframe.outerWidth(), + height: iframe.outerHeight() + }) + .appendTo( iframe.parent() ) + .offset( iframe.offset() )[0]; + }); + }, + + _unblockFrames: function() { + if ( this.iframeBlocks ) { + this.iframeBlocks.remove(); + delete this.iframeBlocks; + } + }, + _createOverlay: function() { if ( !this.options.modal ) { return; -- cgit v1.2.3