1
1
/**
2
- * angular-timer - v1.3.1 - 2015-03-30 1:00 PM
2
+ * angular-timer - v1.3.1 - 2015-05-19 12:41 AM
3
3
* https://github.com/siddii/angular-timer
4
4
*
5
5
* Copyright (c) 2015 Siddique Hameed
@@ -18,6 +18,7 @@ var timerModule = angular.module('timer', [])
18
18
finishCallback : '&finishCallback' ,
19
19
autoStart : '&autoStart' ,
20
20
language : '@?' ,
21
+ fallback : '@?' ,
21
22
maxTimeUnit : '='
22
23
} ,
23
24
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', [])
37
38
38
39
39
40
$scope . language = $scope . language || 'en' ;
41
+ $scope . fallback = $scope . fallback || 'en' ;
40
42
41
43
//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
+ }
44
48
} ) ;
45
49
46
50
//init momentJS i18n, default english
47
51
var i18nService = new I18nService ( ) ;
48
- i18nService . init ( $scope . language ) ;
52
+ i18nService . init ( $scope . language , $scope . fallback ) ;
49
53
50
54
//progress bar
51
55
$scope . displayProgressBar = 0 ;
@@ -99,6 +103,12 @@ var timerModule = angular.module('timer', [])
99
103
}
100
104
} ) ;
101
105
106
+ $scope . $watch ( 'endTimeAttr' , function ( newValue , oldValue ) {
107
+ if ( newValue !== oldValue && $scope . isRunning ) {
108
+ $scope . start ( ) ;
109
+ }
110
+ } ) ;
111
+
102
112
$scope . start = $element [ 0 ] . start = function ( ) {
103
113
$scope . startTime = $scope . startTimeAttr ? moment ( $scope . startTimeAttr ) : moment ( ) ;
104
114
$scope . endTime = $scope . endTimeAttr ? moment ( $scope . endTimeAttr ) : null ;
@@ -336,10 +346,22 @@ app.factory('I18nService', function() {
336
346
var I18nService = function ( ) { } ;
337
347
338
348
I18nService . prototype . language = 'en' ;
349
+ I18nService . prototype . fallback = 'en' ;
339
350
I18nService . prototype . timeHumanizer = { } ;
340
351
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
+
342
360
this . language = lang ;
361
+ if ( supported_languages . indexOf ( lang ) === - 1 ) {
362
+ this . language = this . fallback ;
363
+ }
364
+
343
365
//moment init
344
366
moment . locale ( this . language ) ; //@TODO maybe to remove, it should be handle by the user's application itself, and not inside the directive
345
367
0 commit comments