From 1963bfd82a37cff96a79f13e55efadd9bd7036a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ko=C4=8Dvara?= Date: Mon, 27 Oct 2014 11:44:54 +0100 Subject: [PATCH 1/8] add message to set timer value --- app/js/timer.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/js/timer.js b/app/js/timer.js index ced1501..eec80f7 100644 --- a/app/js/timer.js +++ b/app/js/timer.js @@ -57,6 +57,14 @@ var timerModule = angular.module('timer', []) $scope.$on('timer-set-countdown', function (e, countdown) { $scope.countdown = countdown; }); + + $scope.$on('timer-set-value', function (e, millis) { + if ($scope.countdownattr) { + $scope.countdown = millis / 1000; + } else { + $scope.millis = millis; + } + }); function resetTimeout() { if ($scope.timeoutId) { From 412e52a20ac7518b2173a82ce6b6145fb298670e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ko=C4=8Dvara?= Date: Mon, 27 Oct 2014 14:37:39 +0100 Subject: [PATCH 2/8] working timer value setter --- app/js/timer.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/js/timer.js b/app/js/timer.js index eec80f7..03ded98 100644 --- a/app/js/timer.js +++ b/app/js/timer.js @@ -60,9 +60,9 @@ var timerModule = angular.module('timer', []) $scope.$on('timer-set-value', function (e, millis) { if ($scope.countdownattr) { - $scope.countdown = millis / 1000; + $scope.countdown = millis; } else { - $scope.millis = millis; + $scope.startTime = new Date() - (millis * 1000); } }); From e4016ad11240f6a7ffd3a4473b867614ccf0faa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ko=C4=8Dvara?= Date: Mon, 27 Oct 2014 14:59:01 +0100 Subject: [PATCH 3/8] Renamed millis to seconds for better readability --- app/js/timer.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/js/timer.js b/app/js/timer.js index 03ded98..aa771f8 100644 --- a/app/js/timer.js +++ b/app/js/timer.js @@ -58,11 +58,11 @@ var timerModule = angular.module('timer', []) $scope.countdown = countdown; }); - $scope.$on('timer-set-value', function (e, millis) { + $scope.$on('timer-set-value', function (e, seconds) { if ($scope.countdownattr) { - $scope.countdown = millis; + $scope.countdown = seconds; } else { - $scope.startTime = new Date() - (millis * 1000); + $scope.startTime = new Date() - (seconds * 1000); } }); From fd559da4ae16738f6c8dc7a002f6f36e3904fb16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ko=C4=8Dvara?= Date: Mon, 27 Oct 2014 15:21:14 +0100 Subject: [PATCH 4/8] angular-timer.js built --- dist/angular-timer.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/dist/angular-timer.js b/dist/angular-timer.js index 7b11bd1..23bdde3 100644 --- a/dist/angular-timer.js +++ b/dist/angular-timer.js @@ -65,6 +65,14 @@ var timerModule = angular.module('timer', []) $scope.countdown = countdown; }); + $scope.$on('timer-set-value', function (e, seconds) { + if ($scope.countdownattr) { + $scope.countdown = seconds; + } else { + $scope.startTime = new Date() - (seconds * 1000); + } + }); + function resetTimeout() { if ($scope.timeoutId) { clearTimeout($scope.timeoutId); From f990e4b55c68947038abbf97616f7f0b21d59f8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ko=C4=8Dvara?= Date: Wed, 5 Nov 2014 15:15:53 +0100 Subject: [PATCH 5/8] Fix IE countdown --- app/js/timer.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/app/js/timer.js b/app/js/timer.js index aa771f8..80fe277 100644 --- a/app/js/timer.js +++ b/app/js/timer.js @@ -1,3 +1,10 @@ +/** + * angular-timer - v1.1.6 - 2014-07-01 7:37 AM + * https://github.com/siddii/angular-timer + * + * Copyright (c) 2014 Siddique Hameed + * Licensed MIT + */ var timerModule = angular.module('timer', []) .directive('timer', ['$compile', function ($compile) { return { @@ -8,11 +15,12 @@ var timerModule = angular.module('timer', []) startTimeAttr: '=startTime', endTimeAttr: '=endTime', countdownattr: '=countdown', + finishCallback: '&finishCallback', autoStart: '&autoStart', maxTimeUnit: '=' }, controller: ['$scope', '$element', '$attrs', '$timeout', function ($scope, $element, $attrs, $timeout) { - + console.log($scope.interval); // Checking for trim function since IE8 doesn't have it // If not a function, create tirm with RegEx to mimic native trim if (typeof String.prototype.trim !== 'function') { @@ -57,7 +65,7 @@ var timerModule = angular.module('timer', []) $scope.$on('timer-set-countdown', function (e, countdown) { $scope.countdown = countdown; }); - + $scope.$on('timer-set-value', function (e, seconds) { if ($scope.countdownattr) { $scope.countdown = seconds; @@ -220,13 +228,16 @@ var timerModule = angular.module('timer', []) if ($scope.countdownattr) { - $scope.millis = $scope.countdown * 1000; + $scope.millis = Math.round(($scope.countdown * 1000 - $scope.millis) / 1000) * 1000; } if ($scope.millis < 0) { $scope.stop(); $scope.millis = 0; calculateTimeUnits(); + if($scope.finishCallback) { + $scope.$eval($scope.finishCallback); + } return; } calculateTimeUnits(); @@ -238,13 +249,6 @@ var timerModule = angular.module('timer', []) }, $scope.interval - adjustment); $scope.$emit('timer-tick', {timeoutId: $scope.timeoutId, millis: $scope.millis}); - - if ($scope.countdown > 0) { - $scope.countdown--; - } - else if ($scope.countdown <= 0) { - $scope.stop(); - } }; if ($scope.autoStart === undefined || $scope.autoStart === true) { From e6f50f8746bb29b6071dec35cbd72c10ab8e3adf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ko=C4=8Dvara?= Date: Wed, 5 Nov 2014 15:20:52 +0100 Subject: [PATCH 6/8] built last commit --- dist/angular-timer.js | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/dist/angular-timer.js b/dist/angular-timer.js index 23bdde3..80fe277 100644 --- a/dist/angular-timer.js +++ b/dist/angular-timer.js @@ -1,5 +1,5 @@ /** - * angular-timer - v1.1.5 - 2014-06-14 7:52 AM + * angular-timer - v1.1.6 - 2014-07-01 7:37 AM * https://github.com/siddii/angular-timer * * Copyright (c) 2014 Siddique Hameed @@ -15,11 +15,12 @@ var timerModule = angular.module('timer', []) startTimeAttr: '=startTime', endTimeAttr: '=endTime', countdownattr: '=countdown', + finishCallback: '&finishCallback', autoStart: '&autoStart', maxTimeUnit: '=' }, controller: ['$scope', '$element', '$attrs', '$timeout', function ($scope, $element, $attrs, $timeout) { - + console.log($scope.interval); // Checking for trim function since IE8 doesn't have it // If not a function, create tirm with RegEx to mimic native trim if (typeof String.prototype.trim !== 'function') { @@ -72,7 +73,7 @@ var timerModule = angular.module('timer', []) $scope.startTime = new Date() - (seconds * 1000); } }); - + function resetTimeout() { if ($scope.timeoutId) { clearTimeout($scope.timeoutId); @@ -227,13 +228,16 @@ var timerModule = angular.module('timer', []) if ($scope.countdownattr) { - $scope.millis = $scope.countdown * 1000; + $scope.millis = Math.round(($scope.countdown * 1000 - $scope.millis) / 1000) * 1000; } if ($scope.millis < 0) { $scope.stop(); $scope.millis = 0; calculateTimeUnits(); + if($scope.finishCallback) { + $scope.$eval($scope.finishCallback); + } return; } calculateTimeUnits(); @@ -245,13 +249,6 @@ var timerModule = angular.module('timer', []) }, $scope.interval - adjustment); $scope.$emit('timer-tick', {timeoutId: $scope.timeoutId, millis: $scope.millis}); - - if ($scope.countdown > 0) { - $scope.countdown--; - } - else if ($scope.countdown <= 0) { - $scope.stop(); - } }; if ($scope.autoStart === undefined || $scope.autoStart === true) { From cad0815f390ae8b80c0d19754b59e69344c9babd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ko=C4=8Dvara?= Date: Thu, 6 Nov 2014 13:08:41 +0100 Subject: [PATCH 7/8] fixed countdown setter --- app/js/timer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/js/timer.js b/app/js/timer.js index 80fe277..5677b23 100644 --- a/app/js/timer.js +++ b/app/js/timer.js @@ -68,7 +68,7 @@ var timerModule = angular.module('timer', []) $scope.$on('timer-set-value', function (e, seconds) { if ($scope.countdownattr) { - $scope.countdown = seconds; + $scope.countdown = $scope.countdown - ($scope.millis / 1000 - seconds); } else { $scope.startTime = new Date() - (seconds * 1000); } From ffac25498a184f49a2f3cf6685d0fd2846e5af5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ko=C4=8Dvara?= Date: Thu, 6 Nov 2014 13:09:14 +0100 Subject: [PATCH 8/8] built last commit --- dist/angular-timer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/angular-timer.js b/dist/angular-timer.js index 80fe277..48a42a0 100644 --- a/dist/angular-timer.js +++ b/dist/angular-timer.js @@ -68,7 +68,7 @@ var timerModule = angular.module('timer', []) $scope.$on('timer-set-value', function (e, seconds) { if ($scope.countdownattr) { - $scope.countdown = seconds; + $scope.countdown = $scope.countdown = $scope.countdown - ($scope.millis / 1000 - seconds); } else { $scope.startTime = new Date() - (seconds * 1000); }