remove debugging code
[roojs1] / ux / FlipCounter.js
index a18a936..0296373 100644 (file)
@@ -2,7 +2,7 @@
 
 Roo.ux.FlipCounter = function(options)
 {
-    Roo.bootstrap.FlipCounter.superclass.constructor.call(this, config);
+    Roo.ux.FlipCounter.superclass.constructor.call(this, options);
     
     //Roo.apply(this, options);
     //this.el = $(element);
@@ -35,44 +35,55 @@ Roo.extend(Roo.ux.FlipCounter, Roo.bootstrap.Component, {
     
     speed : 0.2,
     startnumber : 0,
+    currentNumber : 0,
+    decimal : 0,
     
     digits : false, // array...
-    ulWidth : 0, 
+    ulWidth : 0,
+    cls : '',
     
     getAutoCreate : function(){
         
         return {
             tag: 'ul',
-            cls: 'flipcounter',
+            cls: 'flipcounter ' + this.cls,
             
         };
     },
         
     initEvents : function ()
     { 
-        var startNum = ""+ this.startnumber;
+        
+        
+        var startNum = (1.0*this.startnumber).toFixed(this.decimal);
+        //Roo.log("STARTNUmber:  " + startNum);
         
         for (i=startNum.length-1; i>=0; i=i-1)
         {
+            if (startNum[i] == '.') {
+                this.addSeparator('.');
+                continue;
+            }
             this.addDigit(startNum[i]);
         }
+        this.currentNumber = this.startnumber;
     },
     
     addDigit : function (num)
     {
+        
+        //Roo.log("Add digit "+ num);
         // Add separator after every 3rd digit
-        if (this.digits.length % 3 == 0 && this.digits.length != 0)
-        {
-            this.addSeparator();
+        if (this.decimal == 0 && this.digits.length % 3 == 0 && this.digits.length != 0) {
+            this.addSeparator(',');
         }
         
-         
-        
+          
         
         var digit = new Roo.ux.FlipCounter.Digit({ manager : this, currentNumber : num });
         digit.manager = this;
         this.digits.push(digit);
-        digit.render(this.el);
+        digit.render(this.el, 0);
          
         // Update width
         this.ulWidth = this.ulWidth + digit.el.getWidth(true);
@@ -87,11 +98,11 @@ Roo.extend(Roo.ux.FlipCounter, Roo.bootstrap.Component, {
     {
         var digit = this.digits.splice(this.digits.length-1, 1)[0];
         
-        this.ulWidth = this.ulWidth - digit.el.outerWidth(true);
-        digit.li.remove();
+        this.ulWidth = this.ulWidth - digit.el.getWidth(true);
+        digit.el.remove();
         
         // Remove separators
-        if (this.digits.length % 3 == 0)
+        if (this.decimal == 0 & this.digits.length % 3 == 0)
         {
             var comma = this.el.select('li.comma:first-child');
             this.ulWidth = this.ulWidth - comma.getWidth(true);
@@ -102,9 +113,9 @@ Roo.extend(Roo.ux.FlipCounter, Roo.bootstrap.Component, {
         this.el.set( { 'min-width' : this.ulWidth});
     },
     
-    addSeparator : function (num)
+    addSeparator : function (str)
     {
-        var comma = this.el.insertHtml('afterBegin','<li class="comma">,</li>',true);
+        var comma = this.el.insertHtml('afterBegin','<li class="comma">'+str+'</li>',true);
         
         // Update width
         
@@ -114,12 +125,16 @@ Roo.extend(Roo.ux.FlipCounter, Roo.bootstrap.Component, {
     
     updateTo : function (num)
     {
-        var numStr = parseInt(num).toString();
+        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;
+            var diff = numStr.length - dl;
+            //Roo.log("DIFF LEN=" +diff);
             if (diff > 0)
             {
                 for (i=0; i<diff; i=i+1) {
@@ -137,9 +152,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)
         {
-            this.digits[i].flipTo(numStr[numStr.length - 1 - i]);
+            if (numStr[numStr.length - 1 - i] == '.') {
+                continue;
+            }
+            //Roo.log("UPDATE DIGIT=" + i + " to " + numStr[numStr.length - 1 - i]);
+            this.digits[n++].flipTo(numStr[numStr.length - 1 - i]);
         }
     }
     
@@ -147,7 +167,9 @@ Roo.extend(Roo.ux.FlipCounter, Roo.bootstrap.Component, {
 
 Roo.ux.FlipCounter.Digit = function(options)
 {
-    Roo.apply(this, options);
+    //Roo.apply(this, options);
+    Roo.ux.FlipCounter.Digit.superclass.constructor.call(this, options);
+
     
     this.currentNumber = parseInt(this.currentNumber);
     
@@ -158,6 +180,10 @@ Roo.extend(Roo.ux.FlipCounter.Digit, Roo.bootstrap.Component, {
 
     manager : null, // the flipcounter... 
     currentNumber : 0,
+    
+    
+    currentNum : 0,
+    nextNum : 0,
     targetNum : 0,
     
     topFrontDiv  : null,
@@ -168,8 +194,11 @@ Roo.extend(Roo.ux.FlipCounter.Digit, Roo.bootstrap.Component, {
     bottomNumFront : null,
     
     
+    
+    
     getAutoCreate : function(){
         
+        //Roo.log("render with cn=" + this.currentNumber);
         return {
                 tag: 'li',
                 cn : [
@@ -180,7 +209,7 @@ Roo.extend(Roo.ux.FlipCounter.Digit, Roo.bootstrap.Component, {
                             {
                                 cls : 'flipper_top flipper_top2 flipper_top_back',
                                 cn : [
-                                    { tag: 'span', html: num },
+                                    { tag: 'span', html: ""+this.currentNumber },
                                     { cls : 'rings' }
                                 ]
                         
@@ -188,7 +217,7 @@ Roo.extend(Roo.ux.FlipCounter.Digit, Roo.bootstrap.Component, {
                             {
                                 cls : 'flipper_top flipper_top_front',
                                 cn : [
-                                    { tag: 'span', html: num },
+                                    { tag: 'span', html: ""+this.currentNumber },
                                     { cls : 'rings' }
                                 ]
                         
@@ -199,14 +228,14 @@ Roo.extend(Roo.ux.FlipCounter.Digit, Roo.bootstrap.Component, {
                             {
                                 cls : 'flipper_bottom flipper_bottom1 flipper_bottom_back',
                                 cn : [
-                                    { tag: 'span', html: num },
+                                    { tag: 'span', html: ""+this.currentNumber },
                                     { cls : 'rings' }
                                 ]
                             },
                             {
                                 cls : 'flipper_bottom flipper_bottom_front',
                                 cn : [
-                                    { tag: 'span', html: num },
+                                    { tag: 'span', html: ""+this.currentNumber },
                                     { cls : 'rings' }
                                 ]
                             },
@@ -222,16 +251,16 @@ Roo.extend(Roo.ux.FlipCounter.Digit, Roo.bootstrap.Component, {
         
          
         
-        this.topFrontDiv = this.el.select('.flipper_top_front',true);
-        this.bottomFrontDiv = this.el.select('.flipper_bottom_front',true);
-        this.topNumBack = this.el.select('.flipper_top_back span',true);
-        this.topNumFront = this.el.select('.flipper_top_front span',true);
-        this.bottomNumBack = this.el.select('.flipper_bottom_back span',true);
-        this.bottomNumFront = this.el.select('.flipper_bottom_front span',true);
+        this.topFrontDiv = this.el.select('.flipper_top_front',true).first();
+        this.bottomFrontDiv = this.el.select('.flipper_bottom_front',true).first();
+        this.topNumBack = this.el.select('.flipper_top_back span',true).first();
+        this.topNumFront = this.el.select('.flipper_top_front span',true).first();
+        this.bottomNumBack = this.el.select('.flipper_bottom_back span',true).first();
+        this.bottomNumFront = this.el.select('.flipper_bottom_front span',true).first();
         
-        this.targetNum = currentNumber;
-        this.currentNum = currentNumber;
-        this.nextNum = currentNumber;
+        this.targetNum = this.currentNumber;
+        this.currentNum = this.currentNumber;
+        this.nextNum = this.currentNumber;
         
         this.currentlyAnimating = false;
     },
@@ -271,7 +300,7 @@ Roo.extend(Roo.ux.FlipCounter.Digit, Roo.bootstrap.Component, {
         
         // Animate top flipper
         var digit = this;
-        digit.topNumBack.html(digit.nextNum);
+        digit.topNumBack.dom.innerHTML = digit.nextNum;
         (function() {
             digit.topFrontDiv.animate(
                 {
@@ -293,7 +322,7 @@ Roo.extend(Roo.ux.FlipCounter.Digit, Roo.bootstrap.Component, {
                     scaleY: {from: 0, to : 1},
                     
                 },
-                this.manager.options.speed * 0.5, //duration
+                this.manager.speed * 0.5, //duration
                 function() {
                     digit.currentNum = digit.nextNum;
                     digit.topNumFront.dom.innerHTML = digit.currentNum;