Created
November 13, 2012 12:59
-
-
Save m4dz/4065644 to your computer and use it in GitHub Desktop.
LessCSS transition compliant syntax
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// CSS TRANSITIONS ------------------------------------------------------------/ | |
// I pass 2 args to the method but the second one is only here to prevent | |
// LessCSS to this bloody trick that @arguments return an array if there's two | |
// args but a string when there's only one oO'… | |
.transition (@param, @fakeParam:X, ...) | |
{ | |
// Explode arguments and remove the fakeParam | |
@args : ~`"@{arguments}".replace(/[\[\]]|\sX/g, '')`; | |
// Specify prefixable properties seperated with commas | |
// i.e.: ~"transform,opacity" | |
@properties : ~"transform"; | |
// Due to fucking limitations in LessCSS, we need to parse the arguments | |
// directly from JS. | |
// The script used to performed this is following (@prefix is optionnal) : | |
// --------------------------------------------------------------------------- | |
// (function(a, p, f) { | |
// var args = a.split(','), | |
// toPrefix = p.split(','), | |
// params = [], | |
// | |
// t = function(arg) { | |
// var a = arg.split(' '); | |
// | |
// if ( a[0] === "none" ) { | |
// return "none"; | |
// } | |
// else if ( a.length > 1 ) { | |
// var p = ( ( f != null ) && ( toPrefix.indexOf( a[0] ) !== -1 ) )? '-' + f + '-' + a[0] : a[0], | |
// d = a[1], | |
// e = ( a[2] == null )? 'ease' : a[2], | |
// t = ( a[3] == null )? '0s' : a[3]; | |
// | |
// return p + ' ' + d + ' ' + e + ' ' + t; | |
// } | |
// }; | |
// | |
// for ( var _i = 0, _len = args.length; _i < _len; _i++ ) { | |
// if ( args[_i].length > 0 ) | |
// params.push( t( args[_i].trim() ) ); | |
// } | |
// | |
// return params.join(','); | |
// })("@{args}", "@{properties}", "@{prefix}"); | |
// | |
// --------------------------------------------------------------------------- | |
// The script is minified with Uglify to one line of code. | |
-webkit-transition : ~`(function(e,t,n){var r=e.split(","),i=t.split(","),s=[],o=function(e){var t=e.split(" ");if(t[0]==="none")return"none";if(t.length>1){var r=n!=null&&i.indexOf(t[0])!==-1?"-"+n+"-"+t[0]:t[0],s=t[1],o=t[2]==null?"ease":t[2],u=t[3]==null?"0s":t[3];return r+" "+s+" "+o+" "+u}};for(var u=0,a=r.length;u<a;u++)r[u].length>0&&s.push(o(r[u].trim()));return s.join(",")})("@{args}","@{properties}", "webkit")`; | |
-moz-transition : ~`(function(e,t,n){var r=e.split(","),i=t.split(","),s=[],o=function(e){var t=e.split(" ");if(t[0]==="none")return"none";if(t.length>1){var r=n!=null&&i.indexOf(t[0])!==-1?"-"+n+"-"+t[0]:t[0],s=t[1],o=t[2]==null?"ease":t[2],u=t[3]==null?"0s":t[3];return r+" "+s+" "+o+" "+u}};for(var u=0,a=r.length;u<a;u++)r[u].length>0&&s.push(o(r[u].trim()));return s.join(",")})("@{args}","@{properties}", "moz")`; | |
-ms-transition : ~`(function(e,t,n){var r=e.split(","),i=t.split(","),s=[],o=function(e){var t=e.split(" ");if(t[0]==="none")return"none";if(t.length>1){var r=n!=null&&i.indexOf(t[0])!==-1?"-"+n+"-"+t[0]:t[0],s=t[1],o=t[2]==null?"ease":t[2],u=t[3]==null?"0s":t[3];return r+" "+s+" "+o+" "+u}};for(var u=0,a=r.length;u<a;u++)r[u].length>0&&s.push(o(r[u].trim()));return s.join(",")})("@{args}","@{properties}", "ms")`; | |
-o-transition : ~`(function(e,t,n){var r=e.split(","),i=t.split(","),s=[],o=function(e){var t=e.split(" ");if(t[0]==="none")return"none";if(t.length>1){var r=n!=null&&i.indexOf(t[0])!==-1?"-"+n+"-"+t[0]:t[0],s=t[1],o=t[2]==null?"ease":t[2],u=t[3]==null?"0s":t[3];return r+" "+s+" "+o+" "+u}};for(var u=0,a=r.length;u<a;u++)r[u].length>0&&s.push(o(r[u].trim()));return s.join(",")})("@{args}","@{properties}", "o")`; | |
transition : ~`(function(e,t,n){var r=e.split(","),i=t.split(","),s=[],o=function(e){var t=e.split(" ");if(t[0]==="none")return"none";if(t.length>1){var r=n!=null&&i.indexOf(t[0])!==-1?"-"+n+"-"+t[0]:t[0],s=t[1],o=t[2]==null?"ease":t[2],u=t[3]==null?"0s":t[3];return r+" "+s+" "+o+" "+u}};for(var u=0,a=r.length;u<a;u++)r[u].length>0&&s.push(o(r[u].trim()));return s.join(",")})("@{args}","@{properties}")`; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment