]> git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/ex-mode/node_modules/space-pen/node_modules/jquery/src/attributes/attr.js
a4414d11fc9e1a609f4b4254c836434440402792
[rbdr/dotfiles] / atom / packages / ex-mode / node_modules / space-pen / node_modules / jquery / src / attributes / attr.js
1 define([
2 "../core",
3 "../var/rnotwhite",
4 "../var/strundefined",
5 "../core/access",
6 "./support",
7 "../selector"
8 ], function( jQuery, rnotwhite, strundefined, access, support ) {
9
10 var nodeHook, boolHook,
11 attrHandle = jQuery.expr.attrHandle;
12
13 jQuery.fn.extend({
14 attr: function( name, value ) {
15 return access( this, jQuery.attr, name, value, arguments.length > 1 );
16 },
17
18 removeAttr: function( name ) {
19 return this.each(function() {
20 jQuery.removeAttr( this, name );
21 });
22 }
23 });
24
25 jQuery.extend({
26 attr: function( elem, name, value ) {
27 var hooks, ret,
28 nType = elem.nodeType;
29
30 // don't get/set attributes on text, comment and attribute nodes
31 if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
32 return;
33 }
34
35 // Fallback to prop when attributes are not supported
36 if ( typeof elem.getAttribute === strundefined ) {
37 return jQuery.prop( elem, name, value );
38 }
39
40 // All attributes are lowercase
41 // Grab necessary hook if one is defined
42 if ( nType !== 1 || !jQuery.isXMLDoc( elem ) ) {
43 name = name.toLowerCase();
44 hooks = jQuery.attrHooks[ name ] ||
45 ( jQuery.expr.match.bool.test( name ) ? boolHook : nodeHook );
46 }
47
48 if ( value !== undefined ) {
49
50 if ( value === null ) {
51 jQuery.removeAttr( elem, name );
52
53 } else if ( hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ) {
54 return ret;
55
56 } else {
57 elem.setAttribute( name, value + "" );
58 return value;
59 }
60
61 } else if ( hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ) {
62 return ret;
63
64 } else {
65 ret = jQuery.find.attr( elem, name );
66
67 // Non-existent attributes return null, we normalize to undefined
68 return ret == null ?
69 undefined :
70 ret;
71 }
72 },
73
74 removeAttr: function( elem, value ) {
75 var name, propName,
76 i = 0,
77 attrNames = value && value.match( rnotwhite );
78
79 if ( attrNames && elem.nodeType === 1 ) {
80 while ( (name = attrNames[i++]) ) {
81 propName = jQuery.propFix[ name ] || name;
82
83 // Boolean attributes get special treatment (#10870)
84 if ( jQuery.expr.match.bool.test( name ) ) {
85 // Set corresponding property to false
86 elem[ propName ] = false;
87 }
88
89 elem.removeAttribute( name );
90 }
91 }
92 },
93
94 attrHooks: {
95 type: {
96 set: function( elem, value ) {
97 if ( !support.radioValue && value === "radio" &&
98 jQuery.nodeName( elem, "input" ) ) {
99 var val = elem.value;
100 elem.setAttribute( "type", value );
101 if ( val ) {
102 elem.value = val;
103 }
104 return value;
105 }
106 }
107 }
108 }
109 });
110
111 // Hooks for boolean attributes
112 boolHook = {
113 set: function( elem, value, name ) {
114 if ( value === false ) {
115 // Remove boolean attributes when set to false
116 jQuery.removeAttr( elem, name );
117 } else {
118 elem.setAttribute( name, name );
119 }
120 return name;
121 }
122 };
123 jQuery.each( jQuery.expr.match.bool.source.match( /\w+/g ), function( i, name ) {
124 var getter = attrHandle[ name ] || jQuery.find.attr;
125
126 attrHandle[ name ] = function( elem, name, isXML ) {
127 var ret, handle;
128 if ( !isXML ) {
129 // Avoid an infinite loop by temporarily removing this function from the getter
130 handle = attrHandle[ name ];
131 attrHandle[ name ] = ret;
132 ret = getter( elem, name, isXML ) != null ?
133 name.toLowerCase() :
134 null;
135 attrHandle[ name ] = handle;
136 }
137 return ret;
138 };
139 });
140
141 });