@@ -146,7 +146,7 @@ var colors = {
146
146
/****************************** CLASS ANIMATIONS ******************************/
147
147
/******************************************************************************/
148
148
149
- var classAnimationActions = [ ' add' , ' remove' , ' toggle' ] ,
149
+ var classAnimationActions = [ " add" , " remove" , " toggle" ] ,
150
150
shorthandStyles = {
151
151
border : 1 ,
152
152
borderBottom : 1 ,
@@ -157,7 +157,18 @@ var classAnimationActions = [ 'add', 'remove', 'toggle' ],
157
157
borderWidth : 1 ,
158
158
margin : 1 ,
159
159
padding : 1
160
+ } ,
161
+ // prefix used for storing data on .data()
162
+ dataSpace = "ec.storage." ;
163
+
164
+ $ . each ( [ "borderLeftStyle" , "borderRightStyle" , "borderBottomStyle" , "borderTopStyle" ] , function ( _ , prop ) {
165
+ $ . fx . step [ prop ] = function ( fx ) {
166
+ if ( fx . end !== "none" && ! fx . setAttr || fx . pos === 1 && ! fx . setAttr ) {
167
+ jQuery . style ( fx . elem , prop , fx . end ) ;
168
+ fx . setAttr = true ;
169
+ }
160
170
} ;
171
+ } )
161
172
162
173
function getElementStyles ( ) {
163
174
var style = document . defaultView
@@ -173,105 +184,83 @@ function getElementStyles() {
173
184
len = style . length ;
174
185
while ( len -- ) {
175
186
key = style [ len ] ;
176
- if ( typeof style [ key ] == 'string' ) {
177
- camelCase = key . replace ( / \- ( \w ) / g, function ( all , letter ) {
178
- return letter . toUpperCase ( ) ;
179
- } ) ;
180
- newStyle [ camelCase ] = style [ key ] ;
187
+ if ( typeof style [ key ] === "string" ) {
188
+ newStyle [ $ . camelCase ( key ) ] = style [ key ] ;
181
189
}
182
190
}
183
191
} else {
184
192
for ( key in style ) {
185
- if ( typeof style [ key ] === ' string' ) {
193
+ if ( typeof style [ key ] === " string" ) {
186
194
newStyle [ key ] = style [ key ] ;
187
195
}
188
196
}
189
197
}
190
-
198
+
191
199
return newStyle ;
192
200
}
193
201
194
- function filterStyles ( styles ) {
195
- var name , value ;
196
- for ( name in styles ) {
197
- value = styles [ name ] ;
198
- if (
199
- // ignore null and undefined values
200
- value == null ||
201
- // ignore functions (when does this occur?)
202
- $ . isFunction ( value ) ||
203
- // shorthand styles that need to be expanded
204
- name in shorthandStyles ||
205
- // ignore scrollbars (break in IE)
206
- ( / s c r o l l b a r / ) . test ( name ) ||
207
-
208
- // only colors or values that can be converted to numbers
209
- ( ! ( / c o l o r / i ) . test ( name ) && isNaN ( parseFloat ( value ) ) )
210
- ) {
211
- delete styles [ name ] ;
212
- }
213
- }
214
-
215
- return styles ;
216
- }
217
202
218
203
function styleDifference ( oldStyle , newStyle ) {
219
- var diff = { _ : 0 } , // http://dev.jquery.com/ticket/5459
220
- name ;
204
+ var diff = { } ,
205
+ name , value ;
221
206
222
207
for ( name in newStyle ) {
223
- if ( oldStyle [ name ] != newStyle [ name ] ) {
224
- diff [ name ] = newStyle [ name ] ;
208
+ value = newStyle [ name ] ;
209
+ if ( oldStyle [ name ] != value ) {
210
+ if ( ! shorthandStyles [ name ] ) {
211
+ if ( $ . fx . step [ name ] || ! isNaN ( parseFloat ( value ) ) ) {
212
+ diff [ name ] = value ;
213
+ }
214
+ }
225
215
}
226
216
}
227
217
228
218
return diff ;
229
219
}
230
220
231
221
$ . effects . animateClass = function ( value , duration , easing , callback ) {
232
- if ( $ . isFunction ( easing ) ) {
233
- callback = easing ;
234
- easing = null ;
235
- }
236
-
237
- return this . queue ( function ( ) {
238
- var that = $ ( this ) ,
239
- originalStyleAttr = that . attr ( 'style' ) || ' ' ,
240
- originalStyle = filterStyles ( getElementStyles . call ( this ) ) ,
222
+ var o = $ . speed ( duration , easing , callback ) ;
223
+
224
+ return this . queue ( function ( ) {
225
+ var animated = $ ( this ) ,
226
+ baseClass = animated . attr ( "class" ) ,
227
+ finalClass ,
228
+ originalStyleAttr = animated . attr ( "style" ) || ' ' ,
229
+ originalStyle = getElementStyles . call ( this ) ,
241
230
newStyle ,
242
- className = that . attr ( 'class' ) ;
231
+ diff ,
232
+ prop ;
243
233
244
234
$ . each ( classAnimationActions , function ( i , action ) {
245
235
if ( value [ action ] ) {
246
- that [ action + ' Class' ] ( value [ action ] ) ;
236
+ animated [ action + " Class" ] ( value [ action ] ) ;
247
237
}
248
238
} ) ;
249
- newStyle = filterStyles ( getElementStyles . call ( this ) ) ;
250
- that . attr ( 'class' , className ) ;
251
-
252
- that . animate ( styleDifference ( originalStyle , newStyle ) , {
253
- queue : false ,
254
- duration : duration ,
255
- easing : easing ,
256
- complete : function ( ) {
257
- $ . each ( classAnimationActions , function ( i , action ) {
258
- if ( value [ action ] ) {
259
- that [ action + 'Class' ] ( value [ action ] ) ;
239
+ newStyle = getElementStyles . call ( this ) ;
240
+ finalClass = animated . attr ( "class" ) ;
241
+ animated . attr ( "class" , baseClass ) ;
242
+
243
+ diff = styleDifference ( originalStyle , newStyle ) ;
244
+ animated
245
+ . animate ( diff , {
246
+ duration : duration ,
247
+ easing : o . easing ,
248
+ queue : false ,
249
+ complete : function ( ) {
250
+ animated . attr ( "class" , finalClass ) ;
251
+
252
+ if ( typeof animated . attr ( 'style' ) == 'object' ) {
253
+ animated . attr ( 'style' ) . cssText = '' ;
254
+ animated . attr ( 'style' ) . cssText = originalStyleAttr ;
255
+ } else {
256
+ animated . attr ( 'style' , originalStyleAttr ) ;
260
257
}
261
- } ) ;
262
- // work around bug in IE by clearing the cssText before setting it
263
- if ( typeof that . attr ( 'style' ) == 'object' ) {
264
- that . attr ( 'style' ) . cssText = '' ;
265
- that . attr ( 'style' ) . cssText = originalStyleAttr ;
266
- } else {
267
- that . attr ( 'style' , originalStyleAttr ) ;
268
- }
269
- if ( callback ) {
270
- callback . apply ( this , arguments ) ;
258
+
259
+ // this is guarnteed to be there if you use jQuery.speed()
260
+ // it also handles dequeuing the next anim...
261
+ o . complete . call ( this ) ;
271
262
}
272
- $ . dequeue ( this ) ;
273
- }
274
- } ) ;
263
+ } ) ;
275
264
} ) ;
276
265
} ;
277
266
@@ -300,7 +289,7 @@ $.fn.extend({
300
289
return $ . effects . animateClass . apply ( this , [ ( force ? { add :classNames } : { remove :classNames } ) , speed , easing , callback ] ) ;
301
290
}
302
291
} else {
303
- // without switch parameter;
292
+ // without force parameter;
304
293
return $ . effects . animateClass . apply ( this , [ { toggle : classNames } , force , speed , easing ] ) ;
305
294
}
306
295
} ,
@@ -326,7 +315,7 @@ $.extend( $.effects, {
326
315
save : function ( element , set ) {
327
316
for ( var i = 0 ; i < set . length ; i ++ ) {
328
317
if ( set [ i ] !== null ) {
329
- element . data ( "ec.storage." + set [ i ] , element [ 0 ] . style [ set [ i ] ] ) ;
318
+ element . data ( dataSpace + set [ i ] , element [ 0 ] . style [ set [ i ] ] ) ;
330
319
}
331
320
}
332
321
} ,
@@ -335,7 +324,7 @@ $.extend( $.effects, {
335
324
restore : function ( element , set ) {
336
325
for ( var i = 0 ; i < set . length ; i ++ ) {
337
326
if ( set [ i ] !== null ) {
338
- element . css ( set [ i ] , element . data ( "ec.storage." + set [ i ] ) ) ;
327
+ element . css ( set [ i ] , element . data ( dataSpace + set [ i ] ) ) ;
339
328
}
340
329
}
341
330
} ,
0 commit comments