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);
153 Roo.extend(Roo.ux.FlipCounter.Digit, Roo.bootstrap.Component, {
159 bottomFrontDiv : null,
162 bottomNumBack : null,
163 bottomNumFront : null,
166 getAutoCreate : function(){
174 { cls : 'flipper_top flipper_top1' },
176 cls : 'flipper_top flipper_top2 flipper_top_back',
178 { tag: 'span', html: num },
184 cls : 'flipper_top flipper_top_front',
186 { tag: 'span', html: num },
191 { cls : 'flipper_bottom flipper_bottom4' },
192 { cls : 'flipper_bottom flipper_bottom3' },
193 { cls : 'flipper_bottom flipper_bottom2' },
195 cls : 'flipper_bottom flipper_bottom1 flipper_bottom_back',
197 { tag: 'span', html: num },
202 cls : 'flipper_bottom flipper_bottom_front',
204 { tag: 'span', html: num },
215 initEvents : function()
220 this.topFrontDiv = this.el.select('.flipper_top_front',true);
221 this.bottomFrontDiv = this.el.select('.flipper_bottom_front',true);
222 this.topNumBack = this.el.select('.flipper_top_back span',true);
223 this.topNumFront = this.el.select('.flipper_top_front span',true);
224 this.bottomNumBack = this.el.select('.flipper_bottom_back span',true);
225 this.bottomNumFront = this.el.select('.flipper_bottom_front span',true);
227 this.targetNum = currentNumber;
228 this.currentNum = currentNumber;
229 this.nextNum = currentNumber;
231 this.currentlyAnimating = false;
234 flipTo : function (num)
236 if (this.currentNum === num)
239 this.targetNum = num;
240 if (this.currentlyAnimating) {
247 animNext : function ()
249 if (this.currentNum == this.targetNum)
251 this.currentlyAnimating = false;
255 var doRandomDelay = !this.currentlyAnimating;
256 this.currentlyAnimating = true;
257 this.nextNum = this.currentNum + 1;
258 if (this.nextNum > 9) {
262 var delay = Math.random()/5;
263 if (!doRandomDelay) {
267 // Animate top flipper
269 digit.topNumBack.html(digit.nextNum);
271 digit.topFrontDiv.animate(
273 scaleY: {from :1, to : 0}
275 this.manager.speed, //duration
276 function() {}, // oncomplate
278 'motion' // desplay type.
280 }).defer(delay, this);
284 digit.bottomNumFront.dom.innerHTML = digit.nextNum;
286 digit.bottomFrontDiv.animate(
288 scaleY: {from: 0, to : 1},
291 this.manager.options.speed * 0.5, //duration
293 digit.currentNum = digit.nextNum;
294 digit.topNumFront.dom.innerHTML = digit.currentNum;
295 digit.topFrontDiv.attr('style', '');
296 digit.bottomNumBack.dom.innerHTML = digit.currentNum;
299 digit.manager.fireEvent('onFlip', digit.manager);
303 'motion' // desplay type.
306 }).defer(delay + this.manager.speed, this);
310 //??? digit.bottomFrontDiv. digit.bottomNumFront.html(digit.nextNum);