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