Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #10: Random delay #13

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions assets/coffee/tick.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,21 @@ class Tick


set_timer: () ->
if @running
_delay = 1000

# setInterval() can cause problems in inactive tabs (see: http://goo.gl/pToBS)
@timer = setTimeout( () =>
@tick()
, @options.delay ) if @running
# if delay is Integer
_delay = @options.delay if @options.delay is parseInt(@options.delay, 10)

# if delay is Array of at least two Integers
_delay = Math.floor( Math.random() * ( this.options.delay[1] - this.options.delay[0] + 1) + this.options.delay[0] ) if @options.delay instanceof Array and
@options.delay[0] is parseInt(@options.delay[0], 10) and
@options.delay[1] is parseInt(@options.delay[1], 10)

# setInterval() can cause problems in inactive tabs (see: http://goo.gl/pToBS)
@timer = setTimeout( () =>
@tick()
, _delay )


###
Expand Down
12 changes: 10 additions & 2 deletions assets/js/tick.js

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

4 changes: 2 additions & 2 deletions demo/assets/js/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ $( document ).ready( function()
{
$( '.tick' ).ticker(
{
delay : 1000,
delay : [50, 1000], // will take random number in between 50 and 1000 ms
separators : true
});
});
});