From df6110c0d424ff3306fdd5576011f2dcf4d242d0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jo=CC=88rn=20Zaefferer?= Date: Fri, 21 Feb 2014 13:22:39 +0100 Subject: [PATCH] Core: Deprecate .focus( n ), replace in dialog with explicit timeouts Fixes #9646 --- tests/unit/core/core.js | 28 -------------------------- tests/unit/core/core_deprecated.js | 28 ++++++++++++++++++++++++++ ui/core.js | 32 +++++++++++++++--------------- ui/dialog.js | 8 ++++++-- 4 files changed, 50 insertions(+), 46 deletions(-) diff --git a/tests/unit/core/core.js b/tests/unit/core/core.js index acacfab9c..1b1dcbabf 100644 --- a/tests/unit/core/core.js +++ b/tests/unit/core/core.js @@ -4,34 +4,6 @@ module( "core - jQuery extensions" ); TestHelpers.testJshint( "core" ); -asyncTest( "focus - original functionality", function() { - expect( 1 ); - $( "#inputTabindex0" ) - .one( "focus", function() { - ok( true, "event triggered" ); - start(); - }) - .focus(); -}); - -asyncTest( "focus", function() { - expect( 2 ); - - // support: IE 8 - // IE sometimes gets confused about what's focused if we don't explicitly - // focus a different element first - $( "body" ).focus(); - - $( "#inputTabindex0" ) - .one( "focus", function() { - ok( true, "event triggered" ); - start(); - }) - .focus( 500, function() { - ok( true, "callback triggered" ); - }); -}); - test( "innerWidth - getter", function() { expect( 2 ); var el = $( "#dimensions" ); diff --git a/tests/unit/core/core_deprecated.js b/tests/unit/core/core_deprecated.js index bb06f77b2..f97b009a7 100644 --- a/tests/unit/core/core_deprecated.js +++ b/tests/unit/core/core_deprecated.js @@ -2,6 +2,34 @@ module( "core - deprecated" ); +asyncTest( "focus - original functionality", function() { + expect( 1 ); + $( "#inputTabindex0" ) + .one( "focus", function() { + ok( true, "event triggered" ); + start(); + }) + .focus(); +}); + +asyncTest( "focus", function() { + expect( 2 ); + + // support: IE 8 + // IE sometimes gets confused about what's focused if we don't explicitly + // focus a different element first + $( "body" ).focus(); + + $( "#inputTabindex0" ) + .one( "focus", function() { + ok( true, "event triggered" ); + start(); + }) + .focus( 500, function() { + ok( true, "callback triggered" ); + }); +}); + test( "zIndex", function() { expect( 7 ); var el = $( "#zIndexAutoWithParent" ), diff --git a/ui/core.js b/ui/core.js index 7323baeeb..a946d522b 100644 --- a/ui/core.js +++ b/ui/core.js @@ -48,22 +48,6 @@ $.extend( $.ui, { // plugins $.fn.extend({ - focus: (function( orig ) { - return function( delay, fn ) { - return typeof delay === "number" ? - this.each(function() { - var elem = this; - setTimeout(function() { - $( elem ).focus(); - if ( fn ) { - fn.call( elem ); - } - }, delay ); - }) : - orig.apply( this, arguments ); - }; - })( $.fn.focus ), - scrollParent: function() { var position = this.css( "position" ), excludeStaticParent = position === "absolute", @@ -225,6 +209,22 @@ $.ui.ie = !!/msie [\w.]+/.exec( navigator.userAgent.toLowerCase() ); $.support.selectstart = "onselectstart" in document.createElement( "div" ); $.fn.extend({ + focus: (function( orig ) { + return function( delay, fn ) { + return typeof delay === "number" ? + this.each(function() { + var elem = this; + setTimeout(function() { + $( elem ).focus(); + if ( fn ) { + fn.call( elem ); + } + }, delay ); + }) : + orig.apply( this, arguments ); + }; + })( $.fn.focus ), + disableSelection: function() { return this.bind( ( $.support.selectstart ? "selectstart" : "mousedown" ) + ".ui-disableSelection", function( event ) { diff --git a/ui/dialog.js b/ui/dialog.js index 07100c934..12dc1da65 100644 --- a/ui/dialog.js +++ b/ui/dialog.js @@ -342,10 +342,14 @@ return $.widget( "ui.dialog", { last = tabbables.filter( ":last" ); if ( ( event.target === last[0] || event.target === this.uiDialog[0] ) && !event.shiftKey ) { - first.focus( 1 ); + this._delay(function() { + first.focus(); + }); event.preventDefault(); } else if ( ( event.target === first[0] || event.target === this.uiDialog[0] ) && event.shiftKey ) { - last.focus( 1 ); + this._delay(function() { + first.focus(); + }); event.preventDefault(); } }, -- 2.39.5