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, {
39 digits : false, // array...
43 getAutoCreate : function(){
47 cls: 'flipcounter ' + this.cls,
52 initEvents : function ()
54 var startNum = ""+ this.startnumber;
56 for (i=startNum.length-1; i>=0; i=i-1)
58 this.addDigit(startNum[i]);
62 addDigit : function (num)
64 // Add separator after every 3rd digit
65 if (this.digits.length % 3 == 0 && this.digits.length != 0)
73 var digit = new Roo.ux.FlipCounter.Digit({ manager : this, currentNumber : num });
75 this.digits.push(digit);
76 digit.render(this.el, 0);
79 this.ulWidth = this.ulWidth + digit.el.getWidth(true);
81 'min-width' : this.ulWidth,
82 'min-height' :digit.el.getHeight(true)
87 removeDigit : function ()
89 var digit = this.digits.splice(this.digits.length-1, 1)[0];
91 this.ulWidth = this.ulWidth - digit.el.getWidth(true);
95 if (this.digits.length % 3 == 0)
97 var comma = this.el.select('li.comma:first-child');
98 this.ulWidth = this.ulWidth - comma.getWidth(true);
102 // Update width to current
103 this.el.set( { 'min-width' : this.ulWidth});
106 addSeparator : function (num)
108 var comma = this.el.insertHtml('afterBegin','<li class="comma">,</li>',true);
112 this.ulWidth = this.ulWidth + comma.getWidth(true);
113 this.el.set({'min-width' : this.ulWidth});
116 updateTo : function (num)
118 var numStr = parseInt(num).toString();
120 // Change the number of digits displayed if needed
121 if (numStr.length != this.digits.length)
123 var diff = numStr.length - this.digits.length;
126 for (i=0; i<diff; i=i+1) {
132 for (i=diff; i<0; i=i+1) {
137 this.fireEvent('onResize',this);
140 // Change all digit values
141 for (i=0; i<numStr.length; i=i+1)
143 this.digits[i].flipTo(numStr[numStr.length - 1 - i]);
149 Roo.ux.FlipCounter.Digit = function(options)
151 //Roo.apply(this, options);
152 Roo.ux.FlipCounter.Digit.superclass.constructor.call(this, options);
155 this.currentNumber = parseInt(this.currentNumber);
160 Roo.extend(Roo.ux.FlipCounter.Digit, Roo.bootstrap.Component, {
162 manager : null, // the flipcounter...
171 bottomFrontDiv : null,
174 bottomNumBack : null,
175 bottomNumFront : null,
180 getAutoCreate : function(){
188 { cls : 'flipper_top flipper_top1' },
190 cls : 'flipper_top flipper_top2 flipper_top_back',
192 { tag: 'span', html: this.currentNumber },
198 cls : 'flipper_top flipper_top_front',
200 { tag: 'span', html: this.currentNumber },
205 { cls : 'flipper_bottom flipper_bottom4' },
206 { cls : 'flipper_bottom flipper_bottom3' },
207 { cls : 'flipper_bottom flipper_bottom2' },
209 cls : 'flipper_bottom flipper_bottom1 flipper_bottom_back',
211 { tag: 'span', html: this.currentNumber },
216 cls : 'flipper_bottom flipper_bottom_front',
218 { tag: 'span', html: this.currentNumber },
229 initEvents : function()
234 this.topFrontDiv = this.el.select('.flipper_top_front',true).first();
235 this.bottomFrontDiv = this.el.select('.flipper_bottom_front',true).first();
236 this.topNumBack = this.el.select('.flipper_top_back span',true).first();
237 this.topNumFront = this.el.select('.flipper_top_front span',true).first();
238 this.bottomNumBack = this.el.select('.flipper_bottom_back span',true).first();
239 this.bottomNumFront = this.el.select('.flipper_bottom_front span',true).first();
241 this.targetNum = this.currentNumber;
242 this.currentNum = this.currentNumber;
243 this.nextNum = this.currentNumber;
245 this.currentlyAnimating = false;
248 flipTo : function (num)
250 if (this.currentNum === num)
253 this.targetNum = num;
254 if (this.currentlyAnimating) {
261 animNext : function ()
263 if (this.currentNum == this.targetNum)
265 this.currentlyAnimating = false;
269 var doRandomDelay = !this.currentlyAnimating;
270 this.currentlyAnimating = true;
271 this.nextNum = this.currentNum + 1;
272 if (this.nextNum > 9) {
276 var delay = Math.random()/5;
277 if (!doRandomDelay) {
281 // Animate top flipper
283 digit.topNumBack.dom.innerHTML = digit.nextNum;
285 digit.topFrontDiv.animate(
287 scaleY: {from :1, to : 0}
289 this.manager.speed, //duration
290 function() {}, // oncomplate
292 'motion' // desplay type.
294 }).defer(delay, this);
298 digit.bottomNumFront.dom.innerHTML = digit.nextNum;
300 digit.bottomFrontDiv.animate(
302 scaleY: {from: 0, to : 1},
305 this.manager.speed * 0.5, //duration
307 digit.currentNum = digit.nextNum;
308 digit.topNumFront.dom.innerHTML = digit.currentNum;
309 digit.topFrontDiv.attr('style', '');
310 digit.bottomNumBack.dom.innerHTML = digit.currentNum;
313 digit.manager.fireEvent('onFlip', digit.manager);
317 'motion' // desplay type.
320 }).defer(delay + this.manager.speed, this);
324 //??? digit.bottomFrontDiv. digit.bottomNumFront.html(digit.nextNum);