aboutsummaryrefslogtreecommitdiffstats
path: root/ui/focusable.js
diff options
context:
space:
mode:
authorAlexander Schmitz <arschmitz@gmail.com>2015-07-16 09:09:14 -0400
committerAlexander Schmitz <arschmitz@gmail.com>2015-08-08 00:29:36 -0400
commit475ccefd97ec24d76cfa6767c007501c14934ba6 (patch)
tree075cd4a1a518cac8e801e9ed5c0c6e6bc1f37cb4 /ui/focusable.js
parent4916487440b0c087e6e5996522cf478af26df591 (diff)
downloadjquery-ui-475ccefd97ec24d76cfa6767c007501c14934ba6.tar.gz
jquery-ui-475ccefd97ec24d76cfa6767c007501c14934ba6.zip
Core: Move focusable into its own module
Ref #9647
Diffstat (limited to 'ui/focusable.js')
-rw-r--r--ui/focusable.js64
1 files changed, 64 insertions, 0 deletions
diff --git a/ui/focusable.js b/ui/focusable.js
new file mode 100644
index 000000000..b6e86e062
--- /dev/null
+++ b/ui/focusable.js
@@ -0,0 +1,64 @@
+/*!
+ * 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 + "']" )[ 0 ];
+ return !!img && visible( img );
+ }
+ return ( /^(input|select|textarea|button|object)$/.test( nodeName ) ?
+ !element.disabled :
+ "a" === nodeName ?
+ element.href || hasTabindex :
+ hasTabindex ) &&
+ // the element and all of its ancestors must be visible
+ visible( element );
+};
+
+function visible( element ) {
+ return $.expr.filters.visible( element ) &&
+ !$( element ).parents().addBack().filter( function() {
+ return $.css( this, "visibility" ) === "hidden";
+ } ).length;
+}
+
+$.extend( $.expr[ ":" ], {
+ focusable: function( element ) {
+ return $.ui.focusable( element, $.attr( element, "tabindex" ) != null );
+ }
+} );
+
+return $.ui.focusable;
+
+} ) );