Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

reseting digits array to evict problems with page that doesn't reload #8

Merged
merged 2 commits into from

3 participants

@verto

Hi,

That code solve a problem with pages that doesn't reload. The problem occurs when we use a strategy to keeps the current page instance alive and change only body content via ajax (In my case i'm using turbolinks). After i change a page that contains the counter display and return to back, the counter display doesn't show correct numbers.

@mattneary mattneary merged commit 280c9e6 into Reflejo:master
@shivakumarpvm

Hey guys I really like your plugin, It would be great if there is way to have days count more than 30.

@mattneary
Collaborator

@shivakumarpvm Thanks for the feedback. If you could open an issue elaborating on your problem and giving an example that would be great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 3 deletions.
  1. +10 −3 js/jquery.countdown.js
View
13 js/jquery.countdown.js
@@ -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);
+ }
};
Something went wrong with that request. Please try again.