mirror of
https://github.com/jquery/jquery-ui.git
synced 2025-01-07 20:34:24 +00:00
Core: Deprecate .focus( n ), replace in dialog with explicit timeouts
Fixes #9646
This commit is contained in:
parent
1c278f97fc
commit
df6110c0d4
@ -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" ),
|
||||
|
32
ui/core.js
32
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 ) {
|
||||
|
@ -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();
|
||||
}
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user