Commits

Chris Nanney committed 4901cf4

Added minified version back, because why not?

Comments (0)

Files changed (1)

js/flipcounter.min.js

+/**
+ * Apple-Style Flip Counter
+ * ------------------------
+ *
+ * Copyright (c) 2010 Chris Nanney
+ * http://cnanney.com/journal/code/apple-style-counter-revisited/
+ * http://cnanney.com/journal/code/apple-style-counter/
+ *
+ * Licensed under MIT
+ * http://www.opensource.org/licenses/mit-license.php
+ */
+var flipCounter=function(D,L){function t(){j=a.value.toString();a.value+=a.inc;i=a.value.toString();p(j,i);if(a.auto===true)l=setTimeout(t,a.pace)}function E(b,e,c){var d=a.value,f=typeof e=="undefined"?false:e,g=typeof c=="undefined"?1:c;f===true&&g--;if(d!=b){j=a.value.toString();a.auto=true;if(d+a.inc<=b&&g!=0)d+=a.inc;else d=b;a.value=d;i=a.value.toString();p(j,i);l=setTimeout(function(){E(b,f,g)},a.pace)}else a.auto=false}function p(b,e){u=F(b);v=F(e);if(e.length>b.length)for(var c=e.length-
+b.length;c>0;){var d=v[e.length-c],f=Number(e.length-c+1)-1;f%3==0&&jQuery(h).prepend('<ul class="cd"><li class="s"></li></ul>');jQuery(h).prepend('<ul class="cd" id="d'+f+'"><li class="t"></li><li class="b"></li></ul>');jQuery(h+" #d"+f+" li.t").css({"background-position":"0 -"+d*q+"px"});jQuery(h+" #d"+f+" li.b").css({"background-position":"0 -"+d*o+"px"});c--}if(e.length<b.length)for(c=b.length-e.length;c>0;){jQuery(h+" #d"+(b.length-c)).remove();d=jQuery(h+" li").first();d.hasClass("s")&&d.parent("ul").remove();
+c--}for(c=0;c<u.length;c++)v[c]!=u[c]&&M(c,u[c],v[c])}function M(b,e,c){var d;if(a.auto===true&&a.pace<=300)switch(b){case 0:d=a.pace/6;break;case 1:d=a.pace/5;break;case 2:d=a.pace/4;break;case 3:d=a.pace/3;break;default:d=a.pace/2}else d=80;d=d>80?80:d;jQuery(h+" #d"+b+" li.t").delay(d).animate({"background-position":"-"+r+"px -"+e*q+"px"},0).delay(d).animate({"background-position":r*-2+"px -"+e*q+"px"},0).delay(d).animate({"background-position":"0 -"+c*q+"px"},0,function(){jQuery(h+" #d"+b+" li.b").animate({"background-position":"-"+
+r+"px -"+e*o+"px"},0).delay(d).animate({"background-position":r*-2+"px -"+c*o+"px"},0).delay(d).animate({"background-position":r*-3+"px -"+c*o+"px"},0).delay(d).animate({"background-position":"0 -"+c*o+"px"},0)})}function F(b){for(var e=[],c=0;c<b.length;c++){J=b.length-(c+1);K=b.length-c;e[c]=b.substring(J,K)}return e}function n(b){return!isNaN(parseFloat(b))&&isFinite(b)}function w(){clearTimeout(l);l=null}var x={value:0,inc:1,pace:1E3,auto:true,debug:false},a=L||{},h=D&&D!=""?"#"+D:"#counter",
+s;for(s in x)a[s]=s in a?a[s]:x[s];var q=39,o=64,r=53,u=[],v=[],J,K,j,i,l=null;this.setValue=function(b){if(n(b)){j=a.value.toString();i=b.toString();a.value=b;p(j,i)}return this};this.setIncrement=function(b){a.inc=n(b)?b:x.inc;return this};this.setPace=function(b){a.pace=n(b)?b:x.pace;return this};this.setAuto=function(b){if(b&&!a.atuo){a.auto=true;t()}if(!b&&a.auto){l&&w();a.auto=false}return this};this.step=function(){a.auto||t();return this};this.add=function(b){if(n(b)){j=a.value.toString();
+a.value+=b;i=a.value.toString();p(j,i)}return this};this.subtract=function(b){if(n(b)){j=a.value.toString();a.value-=b;if(a.value>=0)i=a.value.toString();else{i="0";a.value=0}p(j,i)}return this};this.incrementTo=function(b){l&&w();E(b)};this.smartIncrementTo=function(b,e,c){function d(y,m,z,A,G){return"Condition Checks:\n1: "+(y/m>=1?"pass":"fail")+", 2: "+(m*z<=y?"pass":"fail")+", 3: "+(Math.abs(m*z-y)<=5?"pass":"fail")+", 4: "+(Math.abs(m*A-G)<=100?"pass":"fail")+", 5: "+(m*A<=G?"pass":"fail")+
+"\n----\n   Pace: "+A+"\n   Cycles: "+m+"\n   Calculated Inc: "+y/m+"\n   Rounded Inc: "+z+"\n   Calculated time: "+Math.abs(m*A)+"\n   Target time: "+G+"\n   ACTUAL END VALUE: "+(m*z+a.value)}l&&w();c=n(c)?c*1E3:1E4;e=n(e)?e:a.pace;var f=n(b)?b-a.value:0,g,k,H,I,B=0,C={pace:0,inc:0};e=c/f>e?Math.round(c/f/10)*10:e;g=Math.floor(c/e);k=Math.round(f/g);H=Math.abs(f-g*k)+Math.abs(g*e-c);a.debug&&console.log("***************************************************************\nSTART: "+a.value+"\nEND: "+
+b+"\n"+d(f,g,k,e,c));if(f>0){for(;(f/g<1||g*k>f||Math.abs(g*k-f)>5||Math.abs(g*e-c)>100||g*e>c)&&B<500;){e+=10;g=Math.floor(c/e);k=Math.round(f/g);I=Math.abs(f-g*k)+Math.abs(g*e-c);if(I<H){H=I;C.pace=e;C.inc=k}a.debug&&console.log("ADJUSTMENT: "+(B+1)+"\n"+d(f,g,k,e,c));B++}if(B==100){a.inc=C.inc;a.pace=C.pace}else{a.inc=k;a.pace=e}E(b,true,g)}};this.getValue=function(){return a.value};this.stop=function(){l&&w();return this};(function(b){for(var e=b.toString().length,c=1,d=0;d<e;d++){jQuery(h).prepend('<ul class="cd" id="d'+
+d+'"><li class="t"></li><li class="b"></li></ul>');c!=e&&c%3==0&&jQuery(h).prepend('<ul class="cd"><li class="s"></li></ul>');c++}b=F(b.toString());for(d=0;d<e;d++){jQuery(h+" #d"+d+" li.t").css({"background-position":"0 -"+b[d]*q+"px"});jQuery(h+" #d"+d+" li.b").css({"background-position":"0 -"+b[d]*o+"px"})}if(a.auto===true)l=setTimeout(t,a.pace)})(a.value)};