diff --git a/assets/coffee/tick.coffee b/assets/coffee/tick.coffee index d49ee60..ebe65a3 100755 --- a/assets/coffee/tick.coffee +++ b/assets/coffee/tick.coffee @@ -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 ) ### diff --git a/assets/js/tick.js b/assets/js/tick.js index 78a9564..975b1df 100755 --- a/assets/js/tick.js +++ b/assets/js/tick.js @@ -141,11 +141,19 @@ }; Tick.prototype.set_timer = function() { - var _this = this; + var _delay, + _this = this; if (this.running) { + _delay = 1000; + if (this.options.delay === parseInt(this.options.delay, 10)) { + _delay = this.options.delay; + } + if (this.options.delay instanceof Array && this.options.delay[0] === parseInt(this.options.delay[0], 10) && this.options.delay[1] === parseInt(this.options.delay[1], 10)) { + _delay = Math.floor(Math.random() * (this.options.delay[1] - this.options.delay[0] + 1) + this.options.delay[0]); + } return this.timer = setTimeout(function() { return _this.tick(); - }, this.options.delay); + }, _delay); } }; diff --git a/demo/assets/js/interface.js b/demo/assets/js/interface.js index bafa293..508710f 100755 --- a/demo/assets/js/interface.js +++ b/demo/assets/js/interface.js @@ -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 }); -}); \ No newline at end of file +});