]> git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/ex-mode/node_modules/space-pen/node_modules/jquery/src/attributes/classes.js
101138415f874ad1b82f018680976f39e91a1762
[rbdr/dotfiles] / atom / packages / ex-mode / node_modules / space-pen / node_modules / jquery / src / attributes / classes.js
1 define([
2 "../core",
3 "../var/rnotwhite",
4 "../var/strundefined",
5 "../data/var/data_priv",
6 "../core/init"
7 ], function( jQuery, rnotwhite, strundefined, data_priv ) {
8
9 var rclass = /[\t\r\n\f]/g;
10
11 jQuery.fn.extend({
12 addClass: function( value ) {
13 var classes, elem, cur, clazz, j, finalValue,
14 proceed = typeof value === "string" && value,
15 i = 0,
16 len = this.length;
17
18 if ( jQuery.isFunction( value ) ) {
19 return this.each(function( j ) {
20 jQuery( this ).addClass( value.call( this, j, this.className ) );
21 });
22 }
23
24 if ( proceed ) {
25 // The disjunction here is for better compressibility (see removeClass)
26 classes = ( value || "" ).match( rnotwhite ) || [];
27
28 for ( ; i < len; i++ ) {
29 elem = this[ i ];
30 cur = elem.nodeType === 1 && ( elem.className ?
31 ( " " + elem.className + " " ).replace( rclass, " " ) :
32 " "
33 );
34
35 if ( cur ) {
36 j = 0;
37 while ( (clazz = classes[j++]) ) {
38 if ( cur.indexOf( " " + clazz + " " ) < 0 ) {
39 cur += clazz + " ";
40 }
41 }
42
43 // only assign if different to avoid unneeded rendering.
44 finalValue = jQuery.trim( cur );
45 if ( elem.className !== finalValue ) {
46 elem.className = finalValue;
47 }
48 }
49 }
50 }
51
52 return this;
53 },
54
55 removeClass: function( value ) {
56 var classes, elem, cur, clazz, j, finalValue,
57 proceed = arguments.length === 0 || typeof value === "string" && value,
58 i = 0,
59 len = this.length;
60
61 if ( jQuery.isFunction( value ) ) {
62 return this.each(function( j ) {
63 jQuery( this ).removeClass( value.call( this, j, this.className ) );
64 });
65 }
66 if ( proceed ) {
67 classes = ( value || "" ).match( rnotwhite ) || [];
68
69 for ( ; i < len; i++ ) {
70 elem = this[ i ];
71 // This expression is here for better compressibility (see addClass)
72 cur = elem.nodeType === 1 && ( elem.className ?
73 ( " " + elem.className + " " ).replace( rclass, " " ) :
74 ""
75 );
76
77 if ( cur ) {
78 j = 0;
79 while ( (clazz = classes[j++]) ) {
80 // Remove *all* instances
81 while ( cur.indexOf( " " + clazz + " " ) >= 0 ) {
82 cur = cur.replace( " " + clazz + " ", " " );
83 }
84 }
85
86 // Only assign if different to avoid unneeded rendering.
87 finalValue = value ? jQuery.trim( cur ) : "";
88 if ( elem.className !== finalValue ) {
89 elem.className = finalValue;
90 }
91 }
92 }
93 }
94
95 return this;
96 },
97
98 toggleClass: function( value, stateVal ) {
99 var type = typeof value;
100
101 if ( typeof stateVal === "boolean" && type === "string" ) {
102 return stateVal ? this.addClass( value ) : this.removeClass( value );
103 }
104
105 if ( jQuery.isFunction( value ) ) {
106 return this.each(function( i ) {
107 jQuery( this ).toggleClass( value.call(this, i, this.className, stateVal), stateVal );
108 });
109 }
110
111 return this.each(function() {
112 if ( type === "string" ) {
113 // Toggle individual class names
114 var className,
115 i = 0,
116 self = jQuery( this ),
117 classNames = value.match( rnotwhite ) || [];
118
119 while ( (className = classNames[ i++ ]) ) {
120 // Check each className given, space separated list
121 if ( self.hasClass( className ) ) {
122 self.removeClass( className );
123 } else {
124 self.addClass( className );
125 }
126 }
127
128 // Toggle whole class name
129 } else if ( type === strundefined || type === "boolean" ) {
130 if ( this.className ) {
131 // store className if set
132 data_priv.set( this, "__className__", this.className );
133 }
134
135 // If the element has a class name or if we're passed `false`,
136 // then remove the whole classname (if there was one, the above saved it).
137 // Otherwise bring back whatever was previously saved (if anything),
138 // falling back to the empty string if nothing was stored.
139 this.className = this.className || value === false ? "" : data_priv.get( this, "__className__" ) || "";
140 }
141 });
142 },
143
144 hasClass: function( selector ) {
145 var className = " " + selector + " ",
146 i = 0,
147 l = this.length;
148 for ( ; i < l; i++ ) {
149 if ( this[i].nodeType === 1 && (" " + this[i].className + " ").replace(rclass, " ").indexOf( className ) >= 0 ) {
150 return true;
151 }
152 }
153
154 return false;
155 }
156 });
157
158 });