]> source.dussan.org Git - jquery-ui.git/commitdiff
Draggable: active element blurs when clicking on a draggable. Fixes #4261 - Draggable...
authorSteven Luscher <jquerycla@steveluscher.com>
Wed, 1 May 2013 22:01:32 +0000 (15:01 -0700)
committerMike Sherov <mike.sherov@gmail.com>
Wed, 19 Jun 2013 22:07:38 +0000 (18:07 -0400)
tests/unit/datepicker/datepicker_test_helpers.js
tests/unit/draggable/draggable_core.js
tests/unit/testsuite.js
ui/jquery.ui.draggable.js

index 9cb63c9eca4f9ecfbc34480503c7e6d3d23e9fe1..34b41bbc6a5c1df4c7f60796da8bc28214f9b7b3 100644 (file)
@@ -22,16 +22,6 @@ TestHelpers.datepicker = {
                var id = $( "<input>" ).appendTo( "#qunit-fixture" );
                return TestHelpers.datepicker.init( id, options );
        },
-       onFocus: function( element, onFocus ) {
-               var fn = function( event ){
-                       if( !event.originalEvent ) {
-                               return;
-                       }
-                       element.unbind( "focus", fn );
-                       onFocus();
-               };
-
-               element.bind( "focus", fn )[ 0 ].focus();
-       },
+       onFocus: TestHelpers.onFocus,
        PROP_NAME: "datepicker"
 };
\ No newline at end of file
index 232ac6c1765e3c3dc74bbe1d13a9c471ffe48b07..69906b6a71fff59f11f5f28a78fc054b3bfb6954 100644 (file)
@@ -199,4 +199,20 @@ test( "#8399: A draggable should become the active element after you are finishe
        strictEqual( document.activeElement, element.get( 0 ), "finishing moving a draggable anchor made it the active element" );
 });
 
+asyncTest( "#4261: active element should blur when mousing down on a draggable", function() {
+       expect( 2 );
+
+       var textInput = $( "<input>" ).appendTo( "#qunit-fixture" ),
+               element = $( "#draggable1" ).draggable();
+
+       TestHelpers.onFocus( textInput, function() {
+               strictEqual( document.activeElement, textInput.get( 0 ), "ensure that a focussed text input is the active element before mousing down on a draggable" );
+
+               TestHelpers.draggable.move( element, 50, 50 );
+
+               notStrictEqual( document.activeElement, textInput.get( 0 ), "ensure the text input is no longer the active element after mousing down on a draggable" );
+               start();
+       });
+});
+
 })( jQuery );
index ddc59ed0802ec82bcfe70646838fc0ccdd66d38a..6e840f415b2c29a8088f7792dd94c1cd55b2e701 100644 (file)
@@ -175,6 +175,18 @@ TestHelpers.commonWidgetTests = function( widget, settings ) {
        });
 };
 
+TestHelpers.onFocus= function( element, onFocus ) {
+       var fn = function( event ){
+               if( !event.originalEvent ) {
+                       return;
+               }
+               element.unbind( "focus", fn );
+               onFocus();
+       };
+
+       element.bind( "focus", fn )[ 0 ].focus();
+};
+
 /*
  * Taken from https://github.com/jquery/qunit/tree/master/addons/close-enough
  */
index 9ee858725a779f46332ed63db214dcaef950c462..ab1e800cdb73bb6e105187ecbb78d5fbca358280 100644 (file)
@@ -78,6 +78,8 @@ $.widget("ui.draggable", $.ui.mouse, {
 
                var o = this.options;
 
+               $( document.activeElement ).blur();
+
                // among others, prevent a drag on a resizable-handle
                if (this.helper || o.disabled || $(event.target).closest(".ui-resizable-handle").length > 0) {
                        return false;