Blame view

app/bower_components/jquery/src/attributes/classes.js 4.17 KB
87c93a029   Dang YoungWorld   add modal
1
  define( [
f986e111b   TRUONG   add libs
2
  	"../core",
87c93a029   Dang YoungWorld   add modal
3
4
5
  	"../core/stripAndCollapse",
  	"../var/rnothtmlwhite",
  	"../data/var/dataPriv",
f986e111b   TRUONG   add libs
6
  	"../core/init"
87c93a029   Dang YoungWorld   add modal
7
  ], function( jQuery, stripAndCollapse, rnothtmlwhite, dataPriv ) {
f986e111b   TRUONG   add libs
8

87c93a029   Dang YoungWorld   add modal
9
  "use strict";
f986e111b   TRUONG   add libs
10

87c93a029   Dang YoungWorld   add modal
11
12
13
14
15
  function getClass( elem ) {
  	return elem.getAttribute && elem.getAttribute( "class" ) || "";
  }
  
  jQuery.fn.extend( {
f986e111b   TRUONG   add libs
16
  	addClass: function( value ) {
87c93a029   Dang YoungWorld   add modal
17
18
  		var classes, elem, cur, curValue, clazz, j, finalValue,
  			i = 0;
f986e111b   TRUONG   add libs
19
20
  
  		if ( jQuery.isFunction( value ) ) {
87c93a029   Dang YoungWorld   add modal
21
22
23
  			return this.each( function( j ) {
  				jQuery( this ).addClass( value.call( this, j, getClass( this ) ) );
  			} );
f986e111b   TRUONG   add libs
24
  		}
87c93a029   Dang YoungWorld   add modal
25
26
  		if ( typeof value === "string" && value ) {
  			classes = value.match( rnothtmlwhite ) || [];
f986e111b   TRUONG   add libs
27

87c93a029   Dang YoungWorld   add modal
28
29
30
  			while ( ( elem = this[ i++ ] ) ) {
  				curValue = getClass( elem );
  				cur = elem.nodeType === 1 && ( " " + stripAndCollapse( curValue ) + " " );
f986e111b   TRUONG   add libs
31
32
33
  
  				if ( cur ) {
  					j = 0;
87c93a029   Dang YoungWorld   add modal
34
  					while ( ( clazz = classes[ j++ ] ) ) {
f986e111b   TRUONG   add libs
35
36
37
38
  						if ( cur.indexOf( " " + clazz + " " ) < 0 ) {
  							cur += clazz + " ";
  						}
  					}
87c93a029   Dang YoungWorld   add modal
39
40
41
42
  					// Only assign if different to avoid unneeded rendering.
  					finalValue = stripAndCollapse( cur );
  					if ( curValue !== finalValue ) {
  						elem.setAttribute( "class", finalValue );
f986e111b   TRUONG   add libs
43
44
45
46
47
48
49
50
51
  					}
  				}
  			}
  		}
  
  		return this;
  	},
  
  	removeClass: function( value ) {
87c93a029   Dang YoungWorld   add modal
52
53
  		var classes, elem, cur, curValue, clazz, j, finalValue,
  			i = 0;
f986e111b   TRUONG   add libs
54
55
  
  		if ( jQuery.isFunction( value ) ) {
87c93a029   Dang YoungWorld   add modal
56
57
58
59
60
61
62
  			return this.each( function( j ) {
  				jQuery( this ).removeClass( value.call( this, j, getClass( this ) ) );
  			} );
  		}
  
  		if ( !arguments.length ) {
  			return this.attr( "class", "" );
f986e111b   TRUONG   add libs
63
  		}
f986e111b   TRUONG   add libs
64

87c93a029   Dang YoungWorld   add modal
65
66
67
68
69
  		if ( typeof value === "string" && value ) {
  			classes = value.match( rnothtmlwhite ) || [];
  
  			while ( ( elem = this[ i++ ] ) ) {
  				curValue = getClass( elem );
f986e111b   TRUONG   add libs
70
  				// This expression is here for better compressibility (see addClass)
87c93a029   Dang YoungWorld   add modal
71
  				cur = elem.nodeType === 1 && ( " " + stripAndCollapse( curValue ) + " " );
f986e111b   TRUONG   add libs
72
73
74
  
  				if ( cur ) {
  					j = 0;
87c93a029   Dang YoungWorld   add modal
75
  					while ( ( clazz = classes[ j++ ] ) ) {
f986e111b   TRUONG   add libs
76
  						// Remove *all* instances
87c93a029   Dang YoungWorld   add modal
77
  						while ( cur.indexOf( " " + clazz + " " ) > -1 ) {
f986e111b   TRUONG   add libs
78
79
80
  							cur = cur.replace( " " + clazz + " ", " " );
  						}
  					}
87c93a029   Dang YoungWorld   add modal
81
82
83
84
  					// Only assign if different to avoid unneeded rendering.
  					finalValue = stripAndCollapse( cur );
  					if ( curValue !== finalValue ) {
  						elem.setAttribute( "class", finalValue );
f986e111b   TRUONG   add libs
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
  					}
  				}
  			}
  		}
  
  		return this;
  	},
  
  	toggleClass: function( value, stateVal ) {
  		var type = typeof value;
  
  		if ( typeof stateVal === "boolean" && type === "string" ) {
  			return stateVal ? this.addClass( value ) : this.removeClass( value );
  		}
  
  		if ( jQuery.isFunction( value ) ) {
87c93a029   Dang YoungWorld   add modal
101
102
103
104
105
106
  			return this.each( function( i ) {
  				jQuery( this ).toggleClass(
  					value.call( this, i, getClass( this ), stateVal ),
  					stateVal
  				);
  			} );
f986e111b   TRUONG   add libs
107
  		}
87c93a029   Dang YoungWorld   add modal
108
109
  		return this.each( function() {
  			var className, i, self, classNames;
f986e111b   TRUONG   add libs
110
  			if ( type === "string" ) {
87c93a029   Dang YoungWorld   add modal
111
112
113
114
115
116
117
118
119
  
  				// Toggle individual class names
  				i = 0;
  				self = jQuery( this );
  				classNames = value.match( rnothtmlwhite ) || [];
  
  				while ( ( className = classNames[ i++ ] ) ) {
  
  					// Check each className given, space separated list
f986e111b   TRUONG   add libs
120
121
122
123
124
125
126
127
  					if ( self.hasClass( className ) ) {
  						self.removeClass( className );
  					} else {
  						self.addClass( className );
  					}
  				}
  
  			// Toggle whole class name
87c93a029   Dang YoungWorld   add modal
128
129
130
131
132
133
  			} else if ( value === undefined || type === "boolean" ) {
  				className = getClass( this );
  				if ( className ) {
  
  					// Store className if set
  					dataPriv.set( this, "__className__", className );
f986e111b   TRUONG   add libs
134
  				}
87c93a029   Dang YoungWorld   add modal
135
  				// If the element has a class name or if we're passed `false`,
f986e111b   TRUONG   add libs
136
137
138
  				// 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.
87c93a029   Dang YoungWorld   add modal
139
140
141
142
143
144
145
  				if ( this.setAttribute ) {
  					this.setAttribute( "class",
  						className || value === false ?
  						"" :
  						dataPriv.get( this, "__className__" ) || ""
  					);
  				}
f986e111b   TRUONG   add libs
146
  			}
87c93a029   Dang YoungWorld   add modal
147
  		} );
f986e111b   TRUONG   add libs
148
149
150
  	},
  
  	hasClass: function( selector ) {
87c93a029   Dang YoungWorld   add modal
151
152
153
154
155
156
157
158
  		var className, elem,
  			i = 0;
  
  		className = " " + selector + " ";
  		while ( ( elem = this[ i++ ] ) ) {
  			if ( elem.nodeType === 1 &&
  				( " " + stripAndCollapse( getClass( elem ) ) + " " ).indexOf( className ) > -1 ) {
  					return true;
f986e111b   TRUONG   add libs
159
160
161
162
163
  			}
  		}
  
  		return false;
  	}
87c93a029   Dang YoungWorld   add modal
164
  } );
f986e111b   TRUONG   add libs
165

87c93a029   Dang YoungWorld   add modal
166
  } );