3 Roo.ux.FlipCounter = function(options)
5 Roo.ux.FlipCounter.superclass.constructor.call(this, options);
7 //Roo.apply(this, options);
8 //this.el = $(element);
9 //this.options = $.extend({}, defaults, options);
14 * When a box is flipped
15 * @param {Roo.ux.FlipCounter} counter
20 * When a box is resized
21 * @param {Roo.ux.FlipCounter} counter
27 this.digits = new Array();
34 Roo.extend(Roo.ux.FlipCounter, Roo.bootstrap.Component, {
41 digits : false, // array...
45 getAutoCreate : function(){
49 cls: 'flipcounter ' + this.cls,
54 initEvents : function ()
56 var startNum = (1.0*this.startnumber).toFixed(this.decimal);
58 for (i=startNum.length-1; i>=0; i=i-1)
60 if (startNum[i] == '.') {
61 this.addSeparator('.');
64 this.addDigit(startNum[i]);
66 this.currentNumber = this.startnumber;
69 addDigit : function (num)
72 Roo.log("Add digit "+ num);
73 // Add separator after every 3rd digit
74 /*if (this.digits.length % 3 == 0 && this.digits.length != 0)
76 this.addSeparator(',');
81 var digit = new Roo.ux.FlipCounter.Digit({ manager : this, currentNumber : num });
83 this.digits.push(digit);
84 digit.render(this.el, 0);
87 this.ulWidth = this.ulWidth + digit.el.getWidth(true);
89 'min-width' : this.ulWidth,
90 'min-height' :digit.el.getHeight(true)
95 removeDigit : function ()
97 var digit = this.digits.splice(this.digits.length-1, 1)[0];
99 this.ulWidth = this.ulWidth - digit.el.getWidth(true);
103 // if (this.digits.length % 3 == 0)
105 // var comma = this.el.select('li.comma:first-child');
106 // this.ulWidth = this.ulWidth - comma.getWidth(true);
110 // Update width to current
111 this.el.set( { 'min-width' : this.ulWidth});
114 addSeparator : function (str)
116 var comma = this.el.insertHtml('afterBegin','<li class="comma">'+str+'</li>',true);
120 this.ulWidth = this.ulWidth + comma.getWidth(true);
121 this.el.set({'min-width' : this.ulWidth});
124 updateTo : function (num)
126 var numStr = (1.0*num).toFixed(this.decimal);
128 this.currentNumber = num;
130 var dl = this.digits.length + (this.decimal > 0 ? 1 : 0);
131 // Change the number of digits displayed if needed
132 if (numStr.length != dl)
134 var diff = numStr.length - dl;
135 Roo.log("DIFF LEN=" +diff);
138 for (i=0; i<diff; i=i+1) {
144 for (i=diff; i<0; i=i+1) {
149 this.fireEvent('onResize',this);
152 // Change all digit values
154 for (i=0, n=0; i<numStr.length; i=i+1)
156 if (numStr[numStr.length - 1 - i] == '.') {
159 Roo.log("UPDATE DIGIT=" + i + " to " + numStr[numStr.length - 1 - i]);
160 this.digits[n++].flipTo(numStr[numStr.length - 1 - i]);
166 Roo.ux.FlipCounter.Digit = function(options)
168 //Roo.apply(this, options);
169 Roo.ux.FlipCounter.Digit.superclass.constructor.call(this, options);
172 this.currentNumber = parseInt(this.currentNumber);
177 Roo.extend(Roo.ux.FlipCounter.Digit, Roo.bootstrap.Component, {
179 manager : null, // the flipcounter...
188 bottomFrontDiv : null,
191 bottomNumBack : null,
192 bottomNumFront : null,
197 getAutoCreate : function(){
205 { cls : 'flipper_top flipper_top1' },
207 cls : 'flipper_top flipper_top2 flipper_top_back',
209 { tag: 'span', html: this.currentNumber },
215 cls : 'flipper_top flipper_top_front',
217 { tag: 'span', html: this.currentNumber },
222 { cls : 'flipper_bottom flipper_bottom4' },
223 { cls : 'flipper_bottom flipper_bottom3' },
224 { cls : 'flipper_bottom flipper_bottom2' },
226 cls : 'flipper_bottom flipper_bottom1 flipper_bottom_back',
228 { tag: 'span', html: this.currentNumber },
233 cls : 'flipper_bottom flipper_bottom_front',
235 { tag: 'span', html: this.currentNumber },
246 initEvents : function()
251 this.topFrontDiv = this.el.select('.flipper_top_front',true).first();
252 this.bottomFrontDiv = this.el.select('.flipper_bottom_front',true).first();
253 this.topNumBack = this.el.select('.flipper_top_back span',true).first();
254 this.topNumFront = this.el.select('.flipper_top_front span',true).first();
255 this.bottomNumBack = this.el.select('.flipper_bottom_back span',true).first();
256 this.bottomNumFront = this.el.select('.flipper_bottom_front span',true).first();
258 this.targetNum = this.currentNumber;
259 this.currentNum = this.currentNumber;
260 this.nextNum = this.currentNumber;
262 this.currentlyAnimating = false;
265 flipTo : function (num)
267 if (this.currentNum === num)
270 this.targetNum = num;
271 if (this.currentlyAnimating) {
278 animNext : function ()
280 if (this.currentNum == this.targetNum)
282 this.currentlyAnimating = false;
286 var doRandomDelay = !this.currentlyAnimating;
287 this.currentlyAnimating = true;
288 this.nextNum = this.currentNum + 1;
289 if (this.nextNum > 9) {
293 var delay = Math.random()/5;
294 if (!doRandomDelay) {
298 // Animate top flipper
300 digit.topNumBack.dom.innerHTML = digit.nextNum;
302 digit.topFrontDiv.animate(
304 scaleY: {from :1, to : 0}
306 this.manager.speed, //duration
307 function() {}, // oncomplate
309 'motion' // desplay type.
311 }).defer(delay, this);
315 digit.bottomNumFront.dom.innerHTML = digit.nextNum;
317 digit.bottomFrontDiv.animate(
319 scaleY: {from: 0, to : 1},
322 this.manager.speed * 0.5, //duration
324 digit.currentNum = digit.nextNum;
325 digit.topNumFront.dom.innerHTML = digit.currentNum;
326 digit.topFrontDiv.attr('style', '');
327 digit.bottomNumBack.dom.innerHTML = digit.currentNum;
330 digit.manager.fireEvent('onFlip', digit.manager);
334 'motion' // desplay type.
337 }).defer(delay + this.manager.speed, this);
341 //??? digit.bottomFrontDiv. digit.bottomNumFront.html(digit.nextNum);