Skip to content

Commit 0b71983

Browse files
committed
add Item.enableTransition
tick version v1.1.5 add disable transition
1 parent 3f03c0a commit 0b71983

File tree

3 files changed

+51
-26
lines changed

3 files changed

+51
-26
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "outlayer",
3-
"version": "1.1.4",
3+
"version": "1.1.5",
44
"description": "the brains and guts of a layout library",
55
"main": [
66
"item.js",

item.js

Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ function isEmptyObj( obj ) {
3535
return true;
3636
}
3737

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+
3847
function outlayerItemDefinition( EventEmitter, getSize, getStyleProperty ) {
3948

4049
// -------------------------- CSS3 support -------------------------- //
@@ -271,29 +280,14 @@ Item.prototype._nonTransition = function( args ) {
271280
*/
272281
Item.prototype._transition = function( args ) {
273282
// 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 ) ) {
276284
this._nonTransition( args );
277285
return;
278286
}
279287

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-
294288
var _transition = this._transition;
295289
// keep track of onTransitionEnd callback by css property
296-
for ( prop in args.onTransitionEnd ) {
290+
for ( var prop in args.onTransitionEnd ) {
297291
_transition.onEnd[ prop ] = args.onTransitionEnd[ prop ];
298292
}
299293
// keep track of properties that are transitioning
@@ -313,15 +307,43 @@ Item.prototype._transition = function( args ) {
313307
// hack for JSHint to hush about unused var
314308
h = null;
315309
}
316-
// set transition styles, to enable transition
317-
this.css( transitionStyle );
310+
// enable transition
311+
this.enableTransition( args.to );
318312
// set styles that are transitioning
319-
this.css( style );
313+
this.css( args.to );
320314

321315
this.isTransitioning = true;
322316

323317
};
324318

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+
325347
Item.prototype.transition = Item.prototype[ transitionProperty ? '_transition' : '_nonTransition' ];
326348

327349
// ----- events ----- //
@@ -342,7 +364,6 @@ var dashedVendorProperties = {
342364
};
343365

344366
Item.prototype.ontransitionend = function( event ) {
345-
// console.log('transition end');
346367
// disregard bubbled events from children
347368
if ( event.target !== this.element ) {
348369
return;
@@ -356,9 +377,7 @@ Item.prototype.ontransitionend = function( event ) {
356377
// check if any properties are still transitioning
357378
if ( isEmptyObj( _transition.ingProperties ) ) {
358379
// all properties have completed transitioning
359-
this.removeTransitionStyles();
360-
this.element.removeEventListener( transitionEndEvent, this, false );
361-
this.isTransitioning = false;
380+
this.disableTransition();
362381
}
363382
// clean style
364383
if ( propertyName in _transition.clean ) {
@@ -376,6 +395,12 @@ Item.prototype.ontransitionend = function( event ) {
376395
this.emitEvent( 'transitionEnd', [ this ] );
377396
};
378397

398+
Item.prototype.disableTransition = function() {
399+
this.removeTransitionStyles();
400+
this.element.removeEventListener( transitionEndEvent, this, false );
401+
this.isTransitioning = false;
402+
};
403+
379404
/**
380405
* removes style property from element
381406
* @param {Object} style

outlayer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* Outlayer v1.1.4
2+
* Outlayer v1.1.5
33
* the brains and guts of a layout library
44
*/
55

0 commit comments

Comments
 (0)