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 = ""+ this.startnumber;
58 for (i=startNum.length-1; i>=0; i=i-1)
60 if (startNum[i] == '.') {
61 this.addSeparator('.');
63 this.addDigit(startNum[i]);
65 this.currentNumber = this.startnumber;
68 addDigit : function (num)
70 // Add separator after every 3rd digit
71 /*if (this.digits.length % 3 == 0 && this.digits.length != 0)
73 this.addSeparator(',');
78 var digit = new Roo.ux.FlipCounter.Digit({ manager : this, currentNumber : num });
80 this.digits.push(digit);
81 digit.render(this.el, 0);
84 this.ulWidth = this.ulWidth + digit.el.getWidth(true);
86 'min-width' : this.ulWidth,
87 'min-height' :digit.el.getHeight(true)
92 removeDigit : function ()
94 var digit = this.digits.splice(this.digits.length-1, 1)[0];
96 this.ulWidth = this.ulWidth - digit.el.getWidth(true);
100 if (this.digits.length % 3 == 0)
102 var comma = this.el.select('li.comma:first-child');
103 this.ulWidth = this.ulWidth - comma.getWidth(true);
107 // Update width to current
108 this.el.set( { 'min-width' : this.ulWidth});
111 addSeparator : function (num)
113 var comma = this.el.insertHtml('afterBegin','<li class="comma">,</li>',true);
117 this.ulWidth = this.ulWidth + comma.getWidth(true);
118 this.el.set({'min-width' : this.ulWidth});
121 updateTo : function (num)
123 var numStr = parseInt(num).toString();
125 this.currentNumber = num;
126 // Change the number of digits displayed if needed
127 if (numStr.length != this.digits.length)
129 var diff = numStr.length - this.digits.length;
132 for (i=0; i<diff; i=i+1) {
138 for (i=diff; i<0; i=i+1) {
143 this.fireEvent('onResize',this);
146 // Change all digit values
147 for (i=0; i<numStr.length; i=i+1)
149 this.digits[i].flipTo(numStr[numStr.length - 1 - i]);
155 Roo.ux.FlipCounter.Digit = function(options)
157 //Roo.apply(this, options);
158 Roo.ux.FlipCounter.Digit.superclass.constructor.call(this, options);
161 this.currentNumber = parseInt(this.currentNumber);
166 Roo.extend(Roo.ux.FlipCounter.Digit, Roo.bootstrap.Component, {
168 manager : null, // the flipcounter...
177 bottomFrontDiv : null,
180 bottomNumBack : null,
181 bottomNumFront : null,
186 getAutoCreate : function(){
194 { cls : 'flipper_top flipper_top1' },
196 cls : 'flipper_top flipper_top2 flipper_top_back',
198 { tag: 'span', html: this.currentNumber },
204 cls : 'flipper_top flipper_top_front',
206 { tag: 'span', html: this.currentNumber },
211 { cls : 'flipper_bottom flipper_bottom4' },
212 { cls : 'flipper_bottom flipper_bottom3' },
213 { cls : 'flipper_bottom flipper_bottom2' },
215 cls : 'flipper_bottom flipper_bottom1 flipper_bottom_back',
217 { tag: 'span', html: this.currentNumber },
222 cls : 'flipper_bottom flipper_bottom_front',
224 { tag: 'span', html: this.currentNumber },
235 initEvents : function()
240 this.topFrontDiv = this.el.select('.flipper_top_front',true).first();
241 this.bottomFrontDiv = this.el.select('.flipper_bottom_front',true).first();
242 this.topNumBack = this.el.select('.flipper_top_back span',true).first();
243 this.topNumFront = this.el.select('.flipper_top_front span',true).first();
244 this.bottomNumBack = this.el.select('.flipper_bottom_back span',true).first();
245 this.bottomNumFront = this.el.select('.flipper_bottom_front span',true).first();
247 this.targetNum = this.currentNumber;
248 this.currentNum = this.currentNumber;
249 this.nextNum = this.currentNumber;
251 this.currentlyAnimating = false;
254 flipTo : function (num)
256 if (this.currentNum === num)
259 this.targetNum = num;
260 if (this.currentlyAnimating) {
267 animNext : function ()
269 if (this.currentNum == this.targetNum)
271 this.currentlyAnimating = false;
275 var doRandomDelay = !this.currentlyAnimating;
276 this.currentlyAnimating = true;
277 this.nextNum = this.currentNum + 1;
278 if (this.nextNum > 9) {
282 var delay = Math.random()/5;
283 if (!doRandomDelay) {
287 // Animate top flipper
289 digit.topNumBack.dom.innerHTML = digit.nextNum;
291 digit.topFrontDiv.animate(
293 scaleY: {from :1, to : 0}
295 this.manager.speed, //duration
296 function() {}, // oncomplate
298 'motion' // desplay type.
300 }).defer(delay, this);
304 digit.bottomNumFront.dom.innerHTML = digit.nextNum;
306 digit.bottomFrontDiv.animate(
308 scaleY: {from: 0, to : 1},
311 this.manager.speed * 0.5, //duration
313 digit.currentNum = digit.nextNum;
314 digit.topNumFront.dom.innerHTML = digit.currentNum;
315 digit.topFrontDiv.attr('style', '');
316 digit.bottomNumBack.dom.innerHTML = digit.currentNum;
319 digit.manager.fireEvent('onFlip', digit.manager);
323 'motion' // desplay type.
326 }).defer(delay + this.manager.speed, this);
330 //??? digit.bottomFrontDiv. digit.bottomNumFront.html(digit.nextNum);