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 this.addDigit(startNum[i]);
62 this.currentNumber = this.startnumber;
65 addDigit : function (num)
67 // Add separator after every 3rd digit
68 /*if (this.digits.length % 3 == 0 && this.digits.length != 0)
70 this.addSeparator(',');
74 if (this.digits.length % 3 == 0 && this.digits.length != 0)
80 var digit = new Roo.ux.FlipCounter.Digit({ manager : this, currentNumber : num });
82 this.digits.push(digit);
83 digit.render(this.el, 0);
86 this.ulWidth = this.ulWidth + digit.el.getWidth(true);
88 'min-width' : this.ulWidth,
89 'min-height' :digit.el.getHeight(true)
94 removeDigit : function ()
96 var digit = this.digits.splice(this.digits.length-1, 1)[0];
98 this.ulWidth = this.ulWidth - digit.el.getWidth(true);
102 if (this.digits.length % 3 == 0)
104 var comma = this.el.select('li.comma:first-child');
105 this.ulWidth = this.ulWidth - comma.getWidth(true);
109 // Update width to current
110 this.el.set( { 'min-width' : this.ulWidth});
113 addSeparator : function (num)
115 var comma = this.el.insertHtml('afterBegin','<li class="comma">,</li>',true);
119 this.ulWidth = this.ulWidth + comma.getWidth(true);
120 this.el.set({'min-width' : this.ulWidth});
123 updateTo : function (num)
125 var numStr = parseInt(num).toString();
127 this.currentNumber = num;
128 // Change the number of digits displayed if needed
129 if (numStr.length != this.digits.length)
131 var diff = numStr.length - this.digits.length;
134 for (i=0; i<diff; i=i+1) {
140 for (i=diff; i<0; i=i+1) {
145 this.fireEvent('onResize',this);
148 // Change all digit values
149 for (i=0; i<numStr.length; i=i+1)
151 this.digits[i].flipTo(numStr[numStr.length - 1 - i]);
157 Roo.ux.FlipCounter.Digit = function(options)
159 //Roo.apply(this, options);
160 Roo.ux.FlipCounter.Digit.superclass.constructor.call(this, options);
163 this.currentNumber = parseInt(this.currentNumber);
168 Roo.extend(Roo.ux.FlipCounter.Digit, Roo.bootstrap.Component, {
170 manager : null, // the flipcounter...
179 bottomFrontDiv : null,
182 bottomNumBack : null,
183 bottomNumFront : null,
188 getAutoCreate : function(){
196 { cls : 'flipper_top flipper_top1' },
198 cls : 'flipper_top flipper_top2 flipper_top_back',
200 { tag: 'span', html: this.currentNumber },
206 cls : 'flipper_top flipper_top_front',
208 { tag: 'span', html: this.currentNumber },
213 { cls : 'flipper_bottom flipper_bottom4' },
214 { cls : 'flipper_bottom flipper_bottom3' },
215 { cls : 'flipper_bottom flipper_bottom2' },
217 cls : 'flipper_bottom flipper_bottom1 flipper_bottom_back',
219 { tag: 'span', html: this.currentNumber },
224 cls : 'flipper_bottom flipper_bottom_front',
226 { tag: 'span', html: this.currentNumber },
237 initEvents : function()
242 this.topFrontDiv = this.el.select('.flipper_top_front',true).first();
243 this.bottomFrontDiv = this.el.select('.flipper_bottom_front',true).first();
244 this.topNumBack = this.el.select('.flipper_top_back span',true).first();
245 this.topNumFront = this.el.select('.flipper_top_front span',true).first();
246 this.bottomNumBack = this.el.select('.flipper_bottom_back span',true).first();
247 this.bottomNumFront = this.el.select('.flipper_bottom_front span',true).first();
249 this.targetNum = this.currentNumber;
250 this.currentNum = this.currentNumber;
251 this.nextNum = this.currentNumber;
253 this.currentlyAnimating = false;
256 flipTo : function (num)
258 if (this.currentNum === num)
261 this.targetNum = num;
262 if (this.currentlyAnimating) {
269 animNext : function ()
271 if (this.currentNum == this.targetNum)
273 this.currentlyAnimating = false;
277 var doRandomDelay = !this.currentlyAnimating;
278 this.currentlyAnimating = true;
279 this.nextNum = this.currentNum + 1;
280 if (this.nextNum > 9) {
284 var delay = Math.random()/5;
285 if (!doRandomDelay) {
289 // Animate top flipper
291 digit.topNumBack.dom.innerHTML = digit.nextNum;
293 digit.topFrontDiv.animate(
295 scaleY: {from :1, to : 0}
297 this.manager.speed, //duration
298 function() {}, // oncomplate
300 'motion' // desplay type.
302 }).defer(delay, this);
306 digit.bottomNumFront.dom.innerHTML = digit.nextNum;
308 digit.bottomFrontDiv.animate(
310 scaleY: {from: 0, to : 1},
313 this.manager.speed * 0.5, //duration
315 digit.currentNum = digit.nextNum;
316 digit.topNumFront.dom.innerHTML = digit.currentNum;
317 digit.topFrontDiv.attr('style', '');
318 digit.bottomNumBack.dom.innerHTML = digit.currentNum;
321 digit.manager.fireEvent('onFlip', digit.manager);
325 'motion' // desplay type.
328 }).defer(delay + this.manager.speed, this);
332 //??? digit.bottomFrontDiv. digit.bottomNumFront.html(digit.nextNum);