]> source.dussan.org Git - jquery-ui.git/commitdiff
Core: Move focusable into its own module
authorAlexander Schmitz <arschmitz@gmail.com>
Thu, 16 Jul 2015 13:09:14 +0000 (09:09 -0400)
committerAlexander Schmitz <arschmitz@gmail.com>
Sat, 8 Aug 2015 04:29:36 +0000 (00:29 -0400)
Ref #9647

tests/unit/core/selector.js
ui/core.js
ui/dialog.js
ui/focusable.js [new file with mode: 0644]

index 14f1de70e49e23f8dd033041f6ef95f395382a8e..dee24809e9744f0bd9b11b4b48a60015e0953cc1 100644 (file)
@@ -1,7 +1,8 @@
 define( [
        "jquery",
        "ui/core",
-       "ui/data"
+       "ui/data",
+       "ui/focusable"
 ], function( $ ) {
 
 module( "core - selectors" );
index 1072e89f15fcf226653bf972b52b95de17b3668a..a0931dffad239faa776f4d2dce0765701547b18e 100644 (file)
@@ -22,6 +22,7 @@
                        "jquery",
                        "./data",
                        "./disable-selection",
+                       "./focusable",
                        "./version"
                ], factory );
        } else {
@@ -180,44 +181,11 @@ $.fn.extend( {
        }
 } );
 
-// selectors
-function focusable( 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 focusable( element, $.attr( element, "tabindex" ) != null );
-       },
-
        tabbable: function( element ) {
                var tabIndex = $.attr( element, "tabindex" ),
                        hasTabindex = tabIndex != null;
-               return ( !hasTabindex || tabIndex >= 0 ) && focusable( element, hasTabindex );
+               return ( !hasTabindex || tabIndex >= 0 ) && $.ui.focusable( element, hasTabindex );
        }
 } );
 
index 11ff77c6b501b34bb0f3e23c4c4817c99447df55..4dbf2ab34317da29407723ad9488e97e9bb90851 100644 (file)
@@ -26,6 +26,7 @@
                        "./widget",
                        "./button",
                        "./draggable",
+                       "./focusable",
                        "./mouse",
                        "./position",
                        "./resizable",
diff --git a/ui/focusable.js b/ui/focusable.js
new file mode 100644 (file)
index 0000000..b6e86e0
--- /dev/null
@@ -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;
+
+} ) );