Skip to content
Merged
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
10 changes: 6 additions & 4 deletions dist/timer.jquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function getDefaultConfig() {
repeat: false, // This will repeat callback every n times duration is elapsed
countdown: false, // If true, this will render the timer as a countdown (must have duration)
format: null, // This sets the format in which the time will be printed
updateFrequency: 500 // How often should timer display update
updateFrequency: 500, // How often should timer display update
};
}

Expand Down Expand Up @@ -250,15 +250,16 @@ function intervalHandler(timerInstance) {
}

timerInstance.render();

if (!timerInstance.config.duration) {
return;
}

// If the timer was called with a duration parameter,
// run the callback if duration is complete
// run the callback if duration is complete or total seconds is more than duration
// and remove the duration if `repeat` is not requested
if (timerInstance.totalSeconds > 0 &&
timerInstance.totalSeconds % timerInstance.config.duration === 0) {
(timerInstance.totalSeconds % timerInstance.config.duration === 0 || timerInstance.totalSeconds > timerInstance.config.duration )) {
if (timerInstance.config.callback) {
timerInstance.config.callback();
}
Expand Down Expand Up @@ -293,6 +294,7 @@ function Timer(element, config) {
this.originalConfig = $.extend({}, config);
this.totalSeconds = 0;
this.intervalId = null;

// A HTML element will have the html() method in jQuery to inject content,
this.html = 'html';
if (element.tagName === 'INPUT' || element.tagName === 'TEXTAREA') {
Expand Down Expand Up @@ -423,4 +425,4 @@ $.fn.timer = function(options) {
}
});
};
} (jQuery));
} (jQuery));
2 changes: 1 addition & 1 deletion dist/timer.jquery.min.js

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "timer.jquery",
"description": "Start/Stop/Resume/Remove a pretty timer inside any HTML element.",
"author": "Walmik Deshpande",
"version": "0.9.0",
"version": "0.9.1",
"repository": {
"type": "git",
"url": "git://github.com/walmik/timer.jquery.git"
Expand Down
1 change: 1 addition & 0 deletions src/Timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function Timer(element, config) {
this.originalConfig = $.extend({}, config);
this.totalSeconds = 0;
this.intervalId = null;

// A HTML element will have the html() method in jQuery to inject content,
this.html = 'html';
if (element.tagName === 'INPUT' || element.tagName === 'TEXTAREA') {
Expand Down
10 changes: 6 additions & 4 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function getDefaultConfig() {
repeat: false, // This will repeat callback every n times duration is elapsed
countdown: false, // If true, this will render the timer as a countdown (must have duration)
format: null, // This sets the format in which the time will be printed
updateFrequency: 500 // How often should timer display update
updateFrequency: 500, // How often should timer display update
};
}

Expand Down Expand Up @@ -227,7 +227,7 @@ function intervalHandler(timerInstance) {

if (timerInstance.config.countdown) {
timerInstance.totalSeconds = timerInstance.config.duration - timerInstance.totalSeconds;

if (timerInstance.totalSeconds === 0) {
clearInterval(timerInstance.intervalId);
setState(timerInstance, Constants.TIMER_STOPPED);
Expand All @@ -240,15 +240,17 @@ function intervalHandler(timerInstance) {
}

timerInstance.render();

if (!timerInstance.config.duration) {
return;
}

// If the timer was called with a duration parameter,
// run the callback if duration is complete
// run the callback if duration is complete or total seconds is more than duration
// and remove the duration if `repeat` is not requested

if (timerInstance.totalSeconds > 0 &&
timerInstance.totalSeconds % timerInstance.config.duration === 0) {
(timerInstance.totalSeconds % timerInstance.config.duration === 0 || timerInstance.totalSeconds > timerInstance.config.duration )) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good check to add :)

if (timerInstance.config.callback) {
timerInstance.config.callback();
}
Expand Down