mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-12-07 06:14:24 +00:00
d3025968f3
Ref #14596 Ref gh-1583 Closes gh-1605
68 lines
1.7 KiB
JavaScript
68 lines
1.7 KiB
JavaScript
/*!
|
|
* jQuery UI Focusable @VERSION
|
|
* http://jqueryui.com
|
|
*
|
|
* Copyright jQuery Foundation and other contributors
|
|
* Released under the MIT license.
|
|
* http://jquery.org/license
|
|
*/
|
|
|
|
//>>label: focusable
|
|
//>>group: Core
|
|
//>>description: Selects elements which can be focused.
|
|
//>>docs: http://api.jqueryui.com/focusable-selector/
|
|
|
|
( function( factory ) {
|
|
if ( typeof define === "function" && define.amd ) {
|
|
|
|
// AMD. Register as an anonymous module.
|
|
define( [ "jquery", "./version" ], factory );
|
|
} else {
|
|
|
|
// Browser globals
|
|
factory( jQuery );
|
|
}
|
|
} ( function( $ ) {
|
|
|
|
// Selectors
|
|
$.ui.focusable = function( element, hasTabindex ) {
|
|
var map, mapName, img,
|
|
nodeName = element.nodeName.toLowerCase();
|
|
if ( "area" === nodeName ) {
|
|
map = element.parentNode;
|
|
mapName = map.name;
|
|
if ( !element.href || !mapName || map.nodeName.toLowerCase() !== "map" ) {
|
|
return false;
|
|
}
|
|
img = $( "img[usemap='#" + mapName + "']" );
|
|
return img.length > 0 && img.is( ":visible" );
|
|
}
|
|
return ( /^(input|select|textarea|button|object)$/.test( nodeName ) ?
|
|
!element.disabled :
|
|
"a" === nodeName ?
|
|
element.href || hasTabindex :
|
|
hasTabindex ) &&
|
|
$( element ).is( ":visible" ) && visible( $( element ) );
|
|
};
|
|
|
|
// Support: IE 8 only
|
|
// IE 8 doesn't resolve inherit to visible/hidden for computed values
|
|
function visible( element ) {
|
|
var visibility = element.css( "visibility" );
|
|
while ( visibility === "inherit" ) {
|
|
element = element.parent();
|
|
visibility = element.css( "visibility" );
|
|
}
|
|
return visibility !== "hidden";
|
|
}
|
|
|
|
$.extend( $.expr[ ":" ], {
|
|
focusable: function( element ) {
|
|
return $.ui.focusable( element, $.attr( element, "tabindex" ) != null );
|
|
}
|
|
} );
|
|
|
|
return $.ui.focusable;
|
|
|
|
} ) );
|