From 29d9398b04ebc5590b17ce1eac233aef937c621f Mon Sep 17 00:00:00 2001 From: Jyrki Laurila Date: Wed, 28 May 2014 14:14:04 -0700 Subject: [PATCH] Updated distributables --- build/jquery.runner-min.js | 4 +- build/jquery.runner.coffee | 83 ++++++++++++------------- build/jquery.runner.js | 121 +++++++++++++++++++------------------ 3 files changed, 105 insertions(+), 103 deletions(-) diff --git a/build/jquery.runner-min.js b/build/jquery.runner-min.js index 58ede76..a68d3fd 100644 --- a/build/jquery.runner-min.js +++ b/build/jquery.runner-min.js @@ -1,6 +1,6 @@ /*! - * jQuery-runner - v2.3.1 - 2014-05-24 + * jQuery-runner - v2.3.2 - 2014-05-28 * https://github.com/jylauril/jquery-runner/ * Copyright (c) 2014 Jyrki Laurila */ -(function(){var a,b,c,d,e,f,g,h,i;if(c={version:"2.3.1",name:"jQuery-runner"},e={},d=function(a){return(10>a?"0":"")+a},i=1,f=function(){return"runner"+i++},h=function(a,b){return a["webkitR"+b]||a["r"+b]||a["mozR"+b]||a["msR"+b]||function(a){return setTimeout(a,30)}}(this,"equestAnimationFrame"),b=function(a,b){var c,e,f,g,h,i,j,k,l,m,n;for(b=b||{},k=[36e5,6e4,1e3,10],i=["",":",":","."],h="",g="",f=b.milliseconds,e=k.length,l=0,0>a&&(a=Math.abs(a),h="-"),c=m=0,n=k.length;n>m;c=++m)j=k[c],l=0,a>=j&&(l=Math.floor(a/j),a-=l*j),(l||c>1||g)&&(c!==e-1||f)&&(g+=(g?i[c]:"")+d(l));return h+g},a=function(){function a(b,c,d){var g;return this instanceof a?(this.items=b,g=this.id=f(),this.settings=$.extend({},this.settings,c),e[g]=this,b.each(function(a,b){$(b).data("runner",g)}),this.value(this.settings.startAt),void((d||this.settings.autostart)&&this.start())):new a(b,c,d)}return a.prototype.running=!1,a.prototype.updating=!1,a.prototype.finished=!1,a.prototype.interval=null,a.prototype.total=0,a.prototype.lastTime=0,a.prototype.startTime=0,a.prototype.lastLap=0,a.prototype.lapTime=0,a.prototype.settings={autostart:!1,countdown:!1,stopAt:null,startAt:0,milliseconds:!0,format:null},a.prototype.value=function(a){this.items.each(function(b){return function(c,d){var e;c=$(d),e=c.is("input")?"val":"text",c[e](b.format(a))}}(this))},a.prototype.format=function(a){var c;return c=this.settings.format,(c=$.isFunction(c)?c:b)(a,this.settings)},a.prototype.update=function(){var a,b,c,d,e;this.updating||(this.updating=!0,c=this.settings,e=$.now(),d=c.stopAt,a=c.countdown,b=e-this.lastTime,this.lastTime=e,a?this.total-=b:this.total+=b,null!==d&&(a&&this.total<=d||!a&&this.total>=d)&&(this.total=d,this.finished=!0,this.stop(),this.fire("runnerFinish")),this.value(this.total),this.updating=!1)},a.prototype.fire=function(a){this.items.trigger(a,this.info())},a.prototype.start=function(){var a;this.running||(this.running=!0,(!this.startTime||this.finished)&&this.reset(),this.lastTime=$.now(),a=function(b){return function(){b.running&&(b.update(),h(a))}}(this),h(a),this.fire("runnerStart"))},a.prototype.stop=function(){this.running&&(this.running=!1,this.update(),this.fire("runnerStop"))},a.prototype.toggle=function(){this.running?this.stop():this.start()},a.prototype.lap=function(){var a,b;return b=this.lastTime,a=b-this.lapTime,this.settings.countdown&&(a=-a),(this.running||a)&&(this.lastLap=a,this.lapTime=b),b=this.format(this.lastLap),this.fire("runnerLap"),b},a.prototype.reset=function(a){var b;a&&this.stop(),b=$.now(),"number"!=typeof this.settings.startAt||this.settings.countdown||(b-=this.settings.startAt),this.startTime=this.lapTime=this.lastTime=b,this.total=this.settings.startAt,this.value(this.total),this.finished=!1,this.fire("runnerReset")},a.prototype.info=function(){var a;return a=this.lastLap||0,{running:this.running,finished:this.finished,time:this.total,formattedTime:this.format(this.total),startTime:this.startTime,lapTime:a,formattedLapTime:this.format(a),settings:this.settings}},a}(),g=this.jQuery||this.Zepto||this.$,!g)throw new Error("["+c.name+"] jQuery library is required for this plugin to work");g.fn.runner=function(b,d,f){var h,i;switch(b||(b="init"),"object"==typeof b&&(f=d,d=b,b="init"),h=this.data("runner"),i=h?e[h]:!1,b){case"init":new a(this,d,f);break;case"info":if(i)return i.info();break;case"reset":i&&i.reset(d);break;case"lap":if(i)return i.lap();break;case"start":case"stop":case"toggle":if(i)return i[b]();break;case"version":return c.version;default:g.error("["+c.name+"] Method "+b+" does not exist")}return this},g.fn.runner.format=b}).call(this); \ No newline at end of file +(function(){var a,b,c,d,e,f,g,h,i;if(c={version:"2.3.2",name:"jQuery-runner"},g=this.jQuery||this.Zepto||this.$,!g||!g.fn)throw new Error("["+c.name+"] jQuery or jQuery-like library is required for this plugin to work");e={},d=function(a){return(10>a?"0":"")+a},i=1,f=function(){return"runner"+i++},h=function(a,b){return a["webkitR"+b]||a["r"+b]||a["mozR"+b]||a["msR"+b]||function(a){return setTimeout(a,30)}}(this,"equestAnimationFrame"),b=function(a,b){var c,e,f,g,h,i,j,k,l,m,n;for(b=b||{},k=[36e5,6e4,1e3,10],i=["",":",":","."],h="",g="",f=b.milliseconds,e=k.length,l=0,0>a&&(a=Math.abs(a),h="-"),c=m=0,n=k.length;n>m;c=++m)j=k[c],l=0,a>=j&&(l=Math.floor(a/j),a-=l*j),(l||c>1||g)&&(c!==e-1||f)&&(g+=(g?i[c]:"")+d(l));return h+g},a=function(){function a(b,c,d){var h;return this instanceof a?(this.items=b,h=this.id=f(),this.settings=g.extend({},this.settings,c),e[h]=this,b.each(function(a,b){g(b).data("runner",h)}),this.value(this.settings.startAt),void((d||this.settings.autostart)&&this.start())):new a(b,c,d)}return a.prototype.running=!1,a.prototype.updating=!1,a.prototype.finished=!1,a.prototype.interval=null,a.prototype.total=0,a.prototype.lastTime=0,a.prototype.startTime=0,a.prototype.lastLap=0,a.prototype.lapTime=0,a.prototype.settings={autostart:!1,countdown:!1,stopAt:null,startAt:0,milliseconds:!0,format:null},a.prototype.value=function(a){this.items.each(function(b){return function(c,d){var e;c=g(d),e=c.is("input")?"val":"text",c[e](b.format(a))}}(this))},a.prototype.format=function(a){var c;return c=this.settings.format,(c=g.isFunction(c)?c:b)(a,this.settings)},a.prototype.update=function(){var a,b,c,d,e;this.updating||(this.updating=!0,c=this.settings,e=g.now(),d=c.stopAt,a=c.countdown,b=e-this.lastTime,this.lastTime=e,a?this.total-=b:this.total+=b,null!==d&&(a&&this.total<=d||!a&&this.total>=d)&&(this.total=d,this.finished=!0,this.stop(),this.fire("runnerFinish")),this.value(this.total),this.updating=!1)},a.prototype.fire=function(a){this.items.trigger(a,this.info())},a.prototype.start=function(){var a;this.running||(this.running=!0,(!this.startTime||this.finished)&&this.reset(),this.lastTime=g.now(),a=function(b){return function(){b.running&&(b.update(),h(a))}}(this),h(a),this.fire("runnerStart"))},a.prototype.stop=function(){this.running&&(this.running=!1,this.update(),this.fire("runnerStop"))},a.prototype.toggle=function(){this.running?this.stop():this.start()},a.prototype.lap=function(){var a,b;return b=this.lastTime,a=b-this.lapTime,this.settings.countdown&&(a=-a),(this.running||a)&&(this.lastLap=a,this.lapTime=b),b=this.format(this.lastLap),this.fire("runnerLap"),b},a.prototype.reset=function(a){var b;a&&this.stop(),b=g.now(),"number"!=typeof this.settings.startAt||this.settings.countdown||(b-=this.settings.startAt),this.startTime=this.lapTime=this.lastTime=b,this.total=this.settings.startAt,this.value(this.total),this.finished=!1,this.fire("runnerReset")},a.prototype.info=function(){var a;return a=this.lastLap||0,{running:this.running,finished:this.finished,time:this.total,formattedTime:this.format(this.total),startTime:this.startTime,lapTime:a,formattedLapTime:this.format(a),settings:this.settings}},a}(),g.fn.runner=function(b,d,f){var h,i;switch(b||(b="init"),"object"==typeof b&&(f=d,d=b,b="init"),h=this.data("runner"),i=h?e[h]:!1,b){case"init":new a(this,d,f);break;case"info":if(i)return i.info();break;case"reset":i&&i.reset(d);break;case"lap":if(i)return i.lap();break;case"start":case"stop":case"toggle":if(i)return i[b]();break;case"version":return c.version;default:g.error("["+c.name+"] Method "+b+" does not exist")}return this},g.fn.runner.format=b}).call(this); \ No newline at end of file diff --git a/build/jquery.runner.coffee b/build/jquery.runner.coffee index 5ea716a..712ae49 100644 --- a/build/jquery.runner.coffee +++ b/build/jquery.runner.coffee @@ -1,14 +1,20 @@ -# jQuery-runner - v2.3.1 (2014-05-24) +# jQuery-runner - v2.3.2 (2014-05-28) # https://github.com/jylauril/jquery-runner/ # (c) 2014 Jyrki Laurila # ## Helper methods # Meta object that gets prepopulated with version info, etc. meta = { - version: "2.3.1" + version: "2.3.2" name: "jQuery-runner" } +_$ = @jQuery or @Zepto or @$ + +unless _$ and _$.fn + # Require jQuery or any other jQuery-like library + throw new Error('[' + meta.name + '] jQuery or jQuery-like library is required for this plugin to work') + # A place to store the runners runners = {} @@ -63,13 +69,13 @@ class Runner @items = items id = @id = uid() - @settings = $.extend({}, @settings, options) + @settings = _$.extend({}, @settings, options) # Store reference to this instance runners[id] = @ items.each((index, element) -> # Also save reference to each element - $(element).data('runner', id) + _$(element).data('runner', id) return ) @@ -104,7 +110,7 @@ class Runner # Method to update current time value to runner's elements value: (value) -> @items.each((item, element) => - item = $(element) + item = _$(element) # If the element is an input, we need to use `val` instead of `text` action = if item.is('input') then 'val' else 'text' item[action](@format(value)) @@ -116,7 +122,7 @@ class Runner format: (value) -> format = @settings.format # If custom format method is defined, use it, otherwise use the default formatter - format = if $.isFunction(format) then format else formatTime + format = if _$.isFunction(format) then format else formatTime format(value, @settings) # Method to update runner cycle @@ -125,7 +131,7 @@ class Runner unless @updating @updating = true settings = @settings - time = $.now() + time = _$.now() stopAt = settings.stopAt countdown = settings.countdown delta = time - @lastTime @@ -156,7 +162,7 @@ class Runner @running = true # Reset the current time value if we were not paused @reset() if not @startTime or @finished - @lastTime = $.now() + @lastTime = _$.now() step = => if @running # Update cycle if we are still running @@ -205,7 +211,7 @@ class Runner # If we passed in a boolean true, stop the runner @stop() if stop - nowTime = $.now() + nowTime = _$.now() if typeof @settings.startAt is 'number' and not @settings.countdown nowTime -= @settings.startAt @@ -231,35 +237,30 @@ class Runner settings: @settings } -_$ = @jQuery or @Zepto or @$ -if _$ - # Expose the runner as jQuery method - _$.fn.runner = (method, options, start) -> - if not method - method = 'init' - - # Normalize params - if typeof method is 'object' - start = options - options = method - method = 'init' - - # Check if runner is already defined for this element - id = @data('runner') - runner = if id then runners[id] else false - - switch method - when 'init' then new Runner(@, options, start) - when 'info' then return runner.info() if runner - when 'reset' then runner.reset(options) if runner - when 'lap' then return runner.lap() if runner - when 'start', 'stop', 'toggle' then return runner[method]() if runner - when 'version' then return meta.version - else _$.error('[' + meta.name + '] Method ' + method + ' does not exist') - return @ - - # Expose the default format method - _$.fn.runner.format = formatTime -else - # Require jQuery - throw new Error('[' + meta.name + '] jQuery library is required for this plugin to work') +# Expose the runner as jQuery method +_$.fn.runner = (method, options, start) -> + if not method + method = 'init' + + # Normalize params + if typeof method is 'object' + start = options + options = method + method = 'init' + + # Check if runner is already defined for this element + id = @data('runner') + runner = if id then runners[id] else false + + switch method + when 'init' then new Runner(@, options, start) + when 'info' then return runner.info() if runner + when 'reset' then runner.reset(options) if runner + when 'lap' then return runner.lap() if runner + when 'start', 'stop', 'toggle' then return runner[method]() if runner + when 'version' then return meta.version + else _$.error('[' + meta.name + '] Method ' + method + ' does not exist') + return @ + +# Expose the default format method +_$.fn.runner.format = formatTime diff --git a/build/jquery.runner.js b/build/jquery.runner.js index 03fc2ba..d25feba 100644 --- a/build/jquery.runner.js +++ b/build/jquery.runner.js @@ -1,5 +1,5 @@ /*! - * jQuery-runner - v2.3.1 - 2014-05-24 + * jQuery-runner - v2.3.2 - 2014-05-28 * https://github.com/jylauril/jquery-runner/ * Copyright (c) 2014 Jyrki Laurila */ @@ -7,10 +7,16 @@ var Runner, formatTime, meta, pad, runners, uid, _$, _requestAnimationFrame, _uid; meta = { - version: "2.3.1", + version: "2.3.2", name: "jQuery-runner" }; + _$ = this.jQuery || this.Zepto || this.$; + + if (!(_$ && _$.fn)) { + throw new Error('[' + meta.name + '] jQuery or jQuery-like library is required for this plugin to work'); + } + runners = {}; pad = function(num) { @@ -65,10 +71,10 @@ } this.items = items; id = this.id = uid(); - this.settings = $.extend({}, this.settings, options); + this.settings = _$.extend({}, this.settings, options); runners[id] = this; items.each(function(index, element) { - $(element).data('runner', id); + _$(element).data('runner', id); }); this.value(this.settings.startAt); if (start || this.settings.autostart) { @@ -107,7 +113,7 @@ this.items.each((function(_this) { return function(item, element) { var action; - item = $(element); + item = _$(element); action = item.is('input') ? 'val' : 'text'; item[action](_this.format(value)); }; @@ -117,7 +123,7 @@ Runner.prototype.format = function(value) { var format; format = this.settings.format; - format = $.isFunction(format) ? format : formatTime; + format = _$.isFunction(format) ? format : formatTime; return format(value, this.settings); }; @@ -126,7 +132,7 @@ if (!this.updating) { this.updating = true; settings = this.settings; - time = $.now(); + time = _$.now(); stopAt = settings.stopAt; countdown = settings.countdown; delta = time - this.lastTime; @@ -158,7 +164,7 @@ if (!this.startTime || this.finished) { this.reset(); } - this.lastTime = $.now(); + this.lastTime = _$.now(); step = (function(_this) { return function() { if (_this.running) { @@ -209,7 +215,7 @@ if (stop) { this.stop(); } - nowTime = $.now(); + nowTime = _$.now(); if (typeof this.settings.startAt === 'number' && !this.settings.countdown) { nowTime -= this.settings.startAt; } @@ -239,57 +245,52 @@ })(); - _$ = this.jQuery || this.Zepto || this.$; + _$.fn.runner = function(method, options, start) { + var id, runner; + if (!method) { + method = 'init'; + } + if (typeof method === 'object') { + start = options; + options = method; + method = 'init'; + } + id = this.data('runner'); + runner = id ? runners[id] : false; + switch (method) { + case 'init': + new Runner(this, options, start); + break; + case 'info': + if (runner) { + return runner.info(); + } + break; + case 'reset': + if (runner) { + runner.reset(options); + } + break; + case 'lap': + if (runner) { + return runner.lap(); + } + break; + case 'start': + case 'stop': + case 'toggle': + if (runner) { + return runner[method](); + } + break; + case 'version': + return meta.version; + default: + _$.error('[' + meta.name + '] Method ' + method + ' does not exist'); + } + return this; + }; - if (_$) { - _$.fn.runner = function(method, options, start) { - var id, runner; - if (!method) { - method = 'init'; - } - if (typeof method === 'object') { - start = options; - options = method; - method = 'init'; - } - id = this.data('runner'); - runner = id ? runners[id] : false; - switch (method) { - case 'init': - new Runner(this, options, start); - break; - case 'info': - if (runner) { - return runner.info(); - } - break; - case 'reset': - if (runner) { - runner.reset(options); - } - break; - case 'lap': - if (runner) { - return runner.lap(); - } - break; - case 'start': - case 'stop': - case 'toggle': - if (runner) { - return runner[method](); - } - break; - case 'version': - return meta.version; - default: - _$.error('[' + meta.name + '] Method ' + method + ' does not exist'); - } - return this; - }; - _$.fn.runner.format = formatTime; - } else { - throw new Error('[' + meta.name + '] jQuery library is required for this plugin to work'); - } + _$.fn.runner.format = formatTime; }).call(this);