Skip to content

Commit

Permalink
Updated distributables
Browse files Browse the repository at this point in the history
  • Loading branch information
jylauril committed May 28, 2014
1 parent 03ebf61 commit 29d9398
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 103 deletions.
4 changes: 2 additions & 2 deletions build/jquery.runner-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

83 changes: 42 additions & 41 deletions 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 <https://github.com/jylauril>
# ## 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 = {}

Expand Down Expand Up @@ -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
)

Expand Down Expand Up @@ -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))
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
121 changes: 61 additions & 60 deletions build/jquery.runner.js
@@ -1,16 +1,22 @@
/*!
* 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 <https://github.com/jylauril>
*/
(function() {
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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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));
};
Expand All @@ -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);
};

Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);

0 comments on commit 29d9398

Please sign in to comment.