From 7cb910412b9e3c5fb709cb42808d88bcab7b4857 Mon Sep 17 00:00:00 2001 From: Ryan W Tenney Date: Mon, 9 Aug 2010 13:03:34 -0700 Subject: [PATCH] Added substr function back in, IE apparently doesn't like it when you use a strings like an array of chars. Other minor improvements, updated minified version, now at 1692 bytes. Minor edit of readme file. --- README.md | 2 +- emile.js | 20 +++++++++++--------- emile.min.js | 2 +- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index ceb23d8..fec9f1e 100644 --- a/README.md +++ b/README.md @@ -37,4 +37,4 @@ One method: ### License ### Émile is is licensed under the terms of the MIT License, see the included MIT-LICENSE file. -Émile borrows its name from . +Émile borrows its name from [Émile Cohl](http://en.wikipedia.org/wiki/Émile_Cohl). \ No newline at end of file diff --git a/emile.js b/emile.js index 58db356..ee1e3f4 100644 --- a/emile.js +++ b/emile.js @@ -3,7 +3,7 @@ // emile.js (c) 2009 Thomas Fuchs // Licensed under the terms of the MIT license. -(function(emile, container){ +(function (emile, container) { var parseEl = document.createElement('div'), props = ['backgroundColor','borderBottomColor','borderBottomWidth','borderLeftColor','borderLeftWidth', @@ -16,23 +16,25 @@ return (source + (target - source) * pos).toFixed(3); } - function color(source,target,pos) { + function substr(str, pos) { + return str.substr(pos, 1); + } + + function color(source, target, pos) { var i = 2, j, arg, tmp, v = [], r = []; while (j = 3, arg = arguments[i - 1], i--) { /*! lint !*/ - if (arg[0] === 'r') { + if (arg[0] == 'r') { arg = arg.match(/\d+/g); while (j--) { v.push(~~arg[j]); } } else { - if (arg.length === 4) { - arg = '#' + arg[1] + arg[1] + arg[2] + arg[2] + arg[3] + arg[3]; - } + tmp = arg.length == 4 ? 0 : 1; while (j--) { - v.push(parseInt(arg.substr(1 + j * 2, 2), 16)); + v.push(parseInt(substr(arg, j * 2) + substr(arg, j * 2 + tmp), 16)); } } } @@ -69,7 +71,7 @@ } function worker(el, current, target, start, finish, dur, interval, easing, opts, after) { - var time = +new Date(), + var time = +new Date, pos = time > finish ? 1 : (time - start) / dur, prop; @@ -89,7 +91,7 @@ } container[emile] = function (el, style, opts, after) { - el = typeof el === 'string' ? document.getElementById(el) : el; + el = typeof el == 'string' ? document.getElementById(el) : el; opts = opts || {}; var prop, interval, diff --git a/emile.min.js b/emile.min.js index da0ba1b..d502f4a 100644 --- a/emile.min.js +++ b/emile.min.js @@ -1 +1 @@ -(function(t,u){function v(a,e,f){return(a+(e-a)*f).toFixed(3)}function w(a,e,f){for(var c=2,d,b,g=[],i=[];d=3,b=arguments[c-1],c--;)if(b[0]==="r")for(b=b.match(/\d+/g);d--;)g.push(~~b[d]);else{if(b.length===4)b="#"+b[1]+b[1]+b[2]+b[2]+b[3]+b[3];for(;d--;)g.push(parseInt(b.substr(1+d*2,2),16))}for(;d--;){c=~~(g[d+3]+(g[d]-g[d+3])*f);i.push(c<0?0:c>255?255:c)}return"rgb("+i.join(",")+")"}function m(a){var e=parseFloat(a);a=a.replace(/^[\-\d\.]+/,"");return isNaN(e)?{v:a,f:w,u:""}:{v:e,f:v,u:a}}function x(a){var e,f={},c=j.length;n.innerHTML='
';for(a=n.childNodes[0].style;c--;)if(e=a[j[c]])f[j[c]]=m(e);return f}var n=document.createElement("div"),j=["backgroundColor","borderBottomColor","borderBottomWidth","borderLeftColor","borderLeftWidth","borderRightColor","borderRightWidth","borderSpacing","borderTopColor","borderTopWidth","bottom","color","fontSize","fontWeight","height","left","letterSpacing","lineHeight","marginBottom","marginLeft","marginRight","marginTop","maxHeight","maxWidth","minHeight","minWidth","opacity","outlineColor","outlineOffset","outlineWidth","paddingBottom","paddingLeft","paddingRight","paddingTop","right","textIndent","top","width","wordSpacing","zIndex"];u[t]=function(a,e,f,c){a=typeof a==="string"?document.getElementById(a):a;f=f||{};var d,b,g=x(e);e=a.currentStyle?a.currentStyle:getComputedStyle(a,null);var i=f.easing||function(k){return-Math.cos(k*Math.PI)/2+0.5},o={},p=+new Date,q=f.duration||200,r=p+q;for(d in g)o[d]=m(e[d]);b=setInterval(function(){var k=a,s=f,l=+new Date,y=l>r?1:(l-p)/q,h;for(h in g)k.style[h]=g[h].f(o[h].v,g[h].v,i(y))+g[h].u;if(l>r){clearInterval(b);s.after&&s.after();c&&setTimeout(c,1)}},10)}})("emile",this); +(function(t,u){function v(a,c,d){return(a+(c-a)*d).toFixed(3)}function w(a,c,d){for(var g=2,b,f,e,h=[],j=[];b=3,f=arguments[g-1],g--;)if(f[0]=="r")for(f=f.match(/\d+/g);b--;)h.push(~~f[b]);else for(e=f.length==4?0:1;b--;)h.push(parseInt(f.substr(b*2,1)+f.substr(b*2+e,1),16));for(;b--;){e=~~(h[b+3]+(h[b]-h[b+3])*d);j.push(e<0?0:e>255?255:e)}return"rgb("+j.join(",")+")"}function n(a){var c=parseFloat(a);a=a.replace(/^[\-\d\.]+/,"");return isNaN(c)?{v:a,f:w,u:""}:{v:c,f:v,u:a}}function x(a){var c,d={},g=k.length;o.innerHTML='
';for(a=o.childNodes[0].style;g--;)if(c=a[k[g]])d[k[g]]=n(c);return d}var o=document.createElement("div"),k=["backgroundColor","borderBottomColor","borderBottomWidth","borderLeftColor","borderLeftWidth","borderRightColor","borderRightWidth","borderSpacing","borderTopColor","borderTopWidth","bottom","color","fontSize","fontWeight","height","left","letterSpacing","lineHeight","marginBottom","marginLeft","marginRight","marginTop","maxHeight","maxWidth","minHeight","minWidth","opacity","outlineColor","outlineOffset","outlineWidth","paddingBottom","paddingLeft","paddingRight","paddingTop","right","textIndent","top","width","wordSpacing","zIndex"];u[t]=function(a,c,d,g){a=typeof a=="string"?document.getElementById(a):a;d=d||{};var b,f,e=x(c);c=a.currentStyle?a.currentStyle:getComputedStyle(a,null);var h=d.easing||function(l){return-Math.cos(l*Math.PI)/2+0.5},j={},p=+new Date,q=d.duration||200,r=p+q;for(b in e)j[b]=n(c[b]);f=setInterval(function(){var l=a,s=d,m=+new Date,y=m>r?1:(m-p)/q,i;for(i in e)l.style[i]=e[i].f(j[i].v,e[i].v,h(y))+e[i].u;if(m>r){clearInterval(f);s.after&&s.after();g&&setTimeout(g,1)}},10)}})("emile",this); \ No newline at end of file