3 Roo.ux.FlipCounter = function(options)
5 Roo.apply(this, options);
6 //this.el = $(element);
7 //this.options = $.extend({}, defaults, options);
12 * When a box is flipped
13 * @param {Roo.ux.FlipCounter} counter
18 * When a box is resized
19 * @param {Roo.ux.FlipCounter} counter
25 this.digits = new Array();
32 Roo.extend(Roo.ux.FlipCounter, Roo.bootstrap.Component, {
37 digits : false, // array...
40 getAutoCreate : function(){
49 initEvents : function ()
51 var startNum = ""+ this.startnumber;
53 for (i=startNum.length-1; i>=0; i=i-1)
55 this.addDigit(startNum[i]);
59 addDigit : function (num)
61 // Add separator after every 3rd digit
62 if (this.digits.length % 3 == 0 && this.digits.length != 0)
70 var digit = new Roo.ux.FlipCounter.Digit({ manager : this, currentNumber : num });
72 this.digits.push(digit);
73 digit.render(this.el);
76 this.ulWidth = this.ulWidth + digit.el.getWidth(true);
78 'min-width' : this.ulWidth,
79 'min-height' :digit.el.getHeight(true)
84 removeDigit : function ()
86 var digit = this.digits.splice(this.digits.length-1, 1)[0];
88 this.ulWidth = this.ulWidth - digit.el.outerWidth(true);
92 if (this.digits.length % 3 == 0)
94 var comma = this.el.select('li.comma:first-child');
95 this.ulWidth = this.ulWidth - comma.getWidth(true);
99 // Update width to current
100 this.el.set( { 'min-width' : this.ulWidth});
103 addSeparator : function (num)
105 var comma = this.el.insertHtml('afterBegin','<li class="comma">,</li>',true);
109 this.ulWidth = this.ulWidth + comma.getWidth(true);
110 this.el.set({'min-width' : this.ulWidth});
113 updateTo : function (num)
115 var numStr = parseInt(num).toString();
117 // Change the number of digits displayed if needed
118 if (numStr.length != this.digits.length)
120 var diff = numStr.length - this.digits.length;
123 for (i=0; i<diff; i=i+1) {
129 for (i=diff; i<0; i=i+1) {
134 this.fireEvent('onResize',this);
137 // Change all digit values
138 for (i=0; i<numStr.length; i=i+1)
140 this.digits[i].flipTo(numStr[numStr.length - 1 - i]);
146 Roo.ux.FlipCounter.Digit = function(options)
148 Roo.apply(this, options);
150 this.currentNumber = this.parseInt(this.currentNumber);
154 Roo.extend(Roo.ux.FlipCounter.Digit, Roo.bootstrap.Component, {
156 manager : null, // the flipcounter...
161 bottomFrontDiv : null,
164 bottomNumBack : null,
165 bottomNumFront : null,
168 getAutoCreate : function(){
176 { cls : 'flipper_top flipper_top1' },
178 cls : 'flipper_top flipper_top2 flipper_top_back',
180 { tag: 'span', html: num },
186 cls : 'flipper_top flipper_top_front',
188 { tag: 'span', html: num },
193 { cls : 'flipper_bottom flipper_bottom4' },
194 { cls : 'flipper_bottom flipper_bottom3' },
195 { cls : 'flipper_bottom flipper_bottom2' },
197 cls : 'flipper_bottom flipper_bottom1 flipper_bottom_back',
199 { tag: 'span', html: num },
204 cls : 'flipper_bottom flipper_bottom_front',
206 { tag: 'span', html: num },
217 initEvents : function()
222 this.topFrontDiv = this.el.select('.flipper_top_front',true);
223 this.bottomFrontDiv = this.el.select('.flipper_bottom_front',true);
224 this.topNumBack = this.el.select('.flipper_top_back span',true);
225 this.topNumFront = this.el.select('.flipper_top_front span',true);
226 this.bottomNumBack = this.el.select('.flipper_bottom_back span',true);
227 this.bottomNumFront = this.el.select('.flipper_bottom_front span',true);
229 this.targetNum = currentNumber;
230 this.currentNum = currentNumber;
231 this.nextNum = currentNumber;
233 this.currentlyAnimating = false;
236 flipTo : function (num)
238 if (this.currentNum === num)
241 this.targetNum = num;
242 if (this.currentlyAnimating) {
249 animNext : function ()
251 if (this.currentNum == this.targetNum)
253 this.currentlyAnimating = false;
257 var doRandomDelay = !this.currentlyAnimating;
258 this.currentlyAnimating = true;
259 this.nextNum = this.currentNum + 1;
260 if (this.nextNum > 9) {
264 var delay = Math.random()/5;
265 if (!doRandomDelay) {
269 // Animate top flipper
271 digit.topNumBack.html(digit.nextNum);
273 digit.topFrontDiv.animate(
275 scaleY: {from :1, to : 0}
277 this.manager.speed, //duration
278 function() {}, // oncomplate
280 'motion' // desplay type.
282 }).defer(delay, this);
286 digit.bottomNumFront.dom.innerHTML = digit.nextNum;
288 digit.bottomFrontDiv.animate(
290 scaleY: {from: 0, to : 1},
293 this.manager.options.speed * 0.5, //duration
295 digit.currentNum = digit.nextNum;
296 digit.topNumFront.dom.innerHTML = digit.currentNum;
297 digit.topFrontDiv.attr('style', '');
298 digit.bottomNumBack.dom.innerHTML = digit.currentNum;
301 digit.manager.fireEvent('onFlip', digit.manager);
305 'motion' // desplay type.
308 }).defer(delay + this.manager.speed, this);
312 //??? digit.bottomFrontDiv. digit.bottomNumFront.html(digit.nextNum);