Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

- 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...
commit 7e22098ca77dbd650cecbc75050f727ff4bdc298 1 parent ee101f9
Valerio Proietti authored
14 moofx-min.js
@@ -12,12 +12,12 @@ license: MIT
12 12 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=
13 13 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,
14 14 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=
15   -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,
  15 +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,
16 16 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]||
17   -(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=
  17 +(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=
18 18 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)}
19 19 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==
20   -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,
  20 +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,
21 21 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]),
22 22 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"];
23 23 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/
34 34 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,
35 35 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,
36 36 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,
37   -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(){};
38   -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&&
39   -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(),
40   -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])}}();
  37 +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?
  38 +{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/=
  39 +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=
  40 +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])}}();
48 moofx.js
@@ -152,26 +152,21 @@ HSLtoRGB = function(h, s, l, a){
152 152 };
153 153
154 154 moofx.color = function(input, array){
155   - var a, match;
  155 + var match;
156 156 input = colors[input = input.replace(/\s+/g, '')] || input;
157 157 if (input.match(/^#[a-f0-9]{3,8}/)){
158 158 input = HEXtoRGB(input.replace('#', ''));
159   - } else {
160   - if (match = input.match(/([\d.])+/g)){
161   - if (input.match(/^rgb/)){
162   - input = match;
163   - } else if (input.match(/^hsl/)){
164   - input = HSLtoRGB.apply(null, match);
165   - } else {
166   - return null;
167   - }
  159 + } else if (match = input.match(/([\d.])+/g)){
  160 + if (input.match(/^rgb/)){
  161 + input = match;
  162 + } else if (input.match(/^hsl/)){
  163 + input = HSLtoRGB.apply(null, match);
168 164 }
169 165 }
170   - if (!input || !(input = RGBtoRGB.apply(null, input))) return null;
  166 + if (!(input && (input = RGBtoRGB.apply(null, input)))) return null;
171 167 if (array) return input;
172 168 if (input[3] === 1) input.splice(3, 1);
173   - a = input.length > 3 ? 'a' : '';
174   - return "rgb" + a + "(" + input + ")";
  169 + return "rgb" + (input.length > 3 ? 'a' : '') + "(" + input + ")";
175 170 };
176 171
177 172 cancelFrame = moofx.cancelFrame, requestFrame = moofx.requestFrame, color = moofx.color;
@@ -257,9 +252,9 @@ pixelRatio = function(element, u){
257 252 parent = element.parentNode;
258 253 ratio = 1;
259 254 if (parent){
260   - test.style.cssText = cssText + ("width:10" + u + ";");
  255 + test.style.cssText = cssText + ("width:100" + u + ";");
261 256 parent.appendChild(test);
262   - ratio = test.offsetWidth / 10;
  257 + ratio = test.offsetWidth / 100;
263 258 parent.removeChild(test);
264 259 }
265 260 return ratio;
@@ -391,10 +386,10 @@ CSSColorParser = (function(_super){
391 386 }
392 387
393 388 CSSColorParser.prototype.toString = function(forceAlpha){
394   - if (!forceAlpha && this.value[3] === 1){
395   - return "rgb(" + this.value[0] + ", " + this.value[1] + ", " + this.value[2] + ")";
396   - } else {
  389 + if (forceAlpha || this.value[3] !== 1){
397 390 return "rgba(" + this.value + ")";
  391 + } else {
  392 + return "rgb(" + this.value[0] + ", " + this.value[1] + ", " + this.value[2] + ")";
398 393 }
399 394 };
400 395
@@ -804,11 +799,8 @@ Animation = (function(){
804 799 if (match = string(duration).match(/([\d.]+)(s|ms)/)){
805 800 time = number(match[1]);
806 801 unit = match[2];
807   - if (unit === 's'){
808   - return time * 1000;
809   - } else if (unit === 'ms'){
810   - return time;
811   - }
  802 + if (unit === 's') return time * 1000;
  803 + if (unit === 'ms') return time;
812 804 } else {
813 805 return null;
814 806 }
@@ -870,7 +862,7 @@ JSAnimation = (function(_super){
870 862
871 863 JSAnimation.prototype.step = function(now){
872 864 var f, i, tpl, ƒ, δ, _len7, _ref5;
873   - if (!this.time) this.time = now;
  865 + this.time || (this.time = now);
874 866 ƒ = (now - this.time) / this.duration;
875 867 if (ƒ > 1) ƒ = 1;
876 868 δ = this.equation(ƒ);
@@ -1052,8 +1044,14 @@ Animations = (function(){
1052 1044 };
1053 1045
1054 1046 Animations.prototype.starts = function(nodes, styles, options){
1055   - var callback, completed, enforce, fp, fromParsers, fs, get, i, instance, length, node, parsedFrom, parsedTo, parser, property, set, toParsers, tp, ts, value, _len8, _len9, _p;
  1047 + 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;
1056 1048 if (options == null) options = {};
  1049 + type = typeof options;
  1050 + options = type === 'function' ? {
  1051 + callback: options
  1052 + } : type === 'string' ? {
  1053 + duration: options
  1054 + } : options;
1057 1055 callback = options.callback || function(){};
1058 1056 completed = 0;
1059 1057 length = 0;
2  package.json
... ... @@ -1,7 +1,7 @@
1 1 {
2 2 "name": "moofx",
3 3 "description": "A CSS3-enabled javascript animation library on caffeine",
4   - "version": "3.0.0-9-y",
  4 + "version": "3.0.0-10-y",
5 5 "keywords": ["moofx", "fx", "animation", "transition", "effects", "ender"],
6 6 "homepage": "http://moofx.it",
7 7 "author": "Valerio Proietti <@kamicane> (http://mad4milk.net)",
21 src/animation.coffee
@@ -110,9 +110,8 @@ class CSSColorParser extends CSSParser
110 110 value = '#00000000' if value is 'transparent'
111 111 @value = color(value, yes) or [0, 0, 0, 1]
112 112 toString: (forceAlpha) ->
113   - if not forceAlpha and @value[3] is 1 then "rgb(#{@value[0]}, #{@value[1]}, #{@value[2]})"
114   - else "rgba(#{@value})"
115   -
  113 + if forceAlpha or @value[3] isnt 1 then "rgba(#{@value})"
  114 + else "rgb(#{@value[0]}, #{@value[1]}, #{@value[2]})"
116 115
117 116 mirror4 = (values) ->
118 117 length = values.length
@@ -240,7 +239,7 @@ parsers.transform = class CSSTransformParser extends CSSParser
240 239 transforms = translate: '0px,0px', rotate: '0deg', scale: '1,1', skew: '0deg,0deg'
241 240 if value = clean(value).match(/\w+\s?\([-,.\w\s]+\)/g)
242 241 for v in value then do (v) ->
243   - return if not v = v.replace(/\s+/g, '').match(/^(translate|scale|rotate|skew)\((.*)\)$/)
  242 + return unless v = v.replace(/\s+/g, '').match(/^(translate|scale|rotate|skew)\((.*)\)$/)
244 243 name = v[1]
245 244 values = v[2].split(',')
246 245 switch name
@@ -348,8 +347,8 @@ class Animation
348 347 return pass
349 348
350 349 setOptions: (options = {}) ->
351   - if not @duration = @parseDuration(options.duration ? '500ms') then throw new Error "#{options.duration} is not a valid duration"
352   - if not @equation = @parseEquation(options.equation or 'default') then throw new Error "#{options.equation} is not a valid equation"
  350 + throw new Error "#{options.duration} is not a valid duration" unless @duration = @parseDuration(options.duration ? '500ms')
  351 + throw new Error "#{options.equation} is not a valid equation" unless @equation = @parseEquation(options.equation or 'default')
353 352 @callback = options.callback or () ->
354 353 @
355 354
@@ -357,8 +356,8 @@ class Animation
357 356 if match = string(duration).match(/([\d.]+)(s|ms)/)
358 357 time = number(match[1])
359 358 unit = match[2]
360   - if unit is 's' then return time * 1000
361   - else if unit is 'ms' then return time
  359 + return time * 1000 if unit is 's'
  360 + return time if unit is 'ms'
362 361 else return null
363 362
364 363 parseEquation: (equation) ->
@@ -393,7 +392,7 @@ class JSAnimation extends Animation
393 392 @
394 393
395 394 step: (now) ->
396   - if not @time then @time = now
  395 + @time or= now
397 396 ƒ = (now - @time) / @duration
398 397 if ƒ > 1 then ƒ = 1
399 398 δ = @equation(ƒ)
@@ -526,6 +525,8 @@ class Animations
526 525 animation[property] or= if CSSTransition then new CSSAnimation(node, property) else new JSAnimation(node, property)
527 526
528 527 starts: (nodes, styles, options = {}) ->
  528 + type = typeof options
  529 + options = if type is 'function' then callback: options else if type is 'string' then duration: options else options
529 530 callback = options.callback or () ->
530 531 completed = 0
531 532 length = 0
@@ -534,7 +535,7 @@ class Animations
534 535 for property, value of styles
535 536 property = camelize(property)
536 537 parser = parsers[property]
537   - if not parser then throw new Error "no parser for #{property}"
  538 + throw new Error "no parser for #{property}" unless parser
538 539
539 540 set = setter(property)
540 541 get = getter(property)
20 src/color.coffee
@@ -53,15 +53,11 @@ HSLtoRGB = (h, s, l, a = 1) ->
53 53 moofx.color = (input, array) ->
54 54 input = colors[input = input.replace(/\s+/g, '')] or input
55 55 if input.match(/^#[a-f0-9]{3,8}/) then input = HEXtoRGB(input.replace('#', ''))
56   -
57   - else
58   - if match = input.match(/([\d.])+/g)
59   - if input.match(/^rgb/) then input = match
60   - else if input.match(/^hsl/) then input = HSLtoRGB(match...)
61   - else return null
62   -
63   - if not input or not input = RGBtoRGB(input...) then return null
64   - if array then return input
65   - if input[3] is 1 then input.splice(3, 1)
66   - a = if input.length > 3 then 'a' else ''
67   - "rgb#{a}(#{input})"
  56 + else if match = input.match(/([\d.])+/g)
  57 + if input.match(/^rgb/) then input = match
  58 + else if input.match(/^hsl/) then input = HSLtoRGB(match...)
  59 +
  60 + return null unless input and input = RGBtoRGB(input...)
  61 + return input if array
  62 + input.splice(3, 1) if input[3] is 1
  63 + "rgb#{if input.length > 3 then 'a' else ''}(#{input})"

0 comments on commit 7e22098

Please sign in to comment.
Something went wrong with that request. Please try again.