Permalink
Browse files

Merge pull request #8 from verto/digits_reset

Clear digits and intervals on an AJAX page load
  • Loading branch information...
2 parents 91c84d1 + d895923 commit 280c9e62f594d2cc1803589f6e35cf7915efb275 @mattneary mattneary committed Jan 10, 2014
Showing with 10 additions and 3 deletions.
  1. +10 −3 js/jquery.countdown.js
View
@@ -13,6 +13,10 @@ var createDigits = function(where, options) {
// Iterate each startTime digit, if it is not a digit
// we'll asume that it's a separator
var mFirstPos, sFirstPos;
+ // reset digits and intervals array.
+ digits = [];
+ intervals = [];
+
for (var i = 0; i < options.startTime.length; i++) {
if (parseInt(options.startTime[i]) >= 0) {
elem = $('<div id="cnt_' + counter + '" class="cntDigit" />').css({
@@ -212,7 +216,10 @@ jQuery.fn.countdown = function(userOptions) {
delete userOptions.endTime;
}
$.extend(options, userOptions);
- createDigits(this, options);
- intervals.main = setInterval(function(){ moveDigit(digits.length - 1, options); },
- 1000);
+ if (this.length) {
+ clearInterval(intervals.main);
+ createDigits(this, options);
+ intervals.main = setInterval(function(){ moveDigit(digits.length - 1, options); },
+ 1000);
+ }
};

0 comments on commit 280c9e6

Please sign in to comment.