aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJörn Zaefferer <joern.zaefferer@gmail.com>2014-02-21 13:22:39 +0100
committerJörn Zaefferer <joern.zaefferer@gmail.com>2014-02-21 19:57:34 +0100
commitdf6110c0d424ff3306fdd5576011f2dcf4d242d0 (patch)
treeccf0b23716deebd37e27578e01d5b9b1790d5a16
parent1c278f97fca0aa1f3a473396e15c217419a99746 (diff)
downloadjquery-ui-df6110c0d424ff3306fdd5576011f2dcf4d242d0.tar.gz
jquery-ui-df6110c0d424ff3306fdd5576011f2dcf4d242d0.zip
Core: Deprecate .focus( n ), replace in dialog with explicit timeouts
Fixes #9646
-rw-r--r--tests/unit/core/core.js28
-rw-r--r--tests/unit/core/core_deprecated.js28
-rw-r--r--ui/core.js32
-rw-r--r--ui/dialog.js8
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();
}
},