ux/FlipCounter.js
[roojs1] / ux / FlipCounter.js
index ca2aa0b..59b2c6b 100644 (file)
@@ -53,7 +53,10 @@ Roo.extend(Roo.ux.FlipCounter, Roo.bootstrap.Component, {
         
     initEvents : function ()
     { 
+        
+        
         var startNum = (1.0*this.startnumber).toFixed(this.decimal);
+        //Roo.log("STARTNUmber:  " + startNum);
         
         for (i=startNum.length-1; i>=0; i=i-1)
         {
@@ -68,6 +71,8 @@ Roo.extend(Roo.ux.FlipCounter, Roo.bootstrap.Component, {
     
     addDigit : function (num)
     {
+        
+        //Roo.log("Add digit "+ num);
         // Add separator after every 3rd digit
         /*if (this.digits.length % 3 == 0 && this.digits.length != 0)
         {
@@ -124,11 +129,13 @@ Roo.extend(Roo.ux.FlipCounter, Roo.bootstrap.Component, {
         var numStr = (1.0*num).toFixed(this.decimal);
         
         this.currentNumber = num;
+        
+        var dl = this.digits.length + (this.decimal > 0 ? 1 : 0);
         // Change the number of digits displayed if needed
-        if (numStr.length != this.digits.length)
+        if (numStr.length != dl)
         {
-            var diff = numStr.length - this.digits.length;
-            Roo.log("DIFF LEN=" +diff);
+            var diff = numStr.length - dl;
+            //Roo.log("DIFF LEN=" +diff);
             if (diff > 0)
             {
                 for (i=0; i<diff; i=i+1) {
@@ -146,13 +153,14 @@ Roo.extend(Roo.ux.FlipCounter, Roo.bootstrap.Component, {
         }
         
         // Change all digit values
-        for (i=0; i<numStr.length; i=i+1)
+        
+        for (i=0, n=0; i<numStr.length; i=i+1)
         {
             if (numStr[numStr.length - 1 - i] == '.') {
                 continue;
             }
-            Roo.log("UPDATE DIGIT=" + i + " to " + numStr[numStr.length - 1 - i]);
-            this.digits[i].flipTo(numStr[numStr.length - 1 - i]);
+            //Roo.log("UPDATE DIGIT=" + i + " to " + numStr[numStr.length - 1 - i]);
+            this.digits[n++].flipTo(numStr[numStr.length - 1 - i]);
         }
     }
     
@@ -191,6 +199,7 @@ Roo.extend(Roo.ux.FlipCounter.Digit, Roo.bootstrap.Component, {
     
     getAutoCreate : function(){
         
+        //Roo.log("render with cn=" + this.currentNumber);
         return {
                 tag: 'li',
                 cn : [
@@ -201,7 +210,7 @@ Roo.extend(Roo.ux.FlipCounter.Digit, Roo.bootstrap.Component, {
                             {
                                 cls : 'flipper_top flipper_top2 flipper_top_back',
                                 cn : [
-                                    { tag: 'span', html: this.currentNumber },
+                                    { tag: 'span', html: ""+this.currentNumber },
                                     { cls : 'rings' }
                                 ]
                         
@@ -209,7 +218,7 @@ Roo.extend(Roo.ux.FlipCounter.Digit, Roo.bootstrap.Component, {
                             {
                                 cls : 'flipper_top flipper_top_front',
                                 cn : [
-                                    { tag: 'span', html: this.currentNumber },
+                                    { tag: 'span', html: ""+this.currentNumber },
                                     { cls : 'rings' }
                                 ]
                         
@@ -220,14 +229,14 @@ Roo.extend(Roo.ux.FlipCounter.Digit, Roo.bootstrap.Component, {
                             {
                                 cls : 'flipper_bottom flipper_bottom1 flipper_bottom_back',
                                 cn : [
-                                    { tag: 'span', html: this.currentNumber },
+                                    { tag: 'span', html: ""+this.currentNumber },
                                     { cls : 'rings' }
                                 ]
                             },
                             {
                                 cls : 'flipper_bottom flipper_bottom_front',
                                 cn : [
-                                    { tag: 'span', html: this.currentNumber },
+                                    { tag: 'span', html: ""+this.currentNumber },
                                     { cls : 'rings' }
                                 ]
                             },