(function() { var count_framerate, count_ms_per_frame, digit_format, digit_html, digit_speedboost, duration, format_mark_html, format_parser, framerate, frames_per_value, ms_per_frame, mutationobserver, odometer, ribbon_html, transition_end_events, transition_support, value_html, addclass, createfromhtml, fractionalpart, now, removeclass, requestanimationframe, round, transitioncheckstyles, trigger, truncate, wrapjquery, _jquerywrapped, _old, _ref, _ref1, __slice = [].slice; value_html = ''; ribbon_html = '' + value_html + ''; digit_html = '8' + ribbon_html + ''; format_mark_html = ''; digit_format = '(,ddd).dd'; format_parser = /^\(?([^)]*)\)?(?:(.)(d+))?$/; framerate = 30; duration = 2000; count_framerate = 20; frames_per_value = 2; digit_speedboost = .5; ms_per_frame = 1000 / framerate; count_ms_per_frame = 1000 / count_framerate; transition_end_events = 'transitionend webkittransitionend otransitionend otransitionend mstransitionend'; transitioncheckstyles = document.createelement('div').style; transition_support = (transitioncheckstyles.transition != null) || (transitioncheckstyles.webkittransition != null) || (transitioncheckstyles.moztransition != null) || (transitioncheckstyles.otransition != null); requestanimationframe = window.requestanimationframe || window.mozrequestanimationframe || window.webkitrequestanimationframe || window.msrequestanimationframe; mutationobserver = window.mutationobserver || window.webkitmutationobserver || window.mozmutationobserver; createfromhtml = function(html) { var el; el = document.createelement('div'); el.innerhtml = html; return el.children[0]; }; removeclass = function(el, name) { return el.classname = el.classname.replace(new regexp("(^| )" + (name.split(' ').join('|')) + "( |$)", 'gi'), ' '); }; addclass = function(el, name) { removeclass(el, name); return el.classname += " " + name; }; trigger = function(el, name) { var evt; if (document.createevent != null) { evt = document.createevent('htmlevents'); evt.initevent(name, true, true); return el.dispatchevent(evt); } }; now = function() { var _ref, _ref1; return (_ref = (_ref1 = window.performance) != null ? typeof _ref1.now === "function" ? _ref1.now() : void 0 : void 0) != null ? _ref : +(new date); }; round = function(val, precision) { if (precision == null) { precision = 0; } if (!precision) { return math.round(val); } val *= math.pow(10, precision); val += 0.5; val = math.floor(val); return val /= math.pow(10, precision); }; truncate = function(val) { if (val < 0) { return math.ceil(val); } else { return math.floor(val); } }; fractionalpart = function(val) { return val - round(val); }; _jquerywrapped = false; (wrapjquery = function() { var property, _i, _len, _ref, _results; if (_jquerywrapped) { return; } if (window.jquery != null) { _jquerywrapped = true; _ref = ['html', 'text']; _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { property = _ref[_i]; _results.push((function(property) { var old; old = window.jquery.fn[property]; return window.jquery.fn[property] = function(val) { var _ref1; if ((val == null) || (((_ref1 = this[0]) != null ? _ref1.odometer : void 0) == null)) { return old.apply(this, arguments); } return this[0].odometer.update(val); }; })(property)); } return _results; } })(); settimeout(wrapjquery, 0); odometer = (function() { function odometer(options) { var e, k, property, v, _base, _i, _len, _ref, _ref1, _ref2, _this = this; this.options = options; this.el = this.options.el; if (this.el.odometer != null) { return this.el.odometer; } this.el.odometer = this; _ref = odometer.options; for (k in _ref) { v = _ref[k]; if (this.options[k] == null) { this.options[k] = v; } } if ((_base = this.options).duration == null) { _base.duration = duration; } this.max_values = ((this.options.duration / ms_per_frame) / frames_per_value) | 0; this.resetformat(); this.value = this.cleanvalue((_ref1 = this.options.value) != null ? _ref1 : ''); this.renderinside(); this.render(); try { _ref2 = ['innerhtml', 'innertext', 'textcontent']; for (_i = 0, _len = _ref2.length; _i < _len; _i++) { property = _ref2[_i]; if (this.el[property] != null) { (function(property) { return object.defineproperty(_this.el, property, { get: function() { var _ref3; if (property === 'innerhtml') { return _this.inside.outerhtml; } else { return (_ref3 = _this.inside.innertext) != null ? _ref3 : _this.inside.textcontent; } }, set: function(val) { return _this.update(val); } }); })(property); } } } catch (_error) { e = _error; this.watchformutations(); } this; } odometer.prototype.renderinside = function() { this.inside = document.createelement('div'); this.inside.classname = 'odometer-inside'; this.el.innerhtml = ''; return this.el.appendchild(this.inside); }; odometer.prototype.watchformutations = function() { var e, _this = this; if (mutationobserver == null) { return; } try { if (this.observer == null) { this.observer = new mutationobserver(function(mutations) { var newval; newval = _this.el.innertext; _this.renderinside(); _this.render(_this.value); return _this.update(newval); }); } this.watchmutations = true; return this.startwatchingmutations(); } catch (_error) { e = _error; } }; odometer.prototype.startwatchingmutations = function() { if (this.watchmutations) { return this.observer.observe(this.el, { childlist: true }); } }; odometer.prototype.stopwatchingmutations = function() { var _ref; return (_ref = this.observer) != null ? _ref.disconnect() : void 0; }; odometer.prototype.cleanvalue = function(val) { var _ref; if (typeof val === 'string') { val = val.replace((_ref = this.format.radix) != null ? _ref : '.', ''); val = val.replace(/[.,]/g, ''); val = val.replace('', '.'); val = parsefloat(val, 10) || 0; } return round(val, this.format.precision); }; odometer.prototype.bindtransitionend = function() { var event, renderenqueued, _i, _len, _ref, _results, _this = this; if (this.transitionendbound) { return; } this.transitionendbound = true; renderenqueued = false; _ref = transition_end_events.split(' '); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { event = _ref[_i]; _results.push(this.el.addeventlistener(event, function() { if (renderenqueued) { return true; } renderenqueued = true; settimeout(function() { _this.render(); renderenqueued = false; return trigger(_this.el, 'odometerdone'); }, 0); return true; }, false)); } return _results; }; odometer.prototype.resetformat = function() { var format, fractional, parsed, precision, radix, repeating, _ref, _ref1; format = (_ref = this.options.format) != null ? _ref : digit_format; format || (format = 'd'); parsed = format_parser.exec(format); if (!parsed) { throw new error("odometer: unparsable digit format"); } _ref1 = parsed.slice(1, 4), repeating = _ref1[0], radix = _ref1[1], fractional = _ref1[2]; precision = (fractional != null ? fractional.length : void 0) || 0; return this.format = { repeating: repeating, radix: radix, precision: precision }; }; odometer.prototype.render = function(value) { var classes, cls, digit, match, newclasses, theme, wholepart, _i, _j, _len, _len1, _ref; if (value == null) { value = this.value; } this.stopwatchingmutations(); this.resetformat(); this.inside.innerhtml = ''; theme = this.options.theme; classes = this.el.classname.split(' '); newclasses = []; for (_i = 0, _len = classes.length; _i < _len; _i++) { cls = classes[_i]; if (!cls.length) { continue; } if (match = /^odometer-theme-(.+)$/.exec(cls)) { theme = match[1]; continue; } if (/^odometer(-|$)/.test(cls)) { continue; } newclasses.push(cls); } newclasses.push('odometer'); if (!transition_support) { newclasses.push('odometer-no-transitions'); } if (theme) { newclasses.push("odometer-theme-" + theme); } else { newclasses.push("odometer-auto-theme"); } this.el.classname = newclasses.join(' '); this.ribbons = {}; this.digits = []; wholepart = !this.format.precision || !fractionalpart(value) || false; _ref = value.tostring().split('').reverse(); for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) { digit = _ref[_j]; if (digit === '.') { wholepart = true; } this.adddigit(digit, wholepart); } return this.startwatchingmutations(); }; odometer.prototype.update = function(newvalue) { var diff, _this = this; newvalue = this.cleanvalue(newvalue); if (!(diff = newvalue - this.value)) { return; } removeclass(this.el, 'odometer-animating-up odometer-animating-down odometer-animating'); if (diff > 0) { addclass(this.el, 'odometer-animating-up'); } else { addclass(this.el, 'odometer-animating-down'); } this.stopwatchingmutations(); this.animate(newvalue); this.startwatchingmutations(); settimeout(function() { _this.el.offsetheight; return addclass(_this.el, 'odometer-animating'); }, 0); return this.value = newvalue; }; odometer.prototype.renderdigit = function() { return createfromhtml(digit_html); }; odometer.prototype.insertdigit = function(digit, before) { if (before != null) { return this.inside.insertbefore(digit, before); } else if (!this.inside.children.length) { return this.inside.appendchild(digit); } else { return this.inside.insertbefore(digit, this.inside.children[0]); } }; odometer.prototype.addspacer = function(chr, before, extraclasses) { var spacer; spacer = createfromhtml(format_mark_html); spacer.innerhtml = chr; if (extraclasses) { addclass(spacer, extraclasses); } return this.insertdigit(spacer, before); }; odometer.prototype.adddigit = function(value, repeating) { var chr, digit, resetted, _ref; if (repeating == null) { repeating = true; } if (value === '-') { return this.addspacer(value, null, 'odometer-negation-mark'); } if (value === '.') { return this.addspacer((_ref = this.format.radix) != null ? _ref : '.', null, 'odometer-radix-mark'); } if (repeating) { resetted = false; while (true) { if (!this.format.repeating.length) { if (resetted) { throw new error("bad odometer format without digits"); } this.resetformat(); resetted = true; } chr = this.format.repeating[this.format.repeating.length - 1]; this.format.repeating = this.format.repeating.substring(0, this.format.repeating.length - 1); if (chr === 'd') { break; } this.addspacer(chr); } } digit = this.renderdigit(); digit.queryselector('.odometer-value').innerhtml = value; this.digits.push(digit); return this.insertdigit(digit); }; odometer.prototype.animate = function(newvalue) { if (!transition_support || this.options.animation === 'count') { return this.animatecount(newvalue); } else { return this.animateslide(newvalue); } }; odometer.prototype.animatecount = function(newvalue) { var cur, diff, last, start, tick, _this = this; if (!(diff = +newvalue - this.value)) { return; } start = last = now(); cur = this.value; return (tick = function() { var delta, dist, fraction; if ((now() - start) > _this.options.duration) { _this.value = newvalue; _this.render(); trigger(_this.el, 'odometerdone'); return; } delta = now() - last; if (delta > count_ms_per_frame) { last = now(); fraction = delta / _this.options.duration; dist = diff * fraction; cur += dist; _this.render(math.round(cur)); } if (requestanimationframe != null) { return requestanimationframe(tick); } else { return settimeout(tick, count_ms_per_frame); } })(); }; odometer.prototype.getdigitcount = function() { var i, max, value, values, _i, _len; values = 1 <= arguments.length ? __slice.call(arguments, 0) : []; for (i = _i = 0, _len = values.length; _i < _len; i = ++_i) { value = values[i]; values[i] = math.abs(value); } max = math.max.apply(math, values); return math.ceil(math.log(max + 1) / math.log(10)); }; odometer.prototype.getfractionaldigitcount = function() { var i, parser, parts, value, values, _i, _len; values = 1 <= arguments.length ? __slice.call(arguments, 0) : []; parser = /^\-?\d*\.(\d*?)0*$/; for (i = _i = 0, _len = values.length; _i < _len; i = ++_i) { value = values[i]; values[i] = value.tostring(); parts = parser.exec(values[i]); if (parts == null) { values[i] = 0; } else { values[i] = parts[1].length; } } return math.max.apply(math, values); }; odometer.prototype.resetdigits = function() { this.digits = []; this.ribbons = []; this.inside.innerhtml = ''; return this.resetformat(); }; odometer.prototype.animateslide = function(newvalue) { var boosted, cur, diff, digitcount, digits, dist, end, fractionalcount, frame, frames, i, incr, j, mark, numel, oldvalue, start, _base, _i, _j, _k, _l, _len, _len1, _len2, _m, _ref, _results; oldvalue = this.value; fractionalcount = this.getfractionaldigitcount(oldvalue, newvalue); if (fractionalcount) { newvalue = newvalue * math.pow(10, fractionalcount); oldvalue = oldvalue * math.pow(10, fractionalcount); } if (!(diff = newvalue - oldvalue)) { return; } this.bindtransitionend(); digitcount = this.getdigitcount(oldvalue, newvalue); digits = []; boosted = 0; for (i = _i = 0; 0 <= digitcount ? _i < digitcount : _i > digitcount; i = 0 <= digitcount ? ++_i : --_i) { start = truncate(oldvalue / math.pow(10, digitcount - i - 1)); end = truncate(newvalue / math.pow(10, digitcount - i - 1)); dist = end - start; if (math.abs(dist) > this.max_values) { frames = []; incr = dist / (this.max_values + this.max_values * boosted * digit_speedboost); cur = start; while ((dist > 0 && cur < end) || (dist < 0 && cur > end)) { frames.push(math.round(cur)); cur += incr; } if (frames[frames.length - 1] !== end) { frames.push(end); } boosted++; } else { frames = (function() { _results = []; for (var _j = start; start <= end ? _j <= end : _j >= end; start <= end ? _j++ : _j--){ _results.push(_j); } return _results; }).apply(this); } for (i = _k = 0, _len = frames.length; _k < _len; i = ++_k) { frame = frames[i]; frames[i] = math.abs(frame % 10); } digits.push(frames); } this.resetdigits(); _ref = digits.reverse(); for (i = _l = 0, _len1 = _ref.length; _l < _len1; i = ++_l) { frames = _ref[i]; if (!this.digits[i]) { this.adddigit(' ', i >= fractionalcount); } if ((_base = this.ribbons)[i] == null) { _base[i] = this.digits[i].queryselector('.odometer-ribbon-inner'); } this.ribbons[i].innerhtml = ''; if (diff < 0) { frames = frames.reverse(); } for (j = _m = 0, _len2 = frames.length; _m < _len2; j = ++_m) { frame = frames[j]; numel = document.createelement('div'); numel.classname = 'odometer-value'; numel.innerhtml = frame; this.ribbons[i].appendchild(numel); if (j === frames.length - 1) { addclass(numel, 'odometer-last-value'); } if (j === 0) { addclass(numel, 'odometer-first-value'); } } } if (start < 0) { this.adddigit('-'); } mark = this.inside.queryselector('.odometer-radix-mark'); if (mark != null) { mark.parent.removechild(mark); } if (fractionalcount) { return this.addspacer(this.format.radix, this.digits[fractionalcount - 1], 'odometer-radix-mark'); } }; return odometer; })(); odometer.options = (_ref = window.odometeroptions) != null ? _ref : {}; settimeout(function() { var k, v, _base, _ref1, _results; if (window.odometeroptions) { _ref1 = window.odometeroptions; _results = []; for (k in _ref1) { v = _ref1[k]; _results.push((_base = odometer.options)[k] != null ? (_base = odometer.options)[k] : _base[k] = v); } return _results; } }, 0); odometer.init = function() { var el, elements, _i, _len, _ref1, _results; if (document.queryselectorall == null) { return; } elements = document.queryselectorall(odometer.options.selector || '.odometer'); _results = []; for (_i = 0, _len = elements.length; _i < _len; _i++) { el = elements[_i]; _results.push(el.odometer = new odometer({ el: el, value: (_ref1 = el.innertext) != null ? _ref1 : el.textcontent })); } return _results; }; if ((((_ref1 = document.documentelement) != null ? _ref1.doscroll : void 0) != null) && (document.createeventobject != null)) { _old = document.onreadystatechange; document.onreadystatechange = function() { if (document.readystate === 'complete' && odometer.options.auto !== false) { odometer.init(); } return _old != null ? _old.apply(this, arguments) : void 0; }; } else { document.addeventlistener('domcontentloaded', function() { if (odometer.options.auto !== false) { return odometer.init(); } }, false); } if (typeof define === 'function' && define.amd) { define(['jquery'], function() { return odometer; }); } else if (typeof exports === !'undefined') { module.exports = odometer; } else { window.odometer = odometer; } }).call(this);