]> source.dussan.org Git - jquery-ui.git/commitdiff
Dialog: Save the active element that opened the dialog and restore focus to that...
authorJörn Zaefferer <joern.zaefferer@gmail.com>
Tue, 23 Oct 2012 14:31:10 +0000 (10:31 -0400)
committerJörn Zaefferer <joern.zaefferer@gmail.com>
Wed, 24 Oct 2012 21:02:32 +0000 (17:02 -0400)
tests/visual/dialog/complex-dialogs.html
ui/jquery.ui.dialog.js

index 634bfb3d60306747b4043ab1946d73e12f51a6e5..2647871857416b35f3c869d9e84061852c2b161d 100644 (file)
 
        <script>
        $(function() {
-               $( "#dialog" ).dialog({
-                       modal: true,
-                       height: 300,
-                       width: 500
-               });
+               var dialog = $( "#dialog" ).dialog({
+                               modal: true,
+                               height: 300,
+                               width: 500
+                       }),
 
-               var datepickerDialog = $( "#dialog-datepicker" ).dialog({
+                       datepickerDialog = $( "#dialog-datepicker" ).dialog({
                                autoOpen: false,
                                modal: true
                        }),
                                width: 600
                        });
 
+               $( "#open-dialog" ).click(function() {
+                       dialog.dialog( "open" );
+               });
+
                $( "#open-datepicker" ).click(function() {
                        datepickerDialog.dialog( "open" );
                });
@@ -70,6 +74,8 @@
 
 <a href="#">Outside link</a>
 
+<button id="open-dialog">Reopen dialog</button>
+
 <div id="dialog" title="Basic dialog">
        <p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
        <p><button id="open-datepicker">Open another window with a datepicker.</button></p>
index 2b9846b3a0afa4f0c860d574a642ac5f8688b37d..6617c344e276768eae4b3b1638f1ab6f45a5d743 100644 (file)
@@ -248,6 +248,13 @@ $.widget("ui.dialog", {
                        this.overlay.destroy();
                }
 
+               if ( !this.opener.filter( ":focusable" ).focus().length ) {
+                       // Hiding a focused element doesn't trigger blur in WebKit
+                       // so in case we have nothing to focus on, explicitly blur the active element
+                       // https://bugs.webkit.org/show_bug.cgi?id=47182
+                       $( this.document[ 0 ].activeElement ).blur();
+               }
+
                if ( this.options.hide ) {
                        this._hide( this.uiDialog, this.options.hide, function() {
                                that._trigger( "close", event );
@@ -278,6 +285,8 @@ $.widget("ui.dialog", {
                        options = this.options,
                        uiDialog = this.uiDialog;
 
+               this.opener = $( this.document[ 0 ].activeElement );
+
                this._size();
                this._position( options.position );
                uiDialog.show( options.show );