X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=ux%2FFlipCounter.js;h=0296373a26c84aaba21120b827652781ff211035;hb=0b69a11b1055a6d3a3fd0719bdd58b5a235de0e4;hp=c54e7b21e9a3e4978c0c702e538923831922226c;hpb=6e34ce73e154237f2bc18f477770ce90e12ba55e;p=roojs1 diff --git a/ux/FlipCounter.js b/ux/FlipCounter.js index c54e7b21e9..0296373a26 100644 --- a/ux/FlipCounter.js +++ b/ux/FlipCounter.js @@ -2,7 +2,9 @@ Roo.ux.FlipCounter = function(options) { - Roo.apply(this, options); + Roo.ux.FlipCounter.superclass.constructor.call(this, options); + + //Roo.apply(this, options); //this.el = $(element); //this.options = $.extend({}, defaults, options); this.addEvents({ @@ -33,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); @@ -85,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); @@ -100,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 @@ -112,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