Permalink
Browse files

- minor cleanups, the options argument can now also accept either a …

…function (in which case callback: options) or a string (in which case duration: options)
  • Loading branch information...
1 parent ee101f9 commit 7e22098ca77dbd650cecbc75050f727ff4bdc298 @kamicane committed Feb 20, 2012
Showing with 50 additions and 55 deletions.
  1. +7 −7 moofx-min.js
  2. +23 −25 moofx.js
  3. +1 −1 package.json
  4. +11 −10 src/animation.coffee
  5. +8 −12 src/color.coffee
View
14 moofx-min.js
@@ -12,12 +12,12 @@ license: MIT
fa.prototype;"undefined"!==typeof module?module.exports=k:this.moofx=k;B=[];V=!1;qa=function(a){var b;null==a&&(a=+new Date);V=!1;for(b=B.length;b;)B.splice(--b,1)[0](a);return null};ra=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(a){return setTimeout(a,1E3/60)};k.requestFrame=function(a){B.push(a);V||(V=!0,ra(qa));return this};k.cancelFrame=function(a){var b,c,d;for(c=0,d=
B.length;c<d;c++)b=B[c],b===a&&B.splice(c,1);return this};oa={maroon:"#800000",red:"#ff0000",orange:"#ffA500",yellow:"#ffff00",olive:"#808000",purple:"#800080",fuchsia:"#ff00ff",white:"#ffffff",lime:"#00ff00",green:"#008000",navy:"#000080",blue:"#0000ff",aqua:"#00ffff",teal:"#008080",black:"#000000",silver:"#c0c0c0",gray:"#808080"};la=function(a,b,c,d){null==d&&(d=1);return 255<a||0>a||255<b||0>b||255<c||0>c||255<d||0>d?null:[Math.round(a),Math.round(b),Math.round(c),parseFloat(d)]};ia=function(a){var b,
c,d;3===a.length&&(a+="f");4===a.length&&(b=a.charAt(0),c=a.charAt(1),d=a.charAt(2),a=a.charAt(3),a=b+b+c+c+d+d+a+a);6===a.length&&(a+="ff");d=[];for(b=0,c=a.length;b<=c;b+=2)d.push(parseInt(a.substr(b,2),16)/(6===b?255:1));return d};S=function(a,b,c){0>c&&(c+=1);1<c&&(c-=1);return c<1/6?a+6*(b-a)*c:0.5>c?b:c<2/3?a+6*(b-a)*(2/3-c):a};ja=function(a,b,c,d){var e,f;null==d&&(d=1);a/=360;b/=100;c/=100;if(1<a||0>a||1<b||0>b||1<c||0>c||1<d||0>d)return null;0===b?f=a=c:(b=0.5>c?c*(1+b):c+b-c*b,e=2*c-b,f=
-S(e,b,a+1/3),c=S(e,b,a),a=S(e,b,a-1/3));return[255*f,255*c,255*a,parseFloat(d)]};k.color=function(a,b){var c,a=oa[a=a.replace(/\s+/g,"")]||a;if(a.match(/^#[a-f0-9]{3,8}/))a=ia(a.replace("#",""));else if(c=a.match(/([\d.])+/g))if(a.match(/^rgb/))a=c;else if(a.match(/^hsl/))a=ja.apply(null,c);else return null;if(!a||!(a=la.apply(null,a)))return null;if(b)return a;1===a[3]&&a.splice(3,1);return"rgb"+(3<a.length?"a":"")+"("+a+")"};ba=k.cancelFrame;N=k.requestFrame;na=k.color;C=String;m=parseFloat;K=function(a){return a.replace(/-\D/g,
+S(e,b,a+1/3),c=S(e,b,a),a=S(e,b,a-1/3));return[255*f,255*c,255*a,parseFloat(d)]};k.color=function(a,b){var c,a=oa[a=a.replace(/\s+/g,"")]||a;if(a.match(/^#[a-f0-9]{3,8}/))a=ia(a.replace("#",""));else if(c=a.match(/([\d.])+/g))a.match(/^rgb/)?a=c:a.match(/^hsl/)&&(a=ja.apply(null,c));if(!a||!(a=la.apply(null,a)))return null;if(b)return a;1===a[3]&&a.splice(3,1);return"rgb"+(3<a.length?"a":"")+"("+a+")"};ba=k.cancelFrame;N=k.requestFrame;na=k.color;C=String;m=parseFloat;K=function(a){return a.replace(/-\D/g,
function(b){return b.charAt(1).toUpperCase()})};ca=function(a){return a.replace(/[A-Z]/g,function(b){return"-"+b.charAt(0).toLowerCase()})};T=function(a){return C(a).replace(/\s+/g," ").replace(/^\s+|\s+$/g,"")};L="undefined"!==typeof getComputedStyle?function(a){var b;b=getComputedStyle(a);return function(c){return b?b.getPropertyValue(ca(c)):""}}:function(a){var b;b=a.currentStyle;return function(c){return b?b[K(c)]:""}};h={};l={};G={};F=document.documentElement;aa={};A=function(a){return l[a]||
-(l[a]=function(){var b;b=h[a]||Y;return function(){return(new b(L(this)(a))).toString(this)}}())};W=function(a){return G[a]||(G[a]=function(){var b;b=h[a]||Y;return function(c){return this.style[a]=(new b(c)).toString()}}())};O=document.createElement("div");ea=function(a,b){var c,d;c=a.parentNode;d=1;c&&(O.style.cssText="border:none;margin:none;padding:none;visibility:hidden;position:absolute;height:0;"+("width:10"+b+";"),c.appendChild(O),d=O.offsetWidth/10,c.removeChild(O));return d};p=function(){function a(b){this.value=
+(l[a]=function(){var b;b=h[a]||Y;return function(){return(new b(L(this)(a))).toString(this)}}())};W=function(a){return G[a]||(G[a]=function(){var b;b=h[a]||Y;return function(c){return this.style[a]=(new b(c)).toString()}}())};O=document.createElement("div");ea=function(a,b){var c,d;c=a.parentNode;d=1;c&&(O.style.cssText="border:none;margin:none;padding:none;visibility:hidden;position:absolute;height:0;"+("width:100"+b+";"),c.appendChild(O),d=O.offsetWidth/100,c.removeChild(O));return d};p=function(){function a(b){this.value=
C(b)}a.prototype.extract=function(){return[this]};a.prototype.toString=function(){return C(this.value)};return a}();n=function(){function a(b){this.parsers=b}a.prototype.extract=function(){return this.parsers};a.prototype.toString=function(b){var c,a,e,f,g;f=this.parsers;g=[];for(a=0,e=f.length;a<e;a++)c=f[a],g.push(c.toString(b));return g.join(" ")};return a}();y=function(a){function b(c){this.value=m(c)}s(b,a);return b}(p);Y=function(a){function b(){b.__super__.constructor.apply(this,arguments)}
s(b,a);return b}(p);y=function(a){function b(c){this.value=m(c)}s(b,a);return b}(p);E=function(a){function b(c){"auto"===c?this.value="auto":(c=T(C(c)).match(/^([-\d.]+)(%|px|em|pt)?$/))?(this.value=m(c[1]),this.unit=0===this.value||!c[2]?"px":c[2]):(this.value=0,this.unit="px")}s(b,a);b.prototype.toString=function(c){return null==this.value?null:"auto"===this.value?this.value:c&&1===c.nodeType&&"px"!==this.unit?ea(c,this.unit)*this.value+"px":this.value+this.unit};return b}(p);H=function(a){function b(c){null==
-c&&(c="#000");"transparent"===c&&(c="#00000000");this.value=na(c,!0)||[0,0,0,1]}s(b,a);b.prototype.toString=function(c){return!c&&1===this.value[3]?"rgb("+this.value[0]+", "+this.value[1]+", "+this.value[2]+")":"rgba("+this.value+")"};return b}(p);da=function(a){var b;b=a.length;1===b?a.push(a[0],a[0],a[0]):2===b?a.push(a[0],a[1]):3===b&&a.push(a[1]);return a};Q=function(a){function b(c){var a=da,b,f,g,i;g=c.split(" ");i=[];for(b=0,f=g.length;b<f;b++)c=g[b],i.push(new E(c));this.parsers=a(i)}s(b,
+c&&(c="#000");"transparent"===c&&(c="#00000000");this.value=na(c,!0)||[0,0,0,1]}s(b,a);b.prototype.toString=function(c){return c||1!==this.value[3]?"rgba("+this.value+")":"rgb("+this.value[0]+", "+this.value[1]+", "+this.value[2]+")"};return b}(p);da=function(a){var b;b=a.length;1===b?a.push(a[0],a[0],a[0]):2===b?a.push(a[0],a[1]):3===b&&a.push(a[1]);return a};Q=function(a){function b(c){var a=da,b,f,g,i;g=c.split(" ");i=[];for(b=0,f=g.length;b<f;b++)c=g[b],i.push(new E(c));this.parsers=a(i)}s(b,
a);return b}(n);X=function(a){function b(c){this.value=c.match(/none|hidden|dotted|dashed|solid|double|groove|ridge|inset|outset|inherit/)?c:"none"}s(b,a);return b}(p);u=["Top","Right","Bottom","Left"];o=["TopLeft","TopRight","BottomRight","BottomLeft"];h.color=h.backgroundColor=H;h.width=h.height=h.fontSize=h.backgroundSize=E;x=function(a){function b(c){c=T(c).match(/((?:[\d.]+)(?:px|em|pt)?)\s(\w+)\s(rgb(?:a)?\([\d,\s]+\)|hsl(?:a)?\([\d,\s]+\)|#[a-f0-9]+|\w+)/)||[null,"0px"];this.parsers=[new E(c[1]),
new X(c[2]),new H(c[3])]}s(b,a);return b}(n);for(j=0,P=u.length;j<P;j++){r=u[j];q="border"+r;ga=["margin"+r,"padding"+r,q+"Width",r.toLowerCase()];for(v=0,sa=ga.length;v<sa;v++)w=ga[v],h[w]=E;h[q+"Color"]=H;h[q+"Style"]=X;h[q]=x;l[q]=function(){return[A(q+"Width").call(this),A(q+"Style").call(this),A(q+"Color").call(this)].join(" ")}}for(j=0,v=o.length;j<v;j++)r=o[j],h["border"+r+"Radius"]=E;h.zIndex=function(a){function b(c){this.value="auto"===c?c:m(c)}s(b,a);return b}(p);P=["margin","padding"];
o=function(a){h[a]=Q;return l[a]=function(){var b,c,d,e;e=[];for(d=0,c=u.length;d<c;d++)b=u[d],e.push(A(a+b).call(this));return e.join(" ")}};for(j=0,v=P.length;j<v;j++)w=P[j],o(w);h.borderRadius=Q;l.borderRadius=function(){var a,b,c,d;d=[];for(c=0,b=u.length;c<b;c++)a=u[c],d.push(A("border"+a+"Radius").call(this));return d.join(" ")};h.borderWidth=Q;h.borderColor=function(a){function b(c){var b,c=c.match(/rgb(a)?\([\d,\s]+\)|hsl(a)?\([\d,\s]+\)|#[a-f0-9]+|\w+/g)||["#000"],a=da,f,g,i;i=[];for(g=0,
@@ -34,7 +34,7 @@ function(a){return a}:$[d]||($[d]=ma(a[0],a[1],a[2],a[3],2*this.duration,1E3/60/
a,d);this.hproperty=ca(aa[this.property]||this.property);this.bdefer=function(a){return e.defer(a)};this.bcomplete=function(a){return e.complete(a)}}s(b,a);b.prototype.start=function(a,d){b.__super__.start.call(this,a,d)&&(this.to=d,N(this.bdefer));return this};b.prototype.stop=function(a){this.running?(this.running=!1,a&&this.setter.call(this.node,this.getter.call(this.node)),this.clean()):ba(this.bdefer);return this};b.prototype.defer=function(){this.running=!0;this.modCSS(!0);this.node.addEventListener(Z,
this.bcomplete,!1);this.setter.call(this.node,this.to);return null};b.prototype.clean=function(){this.modCSS();this.node.removeEventListener(Z,this.bcomplete);return null};b.prototype.complete=function(a){a&&a.propertyName===this.hproperty&&(this.running=!1,this.clean(),this.callback());return null};b.prototype.removeProp=function(a,b,e,f){var g,i,h,j;for(g=0,j=b.length;g<j;g++)if(h=b[g],h===a){i=g;break}null!=i&&(b.splice(i,1),e.splice(i,1),f.splice(i,1));return null};b.prototype.modCSS=function(a){var b,
e;b=L(this.node);e=b(z+"Property").replace(/\s+/g,"").split(",");r=b(z+"Duration").replace(/\s+/g,"").split(",");b=b(z+"TimingFunction").replace(/\s+/g,"").match(/cubic-bezier\(([\d.,]+)\)/g);this.removeProp("all",e,r,b);this.removeProp(this.hproperty,e,r,b);a&&(e.push(this.hproperty),r.push(this.duration),b.push(this.equation));this.node.style[z+"Property"]=e;this.node.style[z+"Duration"]=r;this.node.style[z+"TimingFunction"]=b;return null};b.prototype.parseDuration=function(a){return""+b.__super__.parseDuration.call(this,
-a)+"ms"};b.prototype.parseEquation=function(a){return"cubic-bezier("+b.__super__.parseEquation.call(this,a)+")"};return b}(p);J=new (function(){function a(){this.uid=0;this.animations={}}a.prototype.retrieve=function(a,c){var d,e,f;d=null!=(f=a.\u00b5id)?f:a.\u00b5id=(this.uid++).toString(36);d=(e=this.animations)[d]||(e[d]={});return d[c]||(d[c]=z?new ha(a,c):new ka(a,c))};a.prototype.starts=function(a,c,d){var e,f,g,i,j,k,t,n,m,o,s,p,r,l,u,v,q,w,x,z,y;null==d&&(d={});e=d.callback||function(){};
-m=f=0;d.callback=function(){if(++f===m)return e()};for(l in c){w=c[l];l=K(l);r=h[l];if(!r)throw Error("no parser for "+l);u=W(l);k=A(l);for(y=0,x=a.length;y<x;y++){o=a[y];m++;n=this.retrieve(o,l);s=new r(k.call(o));p=new r(w);j=s.extract();v=p.extract();for(t=0,z=j.length;t<z;t++){i=j[t];q=v[t];if("auto"===q.value||"auto"===i.value)throw Error("cannot animate "+l+" from or to `auto`");q.unit&&i.unit&&(g=!0,"px"!==q.unit&&(i.value/=ea(o,q.unit),i.unit=q.unit))}i=s.toString(!0);p=p.toString(!0);g&&
-u.call(o,i);n.setOptions(d).start(i,p)}}return this};a.prototype.start=function(a,c,d,e){var f;f={};f[c]=d;return this.starts(a,f,e)};a.prototype.sets=function(a,c){var d,e,f,g,i,h,j,k;for(e in c){g=c[e];f=W(e=K(e));for(h=0,i=a.length;h<i;h++){d=a[h];if(null!=(j=this.animations[d.\u00b5id]))null!=(k=j[e])&&k.stop(!0);f.call(d,g)}}return this};a.prototype.set=function(a,c,d){var e;e={};e[c]=d;return this.sets(a,e)};return a}());k.prototype.animate=function(a,b,c){"string"!==typeof a?J.starts(this.valueOf(),
-a,b):J.start(this.valueOf(),a,b,c);return this};k.prototype.style=function(a,b){"string"!==typeof a?J.sets(this.valueOf(),a):J.set(this.valueOf(),a,b);return this};k.prototype.compute=function(a){return A(K(a)).call(this.valueOf()[0])}}();
+a)+"ms"};b.prototype.parseEquation=function(a){return"cubic-bezier("+b.__super__.parseEquation.call(this,a)+")"};return b}(p);J=new (function(){function a(){this.uid=0;this.animations={}}a.prototype.retrieve=function(a,c){var d,e,f;d=null!=(f=a.\u00b5id)?f:a.\u00b5id=(this.uid++).toString(36);d=(e=this.animations)[d]||(e[d]={});return d[c]||(d[c]=z?new ha(a,c):new ka(a,c))};a.prototype.starts=function(a,c,d){var e,f,g,i,j,k,t,n,m,o,s,p,r,l,u,v,q,w,x,z,y;null==d&&(d={});k=typeof d;d="function"===k?
+{callback:d}:"string"===k?{duration:d}:d;e=d.callback||function(){};m=f=0;d.callback=function(){if(++f===m)return e()};for(l in c){w=c[l];l=K(l);r=h[l];if(!r)throw Error("no parser for "+l);u=W(l);k=A(l);for(y=0,x=a.length;y<x;y++){o=a[y];m++;n=this.retrieve(o,l);s=new r(k.call(o));p=new r(w);j=s.extract();v=p.extract();for(t=0,z=j.length;t<z;t++){i=j[t];q=v[t];if("auto"===q.value||"auto"===i.value)throw Error("cannot animate "+l+" from or to `auto`");q.unit&&i.unit&&(g=!0,"px"!==q.unit&&(i.value/=
+ea(o,q.unit),i.unit=q.unit))}i=s.toString(!0);p=p.toString(!0);g&&u.call(o,i);n.setOptions(d).start(i,p)}}return this};a.prototype.start=function(a,c,d,e){var f;f={};f[c]=d;return this.starts(a,f,e)};a.prototype.sets=function(a,c){var d,e,f,g,i,h,j,k;for(e in c){g=c[e];f=W(e=K(e));for(h=0,i=a.length;h<i;h++){d=a[h];if(null!=(j=this.animations[d.\u00b5id]))null!=(k=j[e])&&k.stop(!0);f.call(d,g)}}return this};a.prototype.set=function(a,c,d){var e;e={};e[c]=d;return this.sets(a,e)};return a}());k.prototype.animate=
+function(a,b,c){"string"!==typeof a?J.starts(this.valueOf(),a,b):J.start(this.valueOf(),a,b,c);return this};k.prototype.style=function(a,b){"string"!==typeof a?J.sets(this.valueOf(),a):J.set(this.valueOf(),a,b);return this};k.prototype.compute=function(a){return A(K(a)).call(this.valueOf()[0])}}();
View
48 moofx.js
@@ -152,26 +152,21 @@ HSLtoRGB = function(h, s, l, a){
};
moofx.color = function(input, array){
- var a, match;
+ var match;
input = colors[input = input.replace(/\s+/g, '')] || input;
if (input.match(/^#[a-f0-9]{3,8}/)){
input = HEXtoRGB(input.replace('#', ''));
- } else {
- if (match = input.match(/([\d.])+/g)){
- if (input.match(/^rgb/)){
- input = match;
- } else if (input.match(/^hsl/)){
- input = HSLtoRGB.apply(null, match);
- } else {
- return null;
- }
+ } else if (match = input.match(/([\d.])+/g)){
+ if (input.match(/^rgb/)){
+ input = match;
+ } else if (input.match(/^hsl/)){
+ input = HSLtoRGB.apply(null, match);
}
}
- if (!input || !(input = RGBtoRGB.apply(null, input))) return null;
+ if (!(input && (input = RGBtoRGB.apply(null, input)))) return null;
if (array) return input;
if (input[3] === 1) input.splice(3, 1);
- a = input.length > 3 ? 'a' : '';
- return "rgb" + a + "(" + input + ")";
+ return "rgb" + (input.length > 3 ? 'a' : '') + "(" + input + ")";
};
cancelFrame = moofx.cancelFrame, requestFrame = moofx.requestFrame, color = moofx.color;
@@ -257,9 +252,9 @@ pixelRatio = function(element, u){
parent = element.parentNode;
ratio = 1;
if (parent){
- test.style.cssText = cssText + ("width:10" + u + ";");
+ test.style.cssText = cssText + ("width:100" + u + ";");
parent.appendChild(test);
- ratio = test.offsetWidth / 10;
+ ratio = test.offsetWidth / 100;
parent.removeChild(test);
}
return ratio;
@@ -391,10 +386,10 @@ CSSColorParser = (function(_super){
}
CSSColorParser.prototype.toString = function(forceAlpha){
- if (!forceAlpha && this.value[3] === 1){
- return "rgb(" + this.value[0] + ", " + this.value[1] + ", " + this.value[2] + ")";
- } else {
+ if (forceAlpha || this.value[3] !== 1){
return "rgba(" + this.value + ")";
+ } else {
+ return "rgb(" + this.value[0] + ", " + this.value[1] + ", " + this.value[2] + ")";
}
};
@@ -804,11 +799,8 @@ Animation = (function(){
if (match = string(duration).match(/([\d.]+)(s|ms)/)){
time = number(match[1]);
unit = match[2];
- if (unit === 's'){
- return time * 1000;
- } else if (unit === 'ms'){
- return time;
- }
+ if (unit === 's') return time * 1000;
+ if (unit === 'ms') return time;
} else {
return null;
}
@@ -870,7 +862,7 @@ JSAnimation = (function(_super){
JSAnimation.prototype.step = function(now){
var f, i, tpl, ƒ, δ, _len7, _ref5;
- if (!this.time) this.time = now;
+ this.time || (this.time = now);
ƒ = (now - this.time) / this.duration;
if> 1) ƒ = 1;
δ = this.equation(ƒ);
@@ -1052,8 +1044,14 @@ Animations = (function(){
};
Animations.prototype.starts = function(nodes, styles, options){
- var callback, completed, enforce, fp, fromParsers, fs, get, i, instance, length, node, parsedFrom, parsedTo, parser, property, set, toParsers, tp, ts, value, _len8, _len9, _p;
+ var callback, completed, enforce, fp, fromParsers, fs, get, i, instance, length, node, parsedFrom, parsedTo, parser, property, set, toParsers, tp, ts, type, value, _len8, _len9, _p;
if (options == null) options = {};
+ type = typeof options;
+ options = type === 'function' ? {
+ callback: options
+ } : type === 'string' ? {
+ duration: options
+ } : options;
callback = options.callback || function(){};
completed = 0;
length = 0;
View
2 package.json
@@ -1,7 +1,7 @@
{
"name": "moofx",
"description": "A CSS3-enabled javascript animation library on caffeine",
- "version": "3.0.0-9-y",
+ "version": "3.0.0-10-y",
"keywords": ["moofx", "fx", "animation", "transition", "effects", "ender"],
"homepage": "http://moofx.it",
"author": "Valerio Proietti <@kamicane> (http://mad4milk.net)",
View
21 src/animation.coffee
@@ -110,9 +110,8 @@ class CSSColorParser extends CSSParser
value = '#00000000' if value is 'transparent'
@value = color(value, yes) or [0, 0, 0, 1]
toString: (forceAlpha) ->
- if not forceAlpha and @value[3] is 1 then "rgb(#{@value[0]}, #{@value[1]}, #{@value[2]})"
- else "rgba(#{@value})"
-
+ if forceAlpha or @value[3] isnt 1 then "rgba(#{@value})"
+ else "rgb(#{@value[0]}, #{@value[1]}, #{@value[2]})"
mirror4 = (values) ->
length = values.length
@@ -240,7 +239,7 @@ parsers.transform = class CSSTransformParser extends CSSParser
transforms = translate: '0px,0px', rotate: '0deg', scale: '1,1', skew: '0deg,0deg'
if value = clean(value).match(/\w+\s?\([-,.\w\s]+\)/g)
for v in value then do (v) ->
- return if not v = v.replace(/\s+/g, '').match(/^(translate|scale|rotate|skew)\((.*)\)$/)
+ return unless v = v.replace(/\s+/g, '').match(/^(translate|scale|rotate|skew)\((.*)\)$/)
name = v[1]
values = v[2].split(',')
switch name
@@ -348,17 +347,17 @@ class Animation
return pass
setOptions: (options = {}) ->
- if not @duration = @parseDuration(options.duration ? '500ms') then throw new Error "#{options.duration} is not a valid duration"
- if not @equation = @parseEquation(options.equation or 'default') then throw new Error "#{options.equation} is not a valid equation"
+ throw new Error "#{options.duration} is not a valid duration" unless @duration = @parseDuration(options.duration ? '500ms')
+ throw new Error "#{options.equation} is not a valid equation" unless @equation = @parseEquation(options.equation or 'default')
@callback = options.callback or () ->
@
parseDuration: (duration) ->
if match = string(duration).match(/([\d.]+)(s|ms)/)
time = number(match[1])
unit = match[2]
- if unit is 's' then return time * 1000
- else if unit is 'ms' then return time
+ return time * 1000 if unit is 's'
+ return time if unit is 'ms'
else return null
parseEquation: (equation) ->
@@ -393,7 +392,7 @@ class JSAnimation extends Animation
@
step: (now) ->
- if not @time then @time = now
+ @time or= now
ƒ = (now - @time) / @duration
if ƒ > 1 then ƒ = 1
δ = @equation(ƒ)
@@ -526,6 +525,8 @@ class Animations
animation[property] or= if CSSTransition then new CSSAnimation(node, property) else new JSAnimation(node, property)
starts: (nodes, styles, options = {}) ->
+ type = typeof options
+ options = if type is 'function' then callback: options else if type is 'string' then duration: options else options
callback = options.callback or () ->
completed = 0
length = 0
@@ -534,7 +535,7 @@ class Animations
for property, value of styles
property = camelize(property)
parser = parsers[property]
- if not parser then throw new Error "no parser for #{property}"
+ throw new Error "no parser for #{property}" unless parser
set = setter(property)
get = getter(property)
View
20 src/color.coffee
@@ -53,15 +53,11 @@ HSLtoRGB = (h, s, l, a = 1) ->
moofx.color = (input, array) ->
input = colors[input = input.replace(/\s+/g, '')] or input
if input.match(/^#[a-f0-9]{3,8}/) then input = HEXtoRGB(input.replace('#', ''))
-
- else
- if match = input.match(/([\d.])+/g)
- if input.match(/^rgb/) then input = match
- else if input.match(/^hsl/) then input = HSLtoRGB(match...)
- else return null
-
- if not input or not input = RGBtoRGB(input...) then return null
- if array then return input
- if input[3] is 1 then input.splice(3, 1)
- a = if input.length > 3 then 'a' else ''
- "rgb#{a}(#{input})"
+ else if match = input.match(/([\d.])+/g)
+ if input.match(/^rgb/) then input = match
+ else if input.match(/^hsl/) then input = HSLtoRGB(match...)
+
+ return null unless input and input = RGBtoRGB(input...)
+ return input if array
+ input.splice(3, 1) if input[3] is 1
+ "rgb#{if input.length > 3 then 'a' else ''}(#{input})"

0 comments on commit 7e22098

Please sign in to comment.