Skip to content

Commit b559373

Browse files
committed
Add verification if Array or Integer was passed as a Delay property (implemented in CoffeeScript and compiled JS).
1 parent 57618cb commit b559373

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

assets/coffee/tick.coffee

+14-4
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,21 @@ class Tick
141141

142142

143143
set_timer: () ->
144+
if @running
145+
_delay = 1000
144146

145-
# setInterval() can cause problems in inactive tabs (see: http://goo.gl/pToBS)
146-
@timer = setTimeout( () =>
147-
@tick()
148-
, @options.delay ) if @running
147+
# if delay is Integer
148+
_delay = @options.delay if @options.delay is parseInt(@options.delay, 10)
149+
150+
# if delay is Array of at least two Integers
151+
_delay = Math.floor( Math.random() * ( this.options.delay[1] - this.options.delay[0] + 1) + this.options.delay[0] ) if @options.delay instanceof Array and
152+
@options.delay[0] is parseInt(@options.delay[0], 10) and
153+
@options.delay[1] is parseInt(@options.delay[1], 10)
154+
155+
# setInterval() can cause problems in inactive tabs (see: http://goo.gl/pToBS)
156+
@timer = setTimeout( () =>
157+
@tick()
158+
, _delay )
149159

150160

151161
###

assets/js/tick.js

+9-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)