2015-07-16 13:09:14 +00:00
|
|
|
/*!
|
|
|
|
* jQuery UI Focusable @VERSION
|
|
|
|
* http://jqueryui.com
|
|
|
|
*
|
|
|
|
* Copyright jQuery Foundation and other contributors
|
|
|
|
* Released under the MIT license.
|
|
|
|
* http://jquery.org/license
|
|
|
|
*/
|
|
|
|
|
2016-01-15 02:07:53 +00:00
|
|
|
//>>label: :focusable Selector
|
2015-07-16 13:09:14 +00:00
|
|
|
//>>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( $ ) {
|
|
|
|
|
2015-08-21 04:14:57 +00:00
|
|
|
// Selectors
|
2015-07-16 13:09:14 +00:00
|
|
|
$.ui.focusable = function( element, hasTabindex ) {
|
2016-05-25 12:37:28 +00:00
|
|
|
var map, mapName, img, focusableIfVisible, fieldset,
|
2015-07-16 13:09:14 +00:00
|
|
|
nodeName = element.nodeName.toLowerCase();
|
2016-05-25 12:37:28 +00:00
|
|
|
|
2015-07-16 13:09:14 +00:00
|
|
|
if ( "area" === nodeName ) {
|
|
|
|
map = element.parentNode;
|
|
|
|
mapName = map.name;
|
|
|
|
if ( !element.href || !mapName || map.nodeName.toLowerCase() !== "map" ) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-08-04 23:46:58 +00:00
|
|
|
img = $( "img[usemap='#" + mapName + "']" );
|
|
|
|
return img.length > 0 && img.is( ":visible" );
|
2015-07-16 13:09:14 +00:00
|
|
|
}
|
2016-05-25 12:37:28 +00:00
|
|
|
|
|
|
|
if ( /^(input|select|textarea|button|object)$/.test( nodeName ) ) {
|
|
|
|
focusableIfVisible = !element.disabled;
|
|
|
|
|
|
|
|
if ( focusableIfVisible ) {
|
|
|
|
|
|
|
|
// Form controls within a disabled fieldset are disabled.
|
|
|
|
// However, controls within the fieldset's legend do not get disabled.
|
|
|
|
// Since controls generally aren't placed inside legends, we skip
|
|
|
|
// this portion of the check.
|
|
|
|
fieldset = $( element ).closest( "fieldset" )[ 0 ];
|
|
|
|
if ( fieldset ) {
|
|
|
|
focusableIfVisible = !fieldset.disabled;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if ( "a" === nodeName ) {
|
|
|
|
focusableIfVisible = element.href || hasTabindex;
|
|
|
|
} else {
|
|
|
|
focusableIfVisible = hasTabindex;
|
|
|
|
}
|
|
|
|
|
|
|
|
return focusableIfVisible && $( element ).is( ":visible" ) && visible( $( element ) );
|
2015-07-16 13:09:14 +00:00
|
|
|
};
|
|
|
|
|
2015-09-25 14:33:58 +00:00
|
|
|
// 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" );
|
|
|
|
}
|
2020-10-14 21:53:11 +00:00
|
|
|
return visibility === "visible";
|
2015-09-25 14:33:58 +00:00
|
|
|
}
|
|
|
|
|
2016-12-02 13:41:30 +00:00
|
|
|
$.extend( $.expr.pseudos, {
|
2015-07-16 13:09:14 +00:00
|
|
|
focusable: function( element ) {
|
|
|
|
return $.ui.focusable( element, $.attr( element, "tabindex" ) != null );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
return $.ui.focusable;
|
|
|
|
|
|
|
|
} ) );
|