4 "../data/var/dataPriv",
6 ], function( jQuery, rnotwhite, dataPriv ) {
8 var rclass = /[\t\r\n\f]/g;
10 function getClass( elem ) {
11 return elem.getAttribute && elem.getAttribute( "class" ) || "";
15 addClass: function( value ) {
16 var classes, elem, cur, curValue, clazz, j, finalValue,
19 if ( jQuery.isFunction( value ) ) {
20 return this.each( function( j ) {
21 jQuery( this ).addClass( value.call( this, j, getClass( this ) ) );
25 if ( typeof value === "string" && value ) {
26 classes = value.match( rnotwhite ) || [];
28 while ( ( elem = this[ i++ ] ) ) {
29 curValue = getClass( elem );
30 cur = elem.nodeType === 1 &&
31 ( " " + curValue + " " ).replace( rclass, " " );
35 while ( ( clazz = classes[ j++ ] ) ) {
36 if ( cur.indexOf( " " + clazz + " " ) < 0 ) {
41 // Only assign if different to avoid unneeded rendering.
42 finalValue = jQuery.trim( cur );
43 if ( curValue !== finalValue ) {
44 elem.setAttribute( "class", finalValue );
53 removeClass: function( value ) {
54 var classes, elem, cur, curValue, clazz, j, finalValue,
57 if ( jQuery.isFunction( value ) ) {
58 return this.each( function( j ) {
59 jQuery( this ).removeClass( value.call( this, j, getClass( this ) ) );
63 if ( !arguments.length ) {
64 return this.attr( "class", "" );
67 if ( typeof value === "string" && value ) {
68 classes = value.match( rnotwhite ) || [];
70 while ( ( elem = this[ i++ ] ) ) {
71 curValue = getClass( elem );
73 // This expression is here for better compressibility (see addClass)
74 cur = elem.nodeType === 1 &&
75 ( " " + curValue + " " ).replace( rclass, " " );
79 while ( ( clazz = classes[ j++ ] ) ) {
81 // Remove *all* instances
82 while ( cur.indexOf( " " + clazz + " " ) > -1 ) {
83 cur = cur.replace( " " + clazz + " ", " " );
87 // Only assign if different to avoid unneeded rendering.
88 finalValue = jQuery.trim( cur );
89 if ( curValue !== finalValue ) {
90 elem.setAttribute( "class", finalValue );
99 toggleClass: function( value, stateVal ) {
100 var type = typeof value;
102 if ( typeof stateVal === "boolean" && type === "string" ) {
103 return stateVal ? this.addClass( value ) : this.removeClass( value );
106 if ( jQuery.isFunction( value ) ) {
107 return this.each( function( i ) {
108 jQuery( this ).toggleClass(
109 value.call( this, i, getClass( this ), stateVal ),
115 return this.each( function() {
116 var className, i, self, classNames;
118 if ( type === "string" ) {
120 // Toggle individual class names
122 self = jQuery( this );
123 classNames = value.match( rnotwhite ) || [];
125 while ( ( className = classNames[ i++ ] ) ) {
127 // Check each className given, space separated list
128 if ( self.hasClass( className ) ) {
129 self.removeClass( className );
131 self.addClass( className );
135 // Toggle whole class name
136 } else if ( value === undefined || type === "boolean" ) {
137 className = getClass( this );
140 // Store className if set
141 dataPriv.set( this, "__className__", className );
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 ?
152 dataPriv.get( this, "__className__" ) || ""
159 hasClass: function( selector ) {
163 className = " " + selector + " ";
164 while ( ( elem = this[ i++ ] ) ) {
165 if ( elem.nodeType === 1 &&
166 ( " " + getClass( elem ) + " " ).replace( rclass, " " )
167 .indexOf( className ) > -1