scratch – Blame information for rev 125

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