From fef8c2a24d58537e8589d9e921cfbf073aaa1c98 Mon Sep 17 00:00:00 2001 From: mohitYogi <20014551+mohitYogi@users.noreply.github.com> Date: Fri, 26 Jul 2019 15:08:01 +0530 Subject: [PATCH 1/9] Updated timer to support continuous run (#1) * Updated intervalHandler to support continuous run intervalHandler is updated in order to support continuous timer run, even after duration is completed * Flag for single call to callback Flag for single call to callback when timer completes in continuous run. * Update utils.js * support continuous Timer run 1. Added stopTimerOnDuration in config to run timer continuously. 2. Updated intervalHandler to support continuous run 3. Added Flag isCallbackCalled to stop multiple calls to callback after reaching the duration in continuous run. --- dist/timer.jquery.js | 25 ++++++++++++++++++++----- src/Timer.js | 4 ++++ src/utils.js | 21 ++++++++++++++++----- 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/dist/timer.jquery.js b/dist/timer.jquery.js index b8c2c8b..4a7320a 100644 --- a/dist/timer.jquery.js +++ b/dist/timer.jquery.js @@ -62,7 +62,8 @@ 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 + stopTimerOnDuration: true, // If set to false than timer will keep on running even after duration is completed }; } @@ -238,10 +239,14 @@ function intervalHandler(timerInstance) { if (timerInstance.config.countdown) { timerInstance.totalSeconds = timerInstance.config.duration - timerInstance.totalSeconds; - if (timerInstance.totalSeconds === 0) { + //Added isCallbackCalled flag, to avoid multiple calls to the callback. + if (!timerInstance.isCallbackCalled && timerInstance.totalSeconds === 0) { clearInterval(timerInstance.intervalId); setState(timerInstance, Constants.TIMER_STOPPED); timerInstance.config.callback(); + + // Updated the flag to avoid repeated callback calls + timerInstance.isCallbackCalled = true; $(timerInstance.element).data('seconds'); } @@ -250,17 +255,23 @@ function intervalHandler(timerInstance) { } timerInstance.render(); - if (!timerInstance.config.duration) { + + //Added isCallbackCalled flag, to avoid multiple calls to the callback. + if (timerInstance.isCallbackCalled || !timerInstance.config.duration) { return; } // If the timer was called with a duration parameter, // run the callback if duration is complete // and remove the duration if `repeat` is not requested + + // Added new Condition of checking the timer completed or not 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(); + // Updated the flag to avoid repeated callback calls + timerInstance.isCallbackCalled = true; } if (!timerInstance.config.repeat) { @@ -293,6 +304,10 @@ function Timer(element, config) { this.originalConfig = $.extend({}, config); this.totalSeconds = 0; this.intervalId = null; + + //Flag for single call to callback when timer completes in continuous run. + this.isCallbackCalled = false; + // A HTML element will have the html() method in jQuery to inject content, this.html = 'html'; if (element.tagName === 'INPUT' || element.tagName === 'TEXTAREA') { @@ -423,4 +438,4 @@ $.fn.timer = function(options) { } }); }; -} (jQuery)); \ No newline at end of file +} (jQuery)); diff --git a/src/Timer.js b/src/Timer.js index bf31aa3..a78d5ee 100644 --- a/src/Timer.js +++ b/src/Timer.js @@ -8,6 +8,10 @@ function Timer(element, config) { this.originalConfig = $.extend({}, config); this.totalSeconds = 0; this.intervalId = null; + + //Flag for single call to callback when timer completes in continuous run. + this.isCallbackCalled = false; + // A HTML element will have the html() method in jQuery to inject content, this.html = 'html'; if (element.tagName === 'INPUT' || element.tagName === 'TEXTAREA') { diff --git a/src/utils.js b/src/utils.js index 04c64f3..55197a0 100644 --- a/src/utils.js +++ b/src/utils.js @@ -52,7 +52,8 @@ 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 + stopTimerOnDuration: true, // If set to false than timer will keep on running even after duration is completed. }; } @@ -227,11 +228,15 @@ function intervalHandler(timerInstance) { if (timerInstance.config.countdown) { timerInstance.totalSeconds = timerInstance.config.duration - timerInstance.totalSeconds; - - if (timerInstance.totalSeconds === 0) { + + //Added isCallbackCalled flag, to avoid multiple calls to the callback. + if (!timerInstance.isCallbackCalled && timerInstance.totalSeconds === 0) { clearInterval(timerInstance.intervalId); setState(timerInstance, Constants.TIMER_STOPPED); timerInstance.config.callback(); + + // Updated the flag to avoid repeated callback calls + timerInstance.isCallbackCalled = true; $(timerInstance.element).data('seconds'); } @@ -240,17 +245,23 @@ function intervalHandler(timerInstance) { } timerInstance.render(); - if (!timerInstance.config.duration) { + + //Added isCallbackCalled flag, to avoid multiple calls to the callback. + if (timerInstance.isCallbackCalled || !timerInstance.config.duration) { return; } // If the timer was called with a duration parameter, // run the callback if duration is complete // and remove the duration if `repeat` is not requested + + // Added new Condition of checking the timer completed or not 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(); + // Updated the flag to avoid repeated callback calls + timerInstance.isCallbackCalled = true; } if (!timerInstance.config.repeat) { From 5da095bdcb94c220119493212d3fae0d6ee9866b Mon Sep 17 00:00:00 2001 From: mohitYogi <20014551+mohitYogi@users.noreply.github.com> Date: Sat, 27 Jul 2019 10:47:48 +0530 Subject: [PATCH 2/9] Updates after review. 1. Removed stopTimerOnDuration flag (repeat flag do the same.) 2. Removed isCallbackCalled flag, as suggested after commit review. --- src/utils.js | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/utils.js b/src/utils.js index 55197a0..245aafc 100644 --- a/src/utils.js +++ b/src/utils.js @@ -53,7 +53,6 @@ function getDefaultConfig() { 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 - stopTimerOnDuration: true, // If set to false than timer will keep on running even after duration is completed. }; } @@ -230,13 +229,10 @@ function intervalHandler(timerInstance) { timerInstance.totalSeconds = timerInstance.config.duration - timerInstance.totalSeconds; //Added isCallbackCalled flag, to avoid multiple calls to the callback. - if (!timerInstance.isCallbackCalled && timerInstance.totalSeconds === 0) { + if (timerInstance.totalSeconds === 0) { clearInterval(timerInstance.intervalId); setState(timerInstance, Constants.TIMER_STOPPED); timerInstance.config.callback(); - - // Updated the flag to avoid repeated callback calls - timerInstance.isCallbackCalled = true; $(timerInstance.element).data('seconds'); } @@ -246,8 +242,7 @@ function intervalHandler(timerInstance) { timerInstance.render(); - //Added isCallbackCalled flag, to avoid multiple calls to the callback. - if (timerInstance.isCallbackCalled || !timerInstance.config.duration) { + if (!timerInstance.config.duration) { return; } @@ -260,8 +255,6 @@ function intervalHandler(timerInstance) { (timerInstance.totalSeconds % timerInstance.config.duration === 0 || timerInstance.totalSeconds > timerInstance.config.duration )) { if (timerInstance.config.callback) { timerInstance.config.callback(); - // Updated the flag to avoid repeated callback calls - timerInstance.isCallbackCalled = true; } if (!timerInstance.config.repeat) { From 076c1af4f8a375b5f98597afd67fb039ab385197 Mon Sep 17 00:00:00 2001 From: mohitYogi <20014551+mohitYogi@users.noreply.github.com> Date: Sat, 27 Jul 2019 10:49:08 +0530 Subject: [PATCH 3/9] Update after Review Removed flag isCallbackCalled. (Not required). --- src/Timer.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Timer.js b/src/Timer.js index a78d5ee..680e1c9 100644 --- a/src/Timer.js +++ b/src/Timer.js @@ -9,9 +9,6 @@ function Timer(element, config) { this.totalSeconds = 0; this.intervalId = null; - //Flag for single call to callback when timer completes in continuous run. - this.isCallbackCalled = false; - // A HTML element will have the html() method in jQuery to inject content, this.html = 'html'; if (element.tagName === 'INPUT' || element.tagName === 'TEXTAREA') { From 408fbef3682d398a38b8577820cda6e531e1dbc7 Mon Sep 17 00:00:00 2001 From: mohitYogi <20014551+mohitYogi@users.noreply.github.com> Date: Sat, 27 Jul 2019 10:52:08 +0530 Subject: [PATCH 4/9] Updates after review 1. Removed stopTimerOnDuration flag (repeat flag do the same.) 2. Removed isCallbackCalled flag, as suggested after commit review. --- dist/timer.jquery.js | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/dist/timer.jquery.js b/dist/timer.jquery.js index 4a7320a..2e97541 100644 --- a/dist/timer.jquery.js +++ b/dist/timer.jquery.js @@ -63,7 +63,6 @@ function getDefaultConfig() { 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 - stopTimerOnDuration: true, // If set to false than timer will keep on running even after duration is completed }; } @@ -240,13 +239,10 @@ function intervalHandler(timerInstance) { timerInstance.totalSeconds = timerInstance.config.duration - timerInstance.totalSeconds; //Added isCallbackCalled flag, to avoid multiple calls to the callback. - if (!timerInstance.isCallbackCalled && timerInstance.totalSeconds === 0) { + if (timerInstance.totalSeconds === 0) { clearInterval(timerInstance.intervalId); setState(timerInstance, Constants.TIMER_STOPPED); - timerInstance.config.callback(); - - // Updated the flag to avoid repeated callback calls - timerInstance.isCallbackCalled = true; + timerInstance.config.callback() $(timerInstance.element).data('seconds'); } @@ -256,8 +252,7 @@ function intervalHandler(timerInstance) { timerInstance.render(); - //Added isCallbackCalled flag, to avoid multiple calls to the callback. - if (timerInstance.isCallbackCalled || !timerInstance.config.duration) { + if (!timerInstance.config.duration) { return; } @@ -270,8 +265,6 @@ function intervalHandler(timerInstance) { (timerInstance.totalSeconds % timerInstance.config.duration === 0 || timerInstance.totalSeconds > timerInstance.config.duration )) { if (timerInstance.config.callback) { timerInstance.config.callback(); - // Updated the flag to avoid repeated callback calls - timerInstance.isCallbackCalled = true; } if (!timerInstance.config.repeat) { @@ -305,9 +298,6 @@ function Timer(element, config) { this.totalSeconds = 0; this.intervalId = null; - //Flag for single call to callback when timer completes in continuous run. - this.isCallbackCalled = false; - // A HTML element will have the html() method in jQuery to inject content, this.html = 'html'; if (element.tagName === 'INPUT' || element.tagName === 'TEXTAREA') { From 9c328efeb3fd678fd003c9ba7e9f33d6cb951b76 Mon Sep 17 00:00:00 2001 From: mohitYogi <20014551+mohitYogi@users.noreply.github.com> Date: Sat, 27 Jul 2019 10:58:05 +0530 Subject: [PATCH 5/9] Updates after Review 1. Removed stopTimerOnDuration flag (repeat flag do the same.) 2. Removed isCallbackCalled flag, as suggested after commit review. --- dist/timer.jquery.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/timer.jquery.min.js b/dist/timer.jquery.min.js index db5f275..1e53ab4 100644 --- a/dist/timer.jquery.min.js +++ b/dist/timer.jquery.min.js @@ -1 +1 @@ -!function(a){function b(a){var b;return a=a||0,b=Math.floor(a/60),{days:a>=n.DAYINSECONDS?Math.floor(a/n.DAYINSECONDS):0,hours:a>=3600?Math.floor(a%n.DAYINSECONDS/3600):0,totalMinutes:b,minutes:a>=60?Math.floor(a%3600/60):b,seconds:a%60,totalSeconds:a}}function c(a){return((a=parseInt(a,10))<10&&"0")+a}function d(){return{seconds:0,editable:!1,duration:null,callback:function(){console.log("Time up!")},repeat:!1,countdown:!1,format:null,updateFrequency:500}}function e(){return Math.round((Date.now?Date.now():(new Date).getTime())/1e3)}function f(a){var d=b(a);if(d.days)return d.days+":"+c(d.hours)+":"+c(d.minutes)+":"+c(d.seconds);if(d.hours)return d.hours+":"+c(d.minutes)+":"+c(d.seconds);return d.minutes?d.minutes+":"+c(d.seconds)+" min":d.seconds+" sec"}function g(a,d){for(var e=b(a),f=[{identifier:"%d",value:e.days},{identifier:"%h",value:e.hours},{identifier:"%m",value:e.minutes},{identifier:"%s",value:e.seconds},{identifier:"%g",value:e.totalMinutes},{identifier:"%t",value:e.totalSeconds},{identifier:"%D",value:c(e.days)},{identifier:"%H",value:c(e.hours)},{identifier:"%M",value:c(e.minutes)},{identifier:"%S",value:c(e.seconds)},{identifier:"%G",value:c(e.totalMinutes)},{identifier:"%T",value:c(e.totalSeconds)}],g=0;g0?c=Number(a.replace(/\ssec/g,"")):a.indexOf("min")>0?(a=a.replace(/\smin/g,""),b=a.split(":"),c=Number(60*b[0])+Number(b[1])):a.match(/\d{1,2}:\d{2}:\d{2}:\d{2}/)?(b=a.split(":"),c=Number(b[0]*n.DAYINSECONDS)+Number(3600*b[1])+Number(60*b[2])+Number(b[3])):a.match(/\d{1,2}:\d{2}:\d{2}/)&&(b=a.split(":"),c=Number(3600*b[0])+Number(60*b[1])+Number(b[2])),c}function j(b,c){b.state=c,a(b.element).data("state",c)}function k(b){a(b.element).on("focus",function(){b.pause()}),a(b.element).on("blur",function(){b.totalSeconds=i(a(b.element)[b.html]()),b.resume()})}function l(b){if(b.totalSeconds=e()-b.startTime,b.config.countdown)return b.totalSeconds=b.config.duration-b.totalSeconds,0===b.totalSeconds&&(clearInterval(b.intervalId),j(b,n.TIMER_STOPPED),b.config.callback(),a(b.element).data("seconds")),void b.render();b.render(),b.config.duration&&b.totalSeconds>0&&b.totalSeconds%b.config.duration==0&&(b.config.callback&&b.config.callback(),b.config.repeat||(clearInterval(b.intervalId),j(b,n.TIMER_STOPPED),b.config.duration=null))}function m(b,c){if(this.element=b,this.originalConfig=a.extend({},c),this.totalSeconds=0,this.intervalId=null,this.html="html","INPUT"!==b.tagName&&"TEXTAREA"!==b.tagName||(this.html="val"),this.config=o.getDefaultConfig(),c.duration&&(c.duration=o.durationTimeToSeconds(c.duration)),"string"!=typeof c&&(this.config=a.extend(this.config,c)),this.config.seconds&&(this.totalSeconds=this.config.seconds),this.config.editable&&o.makeEditable(this),this.startTime=o.unixSeconds()-this.totalSeconds,this.config.duration&&this.config.repeat&&this.config.updateFrequency<1e3&&(this.config.updateFrequency=1e3),this.config.countdown){if(!this.config.duration)throw new Error("Countdown option set without duration!");if(this.config.editable)throw new Error("Cannot set editable on a countdown timer!");this.config.startTime=o.unixSeconds()-this.config.duration,this.totalSeconds=this.config.duration}}var n={PLUGIN_NAME:"timer",TIMER_RUNNING:"running",TIMER_PAUSED:"paused",TIMER_REMOVED:"removed",DAYINSECONDS:86400},o={getDefaultConfig:d,unixSeconds:e,secondsToPrettyTime:f,secondsToFormattedTime:g,durationTimeToSeconds:h,prettyTimeToSeconds:i,setState:j,makeEditable:k,intervalHandler:l};m.prototype.start=function(){this.state!==n.TIMER_RUNNING&&(o.setState(this,n.TIMER_RUNNING),this.render(),this.intervalId=setInterval(o.intervalHandler.bind(null,this),this.config.updateFrequency))},m.prototype.pause=function(){this.state===n.TIMER_RUNNING&&(o.setState(this,n.TIMER_PAUSED),clearInterval(this.intervalId))},m.prototype.resume=function(){this.state===n.TIMER_PAUSED&&(o.setState(this,n.TIMER_RUNNING),this.config.countdown?this.startTime=o.unixSeconds()-this.config.duration+this.totalSeconds:this.startTime=o.unixSeconds()-this.totalSeconds,this.intervalId=setInterval(o.intervalHandler.bind(null,this),this.config.updateFrequency))},m.prototype.remove=function(){clearInterval(this.intervalId),o.setState(this,n.TIMER_REMOVED),a(this.element).data(n.PLUGIN_NAME,null),a(this.element).data("seconds",null)},m.prototype.reset=function(){var b=this.originalConfig;this.remove(),a(this.element).timer(b)},m.prototype.render=function(){this.config.format?a(this.element)[this.html](o.secondsToFormattedTime(this.totalSeconds,this.config.format)):a(this.element)[this.html](o.secondsToPrettyTime(this.totalSeconds)),a(this.element).data("seconds",this.totalSeconds)},a.fn.timer=function(b){return b=b||"start",this.each(function(){a.data(this,n.PLUGIN_NAME)instanceof m||a.data(this,n.PLUGIN_NAME,new m(this,b));var c=a.data(this,n.PLUGIN_NAME);"string"==typeof b?"function"==typeof c[b]&&c[b]():c.start()})}}(jQuery); \ No newline at end of file +!function(n){var a={PLUGIN_NAME:"timer",TIMER_RUNNING:"running",TIMER_PAUSED:"paused",TIMER_REMOVED:"removed",DAYINSECONDS:86400};function s(t){var e;return t=t||0,e=Math.floor(t/60),{days:t>=a.DAYINSECONDS?Math.floor(t/a.DAYINSECONDS):0,hours:3600<=t?Math.floor(t%a.DAYINSECONDS/3600):0,totalMinutes:e,minutes:60<=t?Math.floor(t%3600/60):e,seconds:t%60,totalSeconds:t}}function r(t){return((t=parseInt(t,10))<10&&"0")+t}function e(){return Math.round((Date.now?Date.now():(new Date).getTime())/1e3)}function i(t){var e,n;return 0t.config.duration)&&(t.config.callback&&t.config.callback(),t.config.repeat||(clearInterval(t.intervalId),o(t,a.TIMER_STOPPED),t.config.duration=null))}};function c(t,e){if(this.element=t,this.originalConfig=n.extend({},e),this.totalSeconds=0,this.intervalId=null,this.html="html","INPUT"!==t.tagName&&"TEXTAREA"!==t.tagName||(this.html="val"),this.config=d.getDefaultConfig(),e.duration&&(e.duration=d.durationTimeToSeconds(e.duration)),"string"!=typeof e&&(this.config=n.extend(this.config,e)),this.config.seconds&&(this.totalSeconds=this.config.seconds),this.config.editable&&d.makeEditable(this),this.startTime=d.unixSeconds()-this.totalSeconds,this.config.duration&&this.config.repeat&&this.config.updateFrequency<1e3&&(this.config.updateFrequency=1e3),this.config.countdown){if(!this.config.duration)throw new Error("Countdown option set without duration!");if(this.config.editable)throw new Error("Cannot set editable on a countdown timer!");this.config.startTime=d.unixSeconds()-this.config.duration,this.totalSeconds=this.config.duration}}c.prototype.start=function(){this.state!==a.TIMER_RUNNING&&(d.setState(this,a.TIMER_RUNNING),this.render(),this.intervalId=setInterval(d.intervalHandler.bind(null,this),this.config.updateFrequency))},c.prototype.pause=function(){this.state===a.TIMER_RUNNING&&(d.setState(this,a.TIMER_PAUSED),clearInterval(this.intervalId))},c.prototype.resume=function(){this.state===a.TIMER_PAUSED&&(d.setState(this,a.TIMER_RUNNING),this.config.countdown?this.startTime=d.unixSeconds()-this.config.duration+this.totalSeconds:this.startTime=d.unixSeconds()-this.totalSeconds,this.intervalId=setInterval(d.intervalHandler.bind(null,this),this.config.updateFrequency))},c.prototype.remove=function(){clearInterval(this.intervalId),d.setState(this,a.TIMER_REMOVED),n(this.element).data(a.PLUGIN_NAME,null),n(this.element).data("seconds",null)},c.prototype.reset=function(){var t=this.originalConfig;this.remove(),n(this.element).timer(t)},c.prototype.render=function(){this.config.format?n(this.element)[this.html](d.secondsToFormattedTime(this.totalSeconds,this.config.format)):n(this.element)[this.html](d.secondsToPrettyTime(this.totalSeconds)),n(this.element).data("seconds",this.totalSeconds)},n.fn.timer=function(e){return e=e||"start",this.each(function(){n.data(this,a.PLUGIN_NAME)instanceof c||n.data(this,a.PLUGIN_NAME,new c(this,e));var t=n.data(this,a.PLUGIN_NAME);"string"==typeof e?"function"==typeof t[e]&&t[e]():t.start()})}}(jQuery); From 77a7ac9341452626a80509db9b92a6b1d5ac475b Mon Sep 17 00:00:00 2001 From: mohitYogi <20014551+mohitYogi@users.noreply.github.com> Date: Sat, 27 Jul 2019 11:01:57 +0530 Subject: [PATCH 6/9] Patch version New rule for checking timer duration completed. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 14c764d..bf4a8d4 100644 --- a/package.json +++ b/package.json @@ -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" From 84baf37f87f693c9f63d6374cc3cdd699a112e77 Mon Sep 17 00:00:00 2001 From: mohitYogi <20014551+mohitYogi@users.noreply.github.com> Date: Sat, 27 Jul 2019 11:07:10 +0530 Subject: [PATCH 7/9] Update timer.jquery.js --- dist/timer.jquery.js | 1 - 1 file changed, 1 deletion(-) diff --git a/dist/timer.jquery.js b/dist/timer.jquery.js index 2e97541..3afc36c 100644 --- a/dist/timer.jquery.js +++ b/dist/timer.jquery.js @@ -238,7 +238,6 @@ function intervalHandler(timerInstance) { if (timerInstance.config.countdown) { timerInstance.totalSeconds = timerInstance.config.duration - timerInstance.totalSeconds; - //Added isCallbackCalled flag, to avoid multiple calls to the callback. if (timerInstance.totalSeconds === 0) { clearInterval(timerInstance.intervalId); setState(timerInstance, Constants.TIMER_STOPPED); From fd614b926fbef1ac6a3502e8a141878120dba227 Mon Sep 17 00:00:00 2001 From: mohitYogi <20014551+mohitYogi@users.noreply.github.com> Date: Tue, 30 Jul 2019 10:41:03 +0530 Subject: [PATCH 8/9] Semicolon & Comment update Added missing semi colon. Updated Comment. --- dist/timer.jquery.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/dist/timer.jquery.js b/dist/timer.jquery.js index 3afc36c..068431e 100644 --- a/dist/timer.jquery.js +++ b/dist/timer.jquery.js @@ -241,7 +241,7 @@ function intervalHandler(timerInstance) { if (timerInstance.totalSeconds === 0) { clearInterval(timerInstance.intervalId); setState(timerInstance, Constants.TIMER_STOPPED); - timerInstance.config.callback() + timerInstance.config.callback(); $(timerInstance.element).data('seconds'); } @@ -256,10 +256,8 @@ function intervalHandler(timerInstance) { } // 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 - - // Added new Condition of checking the timer completed or not if (timerInstance.totalSeconds > 0 && (timerInstance.totalSeconds % timerInstance.config.duration === 0 || timerInstance.totalSeconds > timerInstance.config.duration )) { if (timerInstance.config.callback) { From c3e5986ab4bc370062bafe70a8ac7f915605f504 Mon Sep 17 00:00:00 2001 From: mohitYogi <20014551+mohitYogi@users.noreply.github.com> Date: Tue, 30 Jul 2019 10:43:05 +0530 Subject: [PATCH 9/9] Removed & Updated Comment --- src/utils.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/utils.js b/src/utils.js index 245aafc..4cb8279 100644 --- a/src/utils.js +++ b/src/utils.js @@ -228,7 +228,6 @@ function intervalHandler(timerInstance) { if (timerInstance.config.countdown) { timerInstance.totalSeconds = timerInstance.config.duration - timerInstance.totalSeconds; - //Added isCallbackCalled flag, to avoid multiple calls to the callback. if (timerInstance.totalSeconds === 0) { clearInterval(timerInstance.intervalId); setState(timerInstance, Constants.TIMER_STOPPED); @@ -247,10 +246,9 @@ function intervalHandler(timerInstance) { } // 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 - // Added new Condition of checking the timer completed or not if (timerInstance.totalSeconds > 0 && (timerInstance.totalSeconds % timerInstance.config.duration === 0 || timerInstance.totalSeconds > timerInstance.config.duration )) { if (timerInstance.config.callback) {