Permalink
Browse files

Core: Deprecate .focus( n ), replace in dialog with explicit timeouts

Fixes #9646
  • Loading branch information...
jzaefferer committed Feb 21, 2014
1 parent 1c278f9 commit df6110c0d424ff3306fdd5576011f2dcf4d242d0
Showing with 50 additions and 46 deletions.
  1. +0 −28 tests/unit/core/core.js
  2. +28 −0 tests/unit/core/core_deprecated.js
  3. +16 −16 ui/core.js
  4. +6 −2 ui/dialog.js
View
@@ -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" );
@@ -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" ),
View
@@ -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 ) {
View
@@ -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();
}
},

0 comments on commit df6110c

Please sign in to comment.