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 = (1.0*this.startnumber).toFixed(this.decimal);
58 for (i=startNum.length-1; i>=0; i=i-1)
60 if (startNum[i] == '.') {
61 this.addSeparator('.');
64 this.addDigit(startNum[i]);
66 this.currentNumber = this.startnumber;
69 addDigit : function (num)
71 // Add separator after every 3rd digit
72 /*if (this.digits.length % 3 == 0 && this.digits.length != 0)
74 this.addSeparator(',');
79 var digit = new Roo.ux.FlipCounter.Digit({ manager : this, currentNumber : num });
81 this.digits.push(digit);
82 digit.render(this.el, 0);
85 this.ulWidth = this.ulWidth + digit.el.getWidth(true);
87 'min-width' : this.ulWidth,
88 'min-height' :digit.el.getHeight(true)
93 removeDigit : function ()
95 var digit = this.digits.splice(this.digits.length-1, 1)[0];
97 this.ulWidth = this.ulWidth - digit.el.getWidth(true);
101 // if (this.digits.length % 3 == 0)
103 // var comma = this.el.select('li.comma:first-child');
104 // this.ulWidth = this.ulWidth - comma.getWidth(true);
108 // Update width to current
109 this.el.set( { 'min-width' : this.ulWidth});
112 addSeparator : function (str)
114 var comma = this.el.insertHtml('afterBegin','<li class="comma">'+str+'</li>',true);
118 this.ulWidth = this.ulWidth + comma.getWidth(true);
119 this.el.set({'min-width' : this.ulWidth});
122 updateTo : function (num)
124 var numStr = (1.0*num).toFixed(this.decimal);
126 this.currentNumber = num;
128 var dl = this.digits.length + (this.decimal > 0 ? 1 : 0);
129 // Change the number of digits displayed if needed
130 if (numStr.length != this.digits.length)
132 var diff = numStr.length - this.digits.length;
133 Roo.log("DIFF LEN=" +diff);
136 for (i=0; i<diff; i=i+1) {
142 for (i=diff; i<0; i=i+1) {
147 this.fireEvent('onResize',this);
150 // Change all digit values
151 for (i=0; i<numStr.length; i=i+1)
153 if (numStr[numStr.length - 1 - i] == '.') {
156 Roo.log("UPDATE DIGIT=" + i + " to " + numStr[numStr.length - 1 - i]);
157 this.digits[i].flipTo(numStr[numStr.length - 1 - i]);
163 Roo.ux.FlipCounter.Digit = function(options)
165 //Roo.apply(this, options);
166 Roo.ux.FlipCounter.Digit.superclass.constructor.call(this, options);
169 this.currentNumber = parseInt(this.currentNumber);
174 Roo.extend(Roo.ux.FlipCounter.Digit, Roo.bootstrap.Component, {
176 manager : null, // the flipcounter...
185 bottomFrontDiv : null,
188 bottomNumBack : null,
189 bottomNumFront : null,
194 getAutoCreate : function(){
202 { cls : 'flipper_top flipper_top1' },
204 cls : 'flipper_top flipper_top2 flipper_top_back',
206 { tag: 'span', html: this.currentNumber },
212 cls : 'flipper_top flipper_top_front',
214 { tag: 'span', html: this.currentNumber },
219 { cls : 'flipper_bottom flipper_bottom4' },
220 { cls : 'flipper_bottom flipper_bottom3' },
221 { cls : 'flipper_bottom flipper_bottom2' },
223 cls : 'flipper_bottom flipper_bottom1 flipper_bottom_back',
225 { tag: 'span', html: this.currentNumber },
230 cls : 'flipper_bottom flipper_bottom_front',
232 { tag: 'span', html: this.currentNumber },
243 initEvents : function()
248 this.topFrontDiv = this.el.select('.flipper_top_front',true).first();
249 this.bottomFrontDiv = this.el.select('.flipper_bottom_front',true).first();
250 this.topNumBack = this.el.select('.flipper_top_back span',true).first();
251 this.topNumFront = this.el.select('.flipper_top_front span',true).first();
252 this.bottomNumBack = this.el.select('.flipper_bottom_back span',true).first();
253 this.bottomNumFront = this.el.select('.flipper_bottom_front span',true).first();
255 this.targetNum = this.currentNumber;
256 this.currentNum = this.currentNumber;
257 this.nextNum = this.currentNumber;
259 this.currentlyAnimating = false;
262 flipTo : function (num)
264 if (this.currentNum === num)
267 this.targetNum = num;
268 if (this.currentlyAnimating) {
275 animNext : function ()
277 if (this.currentNum == this.targetNum)
279 this.currentlyAnimating = false;
283 var doRandomDelay = !this.currentlyAnimating;
284 this.currentlyAnimating = true;
285 this.nextNum = this.currentNum + 1;
286 if (this.nextNum > 9) {
290 var delay = Math.random()/5;
291 if (!doRandomDelay) {
295 // Animate top flipper
297 digit.topNumBack.dom.innerHTML = digit.nextNum;
299 digit.topFrontDiv.animate(
301 scaleY: {from :1, to : 0}
303 this.manager.speed, //duration
304 function() {}, // oncomplate
306 'motion' // desplay type.
308 }).defer(delay, this);
312 digit.bottomNumFront.dom.innerHTML = digit.nextNum;
314 digit.bottomFrontDiv.animate(
316 scaleY: {from: 0, to : 1},
319 this.manager.speed * 0.5, //duration
321 digit.currentNum = digit.nextNum;
322 digit.topNumFront.dom.innerHTML = digit.currentNum;
323 digit.topFrontDiv.attr('style', '');
324 digit.bottomNumBack.dom.innerHTML = digit.currentNum;
327 digit.manager.fireEvent('onFlip', digit.manager);
331 'motion' // desplay type.
334 }).defer(delay + this.manager.speed, this);
338 //??? digit.bottomFrontDiv. digit.bottomNumFront.html(digit.nextNum);