X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=ux%2FFlipCounter.js;h=0296373a26c84aaba21120b827652781ff211035;hb=0b69a11b1055a6d3a3fd0719bdd58b5a235de0e4;hp=fc6fe18bf792dc466e265417468b11f63b79bd28;hpb=97301ddcd5546e67232f65e4f3e1fb584eb9ffd4;p=roojs1 diff --git a/ux/FlipCounter.js b/ux/FlipCounter.js index fc6fe18bf7..0296373a26 100644 --- a/ux/FlipCounter.js +++ b/ux/FlipCounter.js @@ -35,39 +35,50 @@ 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; @@ -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','
  • ,
  • ',true); + var comma = this.el.insertHtml('afterBegin','
  • '+str+'
  • ',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