Skip to content

Commit 76f3949

Browse files
committed
watch endTime attribute so the timer adjusts when endTime changes.
1 parent 06bc1ea commit 76f3949

File tree

4 files changed

+37
-9
lines changed

4 files changed

+37
-9
lines changed

app/js/_timer.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ var timerModule = angular.module('timer', [])
9696
}
9797
});
9898

99+
$scope.$watch('endTimeAttr', function(newValue, oldValue) {
100+
if (newValue !== oldValue && $scope.isRunning) {
101+
$scope.start();
102+
}
103+
});
104+
99105
$scope.start = $element[0].start = function () {
100106
$scope.startTime = $scope.startTimeAttr ? moment($scope.startTimeAttr) : moment();
101107
$scope.endTime = $scope.endTimeAttr ? moment($scope.endTimeAttr) : null;

dist/angular-timer.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* angular-timer - v1.3.1 - 2015-03-30 1:00 PM
2+
* angular-timer - v1.3.1 - 2015-05-19 12:41 AM
33
* https://github.com/siddii/angular-timer
44
*
55
* Copyright (c) 2015 Siddique Hameed
@@ -18,6 +18,7 @@ var timerModule = angular.module('timer', [])
1818
finishCallback: '&finishCallback',
1919
autoStart: '&autoStart',
2020
language: '@?',
21+
fallback: '@?',
2122
maxTimeUnit: '='
2223
},
2324
controller: ['$scope', '$element', '$attrs', '$timeout', 'I18nService', '$interpolate', 'progressBarService', function ($scope, $element, $attrs, $timeout, I18nService, $interpolate, progressBarService) {
@@ -37,15 +38,18 @@ var timerModule = angular.module('timer', [])
3738

3839

3940
$scope.language = $scope.language || 'en';
41+
$scope.fallback = $scope.fallback || 'en';
4042

4143
//allow to change the language of the directive while already launched
42-
$scope.$watch('language', function() {
43-
i18nService.init($scope.language);
44+
$scope.$watch('language', function(newVal, oldVal) {
45+
if(newVal !== undefined) {
46+
i18nService.init(newVal, $scope.fallback);
47+
}
4448
});
4549

4650
//init momentJS i18n, default english
4751
var i18nService = new I18nService();
48-
i18nService.init($scope.language);
52+
i18nService.init($scope.language, $scope.fallback);
4953

5054
//progress bar
5155
$scope.displayProgressBar = 0;
@@ -99,6 +103,12 @@ var timerModule = angular.module('timer', [])
99103
}
100104
});
101105

106+
$scope.$watch('endTimeAttr', function(newValue, oldValue) {
107+
if (newValue !== oldValue && $scope.isRunning) {
108+
$scope.start();
109+
}
110+
});
111+
102112
$scope.start = $element[0].start = function () {
103113
$scope.startTime = $scope.startTimeAttr ? moment($scope.startTimeAttr) : moment();
104114
$scope.endTime = $scope.endTimeAttr ? moment($scope.endTimeAttr) : null;
@@ -336,10 +346,22 @@ app.factory('I18nService', function() {
336346
var I18nService = function() {};
337347

338348
I18nService.prototype.language = 'en';
349+
I18nService.prototype.fallback = 'en';
339350
I18nService.prototype.timeHumanizer = {};
340351

341-
I18nService.prototype.init = function init(lang){
352+
I18nService.prototype.init = function init(lang, fallback) {
353+
var supported_languages = humanizeDuration.getSupportedLanguages();
354+
355+
this.fallback = (fallback !== undefined) ? fallback : 'en';
356+
if (supported_languages.indexOf(fallback) === -1) {
357+
this.fallback = 'en';
358+
}
359+
342360
this.language = lang;
361+
if (supported_languages.indexOf(lang) === -1) {
362+
this.language = this.fallback;
363+
}
364+
343365
//moment init
344366
moment.locale(this.language); //@TODO maybe to remove, it should be handle by the user's application itself, and not inside the directive
345367

dist/angular-timer.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)