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 ()
58 var startNum = (1.0*this.startnumber).toFixed(this.decimal);
59 Roo.log("STARTNUmber: " + startNum);
61 for (i=startNum.length-1; i>=0; i=i-1)
63 if (startNum[i] == '.') {
64 this.addSeparator('.');
67 this.addDigit(startNum[i]);
69 this.currentNumber = this.startnumber;
72 addDigit : function (num)
75 Roo.log("Add digit "+ num);
76 // Add separator after every 3rd digit
77 /*if (this.digits.length % 3 == 0 && this.digits.length != 0)
79 this.addSeparator(',');
84 var digit = new Roo.ux.FlipCounter.Digit({ manager : this, currentNumber : num });
86 this.digits.push(digit);
87 digit.render(this.el, 0);
90 this.ulWidth = this.ulWidth + digit.el.getWidth(true);
92 'min-width' : this.ulWidth,
93 'min-height' :digit.el.getHeight(true)
98 removeDigit : function ()
100 var digit = this.digits.splice(this.digits.length-1, 1)[0];
102 this.ulWidth = this.ulWidth - digit.el.getWidth(true);
106 // if (this.digits.length % 3 == 0)
108 // var comma = this.el.select('li.comma:first-child');
109 // this.ulWidth = this.ulWidth - comma.getWidth(true);
113 // Update width to current
114 this.el.set( { 'min-width' : this.ulWidth});
117 addSeparator : function (str)
119 var comma = this.el.insertHtml('afterBegin','<li class="comma">'+str+'</li>',true);
123 this.ulWidth = this.ulWidth + comma.getWidth(true);
124 this.el.set({'min-width' : this.ulWidth});
127 updateTo : function (num)
129 var numStr = (1.0*num).toFixed(this.decimal);
131 this.currentNumber = num;
133 var dl = this.digits.length + (this.decimal > 0 ? 1 : 0);
134 // Change the number of digits displayed if needed
135 if (numStr.length != dl)
137 var diff = numStr.length - dl;
138 Roo.log("DIFF LEN=" +diff);
141 for (i=0; i<diff; i=i+1) {
147 for (i=diff; i<0; i=i+1) {
152 this.fireEvent('onResize',this);
155 // Change all digit values
157 for (i=0, n=0; i<numStr.length; i=i+1)
159 if (numStr[numStr.length - 1 - i] == '.') {
162 Roo.log("UPDATE DIGIT=" + i + " to " + numStr[numStr.length - 1 - i]);
163 this.digits[n++].flipTo(numStr[numStr.length - 1 - i]);
169 Roo.ux.FlipCounter.Digit = function(options)
171 //Roo.apply(this, options);
172 Roo.ux.FlipCounter.Digit.superclass.constructor.call(this, options);
175 this.currentNumber = parseInt(this.currentNumber);
180 Roo.extend(Roo.ux.FlipCounter.Digit, Roo.bootstrap.Component, {
182 manager : null, // the flipcounter...
191 bottomFrontDiv : null,
194 bottomNumBack : null,
195 bottomNumFront : null,
200 getAutoCreate : function(){
202 Roo.log("render with cn=" + this.currentNumber);
209 { cls : 'flipper_top flipper_top1' },
211 cls : 'flipper_top flipper_top2 flipper_top_back',
213 { tag: 'span', html: ""+this.currentNumber },
219 cls : 'flipper_top flipper_top_front',
221 { tag: 'span', html: ""+this.currentNumber },
226 { cls : 'flipper_bottom flipper_bottom4' },
227 { cls : 'flipper_bottom flipper_bottom3' },
228 { cls : 'flipper_bottom flipper_bottom2' },
230 cls : 'flipper_bottom flipper_bottom1 flipper_bottom_back',
232 { tag: 'span', html: ""+this.currentNumber },
237 cls : 'flipper_bottom flipper_bottom_front',
239 { tag: 'span', html: ""+this.currentNumber },
250 initEvents : function()
255 this.topFrontDiv = this.el.select('.flipper_top_front',true).first();
256 this.bottomFrontDiv = this.el.select('.flipper_bottom_front',true).first();
257 this.topNumBack = this.el.select('.flipper_top_back span',true).first();
258 this.topNumFront = this.el.select('.flipper_top_front span',true).first();
259 this.bottomNumBack = this.el.select('.flipper_bottom_back span',true).first();
260 this.bottomNumFront = this.el.select('.flipper_bottom_front span',true).first();
262 this.targetNum = this.currentNumber;
263 this.currentNum = this.currentNumber;
264 this.nextNum = this.currentNumber;
266 this.currentlyAnimating = false;
269 flipTo : function (num)
271 if (this.currentNum === num)
274 this.targetNum = num;
275 if (this.currentlyAnimating) {
282 animNext : function ()
284 if (this.currentNum == this.targetNum)
286 this.currentlyAnimating = false;
290 var doRandomDelay = !this.currentlyAnimating;
291 this.currentlyAnimating = true;
292 this.nextNum = this.currentNum + 1;
293 if (this.nextNum > 9) {
297 var delay = Math.random()/5;
298 if (!doRandomDelay) {
302 // Animate top flipper
304 digit.topNumBack.dom.innerHTML = digit.nextNum;
306 digit.topFrontDiv.animate(
308 scaleY: {from :1, to : 0}
310 this.manager.speed, //duration
311 function() {}, // oncomplate
313 'motion' // desplay type.
315 }).defer(delay, this);
319 digit.bottomNumFront.dom.innerHTML = digit.nextNum;
321 digit.bottomFrontDiv.animate(
323 scaleY: {from: 0, to : 1},
326 this.manager.speed * 0.5, //duration
328 digit.currentNum = digit.nextNum;
329 digit.topNumFront.dom.innerHTML = digit.currentNum;
330 digit.topFrontDiv.attr('style', '');
331 digit.bottomNumBack.dom.innerHTML = digit.currentNum;
334 digit.manager.fireEvent('onFlip', digit.manager);
338 'motion' // desplay type.
341 }).defer(delay + this.manager.speed, this);
345 //??? digit.bottomFrontDiv. digit.bottomNumFront.html(digit.nextNum);