From: Alexander Schmitz Date: Thu, 16 Jul 2015 13:09:14 +0000 (-0400) Subject: Core: Move focusable into its own module X-Git-Tag: 1.12.0-beta.1~227 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=475ccefd97ec24d76cfa6767c007501c14934ba6;p=jquery-ui.git Core: Move focusable into its own module Ref #9647 --- diff --git a/tests/unit/core/selector.js b/tests/unit/core/selector.js index 14f1de70e..dee24809e 100644 --- a/tests/unit/core/selector.js +++ b/tests/unit/core/selector.js @@ -1,7 +1,8 @@ define( [ "jquery", "ui/core", - "ui/data" + "ui/data", + "ui/focusable" ], function( $ ) { module( "core - selectors" ); diff --git a/ui/core.js b/ui/core.js index 1072e89f1..a0931dffa 100644 --- a/ui/core.js +++ b/ui/core.js @@ -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 ); } } ); diff --git a/ui/dialog.js b/ui/dialog.js index 11ff77c6b..4dbf2ab34 100644 --- a/ui/dialog.js +++ b/ui/dialog.js @@ -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 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; + +} ) );