(function($) { /** * Daily Counter Clock Face * * This class will generate a daily counter for FlipClock.js. A * daily counter will track days, hours, minutes, and seconds. If * the number of available digits is exceeded in the count, a new * digit will be created. * * @param object The parent FlipClock.Factory object * @param object An object of properties to override the default */ FlipClock.DailyCounterExFace = FlipClock.Face.extend({ /** * Constructor * * @param object The parent FlipClock.Factory object * @param object An object of properties to override the default */ constructor: function(factory, options) { factory.countdown = false; this.base(factory, options); }, digitize: function(obj) { var data = []; $.each(obj, function(i, value) { value = value.toString(); if(value.length == 1) { value = '0'+value; } for(var x = 0; x < value.length; x++) { data.push(value.charAt(x)); } }); if(data.length > this.minimumDigits) { this.minimumDigits = data.length; } if(this.minimumDigits > data.length) { for(var x = data.length; x < this.minimumDigits; x++) { data.unshift('0'); } } return data; }, getCustomTime: function() { var date = new Date(); var obj = this.digitize([ date.getHours(), date.getMinutes() ]); return obj; }, /** * Build the clock face * * @param object Pass the time that should be used to display on the clock. */ build: function(time) { var t = this; var children = this.factory.$wrapper.find('ul'); time = time ? time : (this.factory.time.time || this.getCustomTime()); if(time.length > children.length) { $.each(time, function(i, digit) { t.factory.lists.push(t.createList(digit)); }); } this.dividers.push(this.createDivider()); this.dividers.push(this.createDivider()); $(this.dividers[0]).insertBefore(this.factory.lists[this.factory.lists.length - 2].$obj); $(this.dividers[1]).insertBefore(this.factory.lists[this.factory.lists.length - 4].$obj); this._clearExcessDigits(); if(this.autoStart) { this.start(); } }, /** * Flip the clock face */ flip: function(time, doNotAddPlayClass) { time = time ? time : this.getCustomTime(); this.base(time, doNotAddPlayClass); }, /** * Clear the excess digits from the tens columns for sec/min */ _clearExcessDigits: function() { var tenSeconds = this.factory.lists[this.factory.lists.length - 2]; var tenMinutes = this.factory.lists[this.factory.lists.length - 4]; for(var x = 6; x < 10; x++) { tenSeconds.$obj.find('li:last-child').remove(); tenMinutes.$obj.find('li:last-child').remove(); } } }); }(jQuery));