Debian Codegraph @

inst/lib/bs-a11y-p/src/js/functions.js

raw
1
2 // GENERAL UTILITY FUNCTIONS
3 // ===============================
4
5 var uniqueId = function(prefix) {
6 return (prefix || 'ui-id') + '-' + Math.floor((Math.random()*1000)+1)
7 }
8
9
10 var removeMultiValAttributes = function (el, attr, val) {
11 var describedby = (el.attr( attr ) || "").split( /\s+/ )
12 , index = $.inArray(val, describedby)
13 if ( index !== -1 ) {
14 describedby.splice( index, 1 )
15 }
16 describedby = $.trim( describedby.join( " " ) )
17 if (describedby ) {
18 el.attr( attr, describedby )
19 } else {
20 el.removeAttr( attr )
21 }
22 }
23
24 // selectors Courtesy: https://github.com/jquery/jquery-ui/blob/master/ui/focusable.js and tabbable.js
25 /*
26 Copyright jQuery Foundation and other contributors, https://jquery.org/
27
28 This software consists of voluntary contributions made by many
29 individuals. For exact contribution history, see the revision history
30 available at https://github.com/jquery/jquery-ui
31
32 The following license applies to all parts of this software except as
33 documented below:
34
35 ====
36
37 Permission is hereby granted, free of charge, to any person obtaining
38 a copy of this software and associated documentation files (the
39 "Software"), to deal in the Software without restriction, including
40 without limitation the rights to use, copy, modify, merge, publish,
41 distribute, sublicense, and/or sell copies of the Software, and to
42 permit persons to whom the Software is furnished to do so, subject to
43 the following conditions:
44
45 The above copyright notice and this permission notice shall be
46 included in all copies or substantial portions of the Software.
47
48 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
49 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
50 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
51 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
52 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
53 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
54 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
55
56 ====
57
58 Copyright and related rights for sample code are waived via CC0. Sample
59 code is defined as all source code contained within the demos directory.
60
61 CC0: http://creativecommons.org/publicdomain/zero/1.0/
62
63 ====
64 */
65
66 var focusable = function ( element, isTabIndexNotNaN ) {
67 var map, mapName, img,
68 nodeName = element.nodeName.toLowerCase();
69 if ( "area" === nodeName ) {
70 map = element.parentNode;
71 mapName = map.name;
72 if ( !element.href || !mapName || map.nodeName.toLowerCase() !== "map" ) {
73 return false;
74 }
75 img = $( "img[usemap='#" + mapName + "']" )[ 0 ];
76 return !!img && visible( img );
77 }
78 return ( /input|select|textarea|button|object/.test( nodeName ) ?
79 !element.disabled :
80 "a" === nodeName ?
81 element.href || isTabIndexNotNaN :isTabIndexNotNaN) && visible( element ); // the element and all of its ancestors must be visible
82 }
83 var visible = function ( element ) {
84 return $.expr.filters.visible( element ) &&
85 !$( element ).parents().addBack().filter(function() {
86 return $.css( this, "visibility" ) === "hidden";
87 }).length;
88 }
89
90 $.extend( $.expr[ ":" ], {
91 data: $.expr.createPseudo ?
92 $.expr.createPseudo(function( dataName ) {
93 return function( elem ) {
94 return !!$.data( elem, dataName );
95 };
96 }) :
97 // support: jQuery <1.8
98 function( elem, i, match ) {
99 return !!$.data( elem, match[ 3 ] );
100 },
101
102 focusable: function( element ) {
103 return focusable( element, !isNaN( $.attr( element, "tabindex" ) ) );
104 },
105
106 tabbable: function( element ) {
107 var tabIndex = $.attr( element, "tabindex" ),
108 isTabIndexNaN = isNaN( tabIndex );
109 return ( isTabIndexNaN || tabIndex >= 0 ) && focusable( element, !isTabIndexNaN );
110 }
111 });