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