@@ -35,6 +35,15 @@ function isEmptyObj( obj ) {
35
35
return true ;
36
36
}
37
37
38
+ // http://jamesroberts.name/blog/2010/02/22/string-functions-for-javascript-trim-to-camel-case-to-dashed-and-to-underscore/
39
+ function toDash ( str ) {
40
+ return str . replace ( / ( [ A - Z ] ) / g, function ( $1 ) {
41
+ return '-' + $1 . toLowerCase ( ) ;
42
+ } ) ;
43
+ }
44
+
45
+ // -------------------------- Outlayer definition -------------------------- //
46
+
38
47
function outlayerItemDefinition ( EventEmitter , getSize , getStyleProperty ) {
39
48
40
49
// -------------------------- CSS3 support -------------------------- //
@@ -271,29 +280,14 @@ Item.prototype._nonTransition = function( args ) {
271
280
*/
272
281
Item . prototype . _transition = function ( args ) {
273
282
// redirect to nonTransition if no transition duration
274
- var transitionDuration = this . layout . options . transitionDuration ;
275
- if ( ! parseFloat ( transitionDuration ) ) {
283
+ if ( ! parseFloat ( this . layout . options . transitionDuration ) ) {
276
284
this . _nonTransition ( args ) ;
277
285
return ;
278
286
}
279
287
280
- var style = args . to ;
281
- // make transition: foo, bar, baz from style object
282
- var transitionValue = [ ] ;
283
- for ( var prop in style ) {
284
- transitionValue . push ( prop ) ;
285
- }
286
-
287
- // enable transition
288
- var transitionStyle = { } ;
289
- transitionStyle . transitionProperty = transitionValue . join ( ',' ) ;
290
- transitionStyle . transitionDuration = transitionDuration ;
291
-
292
- this . element . addEventListener ( transitionEndEvent , this , false ) ;
293
-
294
288
var _transition = this . _transition ;
295
289
// keep track of onTransitionEnd callback by css property
296
- for ( prop in args . onTransitionEnd ) {
290
+ for ( var prop in args . onTransitionEnd ) {
297
291
_transition . onEnd [ prop ] = args . onTransitionEnd [ prop ] ;
298
292
}
299
293
// keep track of properties that are transitioning
@@ -313,15 +307,43 @@ Item.prototype._transition = function( args ) {
313
307
// hack for JSHint to hush about unused var
314
308
h = null ;
315
309
}
316
- // set transition styles, to enable transition
317
- this . css ( transitionStyle ) ;
310
+ // enable transition
311
+ this . enableTransition ( args . to ) ;
318
312
// set styles that are transitioning
319
- this . css ( style ) ;
313
+ this . css ( args . to ) ;
320
314
321
315
this . isTransitioning = true ;
322
316
323
317
} ;
324
318
319
+ var itemTransitionProperties = transformProperty && ( toDash ( transformProperty ) +
320
+ ',opacity' ) ;
321
+
322
+ Item . prototype . enableTransition = function ( /* style */ ) {
323
+ // only enable if not already transitioning
324
+ // bug in IE10 were re-setting transition style will prevent
325
+ // transitionend event from triggering
326
+ if ( this . isTransitioning ) {
327
+ return ;
328
+ }
329
+
330
+ // make transition: foo, bar, baz from style object
331
+ // TODO uncomment this bit when IE10 bug is resolved
332
+ // var transitionValue = [];
333
+ // for ( var prop in style ) {
334
+ // // dash-ify camelCased properties like WebkitTransition
335
+ // transitionValue.push( toDash( prop ) );
336
+ // }
337
+ // enable transition styles
338
+ // HACK always enable transform,opacity for IE10
339
+ this . css ( {
340
+ transitionProperty : itemTransitionProperties ,
341
+ transitionDuration : this . layout . options . transitionDuration
342
+ } ) ;
343
+ // listen for transition end event
344
+ this . element . addEventListener ( transitionEndEvent , this , false ) ;
345
+ } ;
346
+
325
347
Item . prototype . transition = Item . prototype [ transitionProperty ? '_transition' : '_nonTransition' ] ;
326
348
327
349
// ----- events ----- //
@@ -342,7 +364,6 @@ var dashedVendorProperties = {
342
364
} ;
343
365
344
366
Item . prototype . ontransitionend = function ( event ) {
345
- // console.log('transition end');
346
367
// disregard bubbled events from children
347
368
if ( event . target !== this . element ) {
348
369
return ;
@@ -356,9 +377,7 @@ Item.prototype.ontransitionend = function( event ) {
356
377
// check if any properties are still transitioning
357
378
if ( isEmptyObj ( _transition . ingProperties ) ) {
358
379
// all properties have completed transitioning
359
- this . removeTransitionStyles ( ) ;
360
- this . element . removeEventListener ( transitionEndEvent , this , false ) ;
361
- this . isTransitioning = false ;
380
+ this . disableTransition ( ) ;
362
381
}
363
382
// clean style
364
383
if ( propertyName in _transition . clean ) {
@@ -376,6 +395,12 @@ Item.prototype.ontransitionend = function( event ) {
376
395
this . emitEvent ( 'transitionEnd' , [ this ] ) ;
377
396
} ;
378
397
398
+ Item . prototype . disableTransition = function ( ) {
399
+ this . removeTransitionStyles ( ) ;
400
+ this . element . removeEventListener ( transitionEndEvent , this , false ) ;
401
+ this . isTransitioning = false ;
402
+ } ;
403
+
379
404
/**
380
405
* removes style property from element
381
406
* @param {Object } style
0 commit comments