Skip to content

Commit

Permalink
Support data-transition-duration attributes for step elements.
Browse files Browse the repository at this point in the history
If the next element has its own data-transition-duration attribute,
use that value instead of the global setting.

References:
impress#142
  • Loading branch information
henrikingo committed Oct 21, 2017
1 parent cd68e6d commit fe411e5
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 14 deletions.
44 changes: 37 additions & 7 deletions js/impress.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,28 @@

} )();

var validateOrder = function( order, fallback ) {
var validChars = "xyz";
var returnStr = "";
if ( typeof order === "string" ) {
for ( var i in order.split( "" ) ) {
if ( validChars.indexOf( order[ i ] >= 0 ) ) {
returnStr += order[ i ];

// Each of x,y,z can be used only once.
validChars = validChars.split( order[ i ] ).join( "" );
}
}
}
if ( returnStr ) {
return returnStr;
} else if ( fallback !== undefined ) {
return fallback;
} else {
return "xyz";
}
};

// `css` function applies the styles given in `props` object to the element
// given as `el`. It runs all property names through `pfx` function to make
// sure proper prefixed version of the property is used.
Expand All @@ -79,11 +101,17 @@
// By default the rotations are in X Y Z order that can be reverted by passing `true`
// as second parameter.
var rotate = function( r, revert ) {
var rX = " rotateX(" + r.x + "deg) ",
rY = " rotateY(" + r.y + "deg) ",
rZ = " rotateZ(" + r.z + "deg) ";
var order = r.order ? r.order : "xyz";
var css = "";
var axes = order.split( "" );
if ( revert ) {
axes = axes.reverse();
}

return revert ? rZ + rY + rX : rX + rY + rZ;
for ( var i = 0; i < axes.length; i++ ) {
css += " rotate" + axes[ i ].toUpperCase() + "(" + r[ axes[ i ] ] + "deg)";
}
return css;
};

// `scale` builds a scale transform string for given data.
Expand Down Expand Up @@ -255,7 +283,8 @@
rotate: {
x: lib.util.toNumber( data.rotateX ),
y: lib.util.toNumber( data.rotateY ),
z: lib.util.toNumber( data.rotateZ || data.rotate )
z: lib.util.toNumber( data.rotateZ || data.rotate ),
order: validateOrder( data.rotateOrder )
},
scale: lib.util.toNumber( data.scale, 1 ),
el: el
Expand Down Expand Up @@ -352,7 +381,7 @@
// Set a default initial state of the canvas
currentState = {
translate: { x: 0, y: 0, z: 0 },
rotate: { x: 0, y: 0, z: 0 },
rotate: { x: 0, y: 0, z: 0, order: "xyz" },
scale: 1
};

Expand Down Expand Up @@ -451,7 +480,8 @@
rotate: {
x: -step.rotate.x,
y: -step.rotate.y,
z: -step.rotate.z
z: -step.rotate.z,
order: step.rotate.order
},
translate: {
x: -step.translate.x,
Expand Down
44 changes: 37 additions & 7 deletions src/impress.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,28 @@

} )();

var validateOrder = function( order, fallback ) {
var validChars = "xyz";
var returnStr = "";
if ( typeof order === "string" ) {
for ( var i in order.split( "" ) ) {
if ( validChars.indexOf( order[ i ] >= 0 ) ) {
returnStr += order[ i ];

// Each of x,y,z can be used only once.
validChars = validChars.split( order[ i ] ).join( "" );
}
}
}
if ( returnStr ) {
return returnStr;
} else if ( fallback !== undefined ) {
return fallback;
} else {
return "xyz";
}
};

// `css` function applies the styles given in `props` object to the element
// given as `el`. It runs all property names through `pfx` function to make
// sure proper prefixed version of the property is used.
Expand All @@ -79,11 +101,17 @@
// By default the rotations are in X Y Z order that can be reverted by passing `true`
// as second parameter.
var rotate = function( r, revert ) {
var rX = " rotateX(" + r.x + "deg) ",
rY = " rotateY(" + r.y + "deg) ",
rZ = " rotateZ(" + r.z + "deg) ";
var order = r.order ? r.order : "xyz";
var css = "";
var axes = order.split( "" );
if ( revert ) {
axes = axes.reverse();
}

return revert ? rZ + rY + rX : rX + rY + rZ;
for ( var i = 0; i < axes.length; i++ ) {
css += " rotate" + axes[ i ].toUpperCase() + "(" + r[ axes[ i ] ] + "deg)";
}
return css;
};

// `scale` builds a scale transform string for given data.
Expand Down Expand Up @@ -255,7 +283,8 @@
rotate: {
x: lib.util.toNumber( data.rotateX ),
y: lib.util.toNumber( data.rotateY ),
z: lib.util.toNumber( data.rotateZ || data.rotate )
z: lib.util.toNumber( data.rotateZ || data.rotate ),
order: validateOrder( data.rotateOrder )
},
scale: lib.util.toNumber( data.scale, 1 ),
el: el
Expand Down Expand Up @@ -352,7 +381,7 @@
// Set a default initial state of the canvas
currentState = {
translate: { x: 0, y: 0, z: 0 },
rotate: { x: 0, y: 0, z: 0 },
rotate: { x: 0, y: 0, z: 0, order: "xyz" },
scale: 1
};

Expand Down Expand Up @@ -451,7 +480,8 @@
rotate: {
x: -step.rotate.x,
y: -step.rotate.y,
z: -step.rotate.z
z: -step.rotate.z,
order: step.rotate.order
},
translate: {
x: -step.translate.x,
Expand Down

0 comments on commit fe411e5

Please sign in to comment.