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, {
40 digits : false, // array...
44 getAutoCreate : function(){
48 cls: 'flipcounter ' + this.cls,
53 initEvents : function ()
55 var startNum = ""+ this.startnumber;
57 for (i=startNum.length-1; i>=0; i=i-1)
59 this.addDigit(startNum[i]);
61 this.currentNumber = this.startnumber;
64 addDigit : function (num)
66 // Add separator after every 3rd digit
67 if (this.digits.length % 3 == 0 && this.digits.length != 0)
74 var digit = new Roo.ux.FlipCounter.Digit({ manager : this, currentNumber : num });
76 this.digits.push(digit);
77 digit.render(this.el, 0);
80 this.ulWidth = this.ulWidth + digit.el.getWidth(true);
82 'min-width' : this.ulWidth,
83 'min-height' :digit.el.getHeight(true)
88 removeDigit : function ()
90 var digit = this.digits.splice(this.digits.length-1, 1)[0];
92 this.ulWidth = this.ulWidth - digit.el.getWidth(true);
96 if (this.digits.length % 3 == 0)
98 var comma = this.el.select('li.comma:first-child');
99 this.ulWidth = this.ulWidth - comma.getWidth(true);
103 // Update width to current
104 this.el.set( { 'min-width' : this.ulWidth});
107 addSeparator : function (num)
109 var comma = this.el.insertHtml('afterBegin','<li class="comma">,</li>',true);
113 this.ulWidth = this.ulWidth + comma.getWidth(true);
114 this.el.set({'min-width' : this.ulWidth});
117 updateTo : function (num)
119 var numStr = parseInt(num).toString();
121 this.currentNumber = num;
122 // Change the number of digits displayed if needed
123 if (numStr.length != this.digits.length)
125 var diff = numStr.length - this.digits.length;
128 for (i=0; i<diff; i=i+1) {
134 for (i=diff; i<0; i=i+1) {
139 this.fireEvent('onResize',this);
142 // Change all digit values
143 for (i=0; i<numStr.length; i=i+1)
145 this.digits[i].flipTo(numStr[numStr.length - 1 - i]);
151 Roo.ux.FlipCounter.Digit = function(options)
153 //Roo.apply(this, options);
154 Roo.ux.FlipCounter.Digit.superclass.constructor.call(this, options);
157 this.currentNumber = parseInt(this.currentNumber);
162 Roo.extend(Roo.ux.FlipCounter.Digit, Roo.bootstrap.Component, {
164 manager : null, // the flipcounter...
173 bottomFrontDiv : null,
176 bottomNumBack : null,
177 bottomNumFront : null,
182 getAutoCreate : function(){
190 { cls : 'flipper_top flipper_top1' },
192 cls : 'flipper_top flipper_top2 flipper_top_back',
194 { tag: 'span', html: this.currentNumber },
200 cls : 'flipper_top flipper_top_front',
202 { tag: 'span', html: this.currentNumber },
207 { cls : 'flipper_bottom flipper_bottom4' },
208 { cls : 'flipper_bottom flipper_bottom3' },
209 { cls : 'flipper_bottom flipper_bottom2' },
211 cls : 'flipper_bottom flipper_bottom1 flipper_bottom_back',
213 { tag: 'span', html: this.currentNumber },
218 cls : 'flipper_bottom flipper_bottom_front',
220 { tag: 'span', html: this.currentNumber },
231 initEvents : function()
236 this.topFrontDiv = this.el.select('.flipper_top_front',true).first();
237 this.bottomFrontDiv = this.el.select('.flipper_bottom_front',true).first();
238 this.topNumBack = this.el.select('.flipper_top_back span',true).first();
239 this.topNumFront = this.el.select('.flipper_top_front span',true).first();
240 this.bottomNumBack = this.el.select('.flipper_bottom_back span',true).first();
241 this.bottomNumFront = this.el.select('.flipper_bottom_front span',true).first();
243 this.targetNum = this.currentNumber;
244 this.currentNum = this.currentNumber;
245 this.nextNum = this.currentNumber;
247 this.currentlyAnimating = false;
250 flipTo : function (num)
252 if (this.currentNum === num)
255 this.targetNum = num;
256 if (this.currentlyAnimating) {
263 animNext : function ()
265 if (this.currentNum == this.targetNum)
267 this.currentlyAnimating = false;
271 var doRandomDelay = !this.currentlyAnimating;
272 this.currentlyAnimating = true;
273 this.nextNum = this.currentNum + 1;
274 if (this.nextNum > 9) {
278 var delay = Math.random()/5;
279 if (!doRandomDelay) {
283 // Animate top flipper
285 digit.topNumBack.dom.innerHTML = digit.nextNum;
287 digit.topFrontDiv.animate(
289 scaleY: {from :1, to : 0}
291 this.manager.speed, //duration
292 function() {}, // oncomplate
294 'motion' // desplay type.
296 }).defer(delay, this);
300 digit.bottomNumFront.dom.innerHTML = digit.nextNum;
302 digit.bottomFrontDiv.animate(
304 scaleY: {from: 0, to : 1},
307 this.manager.speed * 0.5, //duration
309 digit.currentNum = digit.nextNum;
310 digit.topNumFront.dom.innerHTML = digit.currentNum;
311 digit.topFrontDiv.attr('style', '');
312 digit.bottomNumBack.dom.innerHTML = digit.currentNum;
315 digit.manager.fireEvent('onFlip', digit.manager);
319 'motion' // desplay type.
322 }).defer(delay + this.manager.speed, this);
326 //??? digit.bottomFrontDiv. digit.bottomNumFront.html(digit.nextNum);