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
0 commit comments