/bower_components/jquery/src/attributes/classes.js |
@@ -1,47 +1,49 @@ |
define( [ |
define([ |
"../core", |
"../core/stripAndCollapse", |
"../var/rnothtmlwhite", |
"../data/var/dataPriv", |
"../var/rnotwhite", |
"../var/strundefined", |
"../data/var/data_priv", |
"../core/init" |
], function( jQuery, stripAndCollapse, rnothtmlwhite, dataPriv ) { |
], function( jQuery, rnotwhite, strundefined, data_priv ) { |
|
"use strict"; |
var rclass = /[\t\r\n\f]/g; |
|
function getClass( elem ) { |
return elem.getAttribute && elem.getAttribute( "class" ) || ""; |
} |
|
jQuery.fn.extend( { |
jQuery.fn.extend({ |
addClass: function( value ) { |
var classes, elem, cur, curValue, clazz, j, finalValue, |
i = 0; |
var classes, elem, cur, clazz, j, finalValue, |
proceed = typeof value === "string" && value, |
i = 0, |
len = this.length; |
|
if ( jQuery.isFunction( value ) ) { |
return this.each( function( j ) { |
jQuery( this ).addClass( value.call( this, j, getClass( this ) ) ); |
} ); |
return this.each(function( j ) { |
jQuery( this ).addClass( value.call( this, j, this.className ) ); |
}); |
} |
|
if ( typeof value === "string" && value ) { |
classes = value.match( rnothtmlwhite ) || []; |
if ( proceed ) { |
// The disjunction here is for better compressibility (see removeClass) |
classes = ( value || "" ).match( rnotwhite ) || []; |
|
while ( ( elem = this[ i++ ] ) ) { |
curValue = getClass( elem ); |
cur = elem.nodeType === 1 && ( " " + stripAndCollapse( curValue ) + " " ); |
for ( ; i < len; i++ ) { |
elem = this[ i ]; |
cur = elem.nodeType === 1 && ( elem.className ? |
( " " + elem.className + " " ).replace( rclass, " " ) : |
" " |
); |
|
if ( cur ) { |
j = 0; |
while ( ( clazz = classes[ j++ ] ) ) { |
while ( (clazz = classes[j++]) ) { |
if ( cur.indexOf( " " + clazz + " " ) < 0 ) { |
cur += clazz + " "; |
} |
} |
|
// Only assign if different to avoid unneeded rendering. |
finalValue = stripAndCollapse( cur ); |
if ( curValue !== finalValue ) { |
elem.setAttribute( "class", finalValue ); |
// only assign if different to avoid unneeded rendering. |
finalValue = jQuery.trim( cur ); |
if ( elem.className !== finalValue ) { |
elem.className = finalValue; |
} |
} |
} |
@@ -51,42 +53,40 @@ |
}, |
|
removeClass: function( value ) { |
var classes, elem, cur, curValue, clazz, j, finalValue, |
i = 0; |
var classes, elem, cur, clazz, j, finalValue, |
proceed = arguments.length === 0 || typeof value === "string" && value, |
i = 0, |
len = this.length; |
|
if ( jQuery.isFunction( value ) ) { |
return this.each( function( j ) { |
jQuery( this ).removeClass( value.call( this, j, getClass( this ) ) ); |
} ); |
return this.each(function( j ) { |
jQuery( this ).removeClass( value.call( this, j, this.className ) ); |
}); |
} |
if ( proceed ) { |
classes = ( value || "" ).match( rnotwhite ) || []; |
|
if ( !arguments.length ) { |
return this.attr( "class", "" ); |
} |
|
if ( typeof value === "string" && value ) { |
classes = value.match( rnothtmlwhite ) || []; |
|
while ( ( elem = this[ i++ ] ) ) { |
curValue = getClass( elem ); |
|
for ( ; i < len; i++ ) { |
elem = this[ i ]; |
// This expression is here for better compressibility (see addClass) |
cur = elem.nodeType === 1 && ( " " + stripAndCollapse( curValue ) + " " ); |
cur = elem.nodeType === 1 && ( elem.className ? |
( " " + elem.className + " " ).replace( rclass, " " ) : |
"" |
); |
|
if ( cur ) { |
j = 0; |
while ( ( clazz = classes[ j++ ] ) ) { |
|
while ( (clazz = classes[j++]) ) { |
// Remove *all* instances |
while ( cur.indexOf( " " + clazz + " " ) > -1 ) { |
while ( cur.indexOf( " " + clazz + " " ) >= 0 ) { |
cur = cur.replace( " " + clazz + " ", " " ); |
} |
} |
|
// Only assign if different to avoid unneeded rendering. |
finalValue = stripAndCollapse( cur ); |
if ( curValue !== finalValue ) { |
elem.setAttribute( "class", finalValue ); |
finalValue = value ? jQuery.trim( cur ) : ""; |
if ( elem.className !== finalValue ) { |
elem.className = finalValue; |
} |
} |
} |
@@ -103,26 +103,20 @@ |
} |
|
if ( jQuery.isFunction( value ) ) { |
return this.each( function( i ) { |
jQuery( this ).toggleClass( |
value.call( this, i, getClass( this ), stateVal ), |
stateVal |
); |
} ); |
return this.each(function( i ) { |
jQuery( this ).toggleClass( value.call(this, i, this.className, stateVal), stateVal ); |
}); |
} |
|
return this.each( function() { |
var className, i, self, classNames; |
|
return this.each(function() { |
if ( type === "string" ) { |
|
// Toggle individual class names |
i = 0; |
self = jQuery( this ); |
classNames = value.match( rnothtmlwhite ) || []; |
var className, |
i = 0, |
self = jQuery( this ), |
classNames = value.match( rnotwhite ) || []; |
|
while ( ( className = classNames[ i++ ] ) ) { |
|
while ( (className = classNames[ i++ ]) ) { |
// Check each className given, space separated list |
if ( self.hasClass( className ) ) { |
self.removeClass( className ); |
@@ -132,12 +126,10 @@ |
} |
|
// Toggle whole class name |
} else if ( value === undefined || type === "boolean" ) { |
className = getClass( this ); |
if ( className ) { |
|
// Store className if set |
dataPriv.set( this, "__className__", className ); |
} else if ( type === strundefined || type === "boolean" ) { |
if ( this.className ) { |
// store className if set |
data_priv.set( this, "__className__", this.className ); |
} |
|
// If the element has a class name or if we're passed `false`, |
@@ -144,31 +136,23 @@ |
// then remove the whole classname (if there was one, the above saved it). |
// Otherwise bring back whatever was previously saved (if anything), |
// falling back to the empty string if nothing was stored. |
if ( this.setAttribute ) { |
this.setAttribute( "class", |
className || value === false ? |
"" : |
dataPriv.get( this, "__className__" ) || "" |
); |
} |
this.className = this.className || value === false ? "" : data_priv.get( this, "__className__" ) || ""; |
} |
} ); |
}); |
}, |
|
hasClass: function( selector ) { |
var className, elem, |
i = 0; |
|
className = " " + selector + " "; |
while ( ( elem = this[ i++ ] ) ) { |
if ( elem.nodeType === 1 && |
( " " + stripAndCollapse( getClass( elem ) ) + " " ).indexOf( className ) > -1 ) { |
return true; |
var className = " " + selector + " ", |
i = 0, |
l = this.length; |
for ( ; i < l; i++ ) { |
if ( this[i].nodeType === 1 && (" " + this[i].className + " ").replace(rclass, " ").indexOf( className ) >= 0 ) { |
return true; |
} |
} |
|
return false; |
} |
} ); |
}); |
|
} ); |
}); |