11/**
2- * angular-timer - v1.3.5 - 2017-02-14 1:19 PM
2+ * angular-timer - v1.3.5 - 2017-02-15 4:06 PM
33 * https://github.com/siddii/angular-timer
44 *
55 * Copyright (c) 2017 Adrian Wardell
@@ -130,6 +130,14 @@ var timerModule = angular.module('timer', [])
130130 resetTimeout ( ) ;
131131 tick ( ) ;
132132 $scope . isRunning = true ;
133+ $scope . $emit ( 'timer-started' , {
134+ timeoutId : $scope . timeoutId ,
135+ millis : $scope . millis ,
136+ seconds : $scope . seconds ,
137+ minutes : $scope . minutes ,
138+ hours : $scope . hours ,
139+ days : $scope . days
140+ } ) ;
133141 } ;
134142
135143 $scope . resume = function ( ) {
@@ -140,12 +148,27 @@ var timerModule = angular.module('timer', [])
140148 $scope . startTime = moment ( ) . diff ( ( moment ( $scope . stoppedTime ) . diff ( moment ( $scope . startTime ) ) ) ) ;
141149 tick ( ) ;
142150 $scope . isRunning = true ;
151+ $scope . $emit ( 'timer-started' , {
152+ timeoutId : $scope . timeoutId ,
153+ millis : $scope . millis ,
154+ seconds : $scope . seconds ,
155+ minutes : $scope . minutes ,
156+ hours : $scope . hours ,
157+ days : $scope . days
158+ } ) ;
143159 } ;
144160
145161 $scope . stop = $scope . pause = function ( ) {
146162 var timeoutId = $scope . timeoutId ;
147163 $scope . clear ( ) ;
148- $scope . $emit ( 'timer-stopped' , { timeoutId : timeoutId , millis : $scope . millis , seconds : $scope . seconds , minutes : $scope . minutes , hours : $scope . hours , days : $scope . days } ) ;
164+ $scope . $emit ( 'timer-stopped' , {
165+ timeoutId : timeoutId ,
166+ millis : $scope . millis ,
167+ seconds : $scope . seconds ,
168+ minutes : $scope . minutes ,
169+ hours : $scope . hours ,
170+ days : $scope . days
171+ } ) ;
149172 } ;
150173
151174 $scope . clear = function ( ) {
@@ -164,6 +187,14 @@ var timerModule = angular.module('timer', [])
164187 tick ( ) ;
165188 $scope . isRunning = false ;
166189 $scope . clear ( ) ;
190+ $scope . $emit ( 'timer-reset' , {
191+ timeoutId : timeoutId ,
192+ millis : $scope . millis ,
193+ seconds : $scope . seconds ,
194+ minutes : $scope . minutes ,
195+ hours : $scope . hours ,
196+ days : $scope . days
197+ } ) ;
167198 } ;
168199
169200 $element . bind ( '$destroy' , function ( ) {
@@ -258,16 +289,13 @@ var timerModule = angular.module('timer', [])
258289
259290 $scope . addCDSeconds = function ( extraSeconds ) {
260291 $scope . countdown += extraSeconds ;
261- $scope . $digest ( ) ;
262292 if ( ! $scope . isRunning ) {
263293 $scope . start ( ) ;
264294 }
265295 } ;
266296
267297 $scope . $on ( 'timer-add-cd-seconds' , function ( e , extraSeconds ) {
268- $timeout ( function ( ) {
269- $scope . addCDSeconds ( extraSeconds ) ;
270- } ) ;
298+ $scope . addCDSeconds ( extraSeconds ) ;
271299 } ) ;
272300
273301 $scope . $on ( 'timer-set-countdown-seconds' , function ( e , countdownSeconds ) {
@@ -317,7 +345,14 @@ var timerModule = angular.module('timer', [])
317345 $scope . $digest ( ) ;
318346 } , $scope . interval - adjustment ) ;
319347
320- $scope . $emit ( 'timer-tick' , { timeoutId : $scope . timeoutId , millis : $scope . millis } ) ;
348+ $scope . $emit ( 'timer-tick' , {
349+ timeoutId : $scope . timeoutId ,
350+ millis : $scope . millis ,
351+ seconds : $scope . seconds ,
352+ minutes : $scope . minutes ,
353+ hours : $scope . hours ,
354+ days : $scope . days
355+ } ) ;
321356
322357 if ( $scope . countdown > 0 ) {
323358 $scope . countdown -- ;
@@ -344,7 +379,50 @@ var timerModule = angular.module('timer', [])
344379 }
345380 } ]
346381 } ;
347- } ] ) ;
382+ } ] )
383+ . directive ( 'timerControls' , function ( ) {
384+ return {
385+ restrict : 'EA' ,
386+ scope : true ,
387+ controller : [ '$scope' , function ( $scope ) {
388+ $scope . timerStatus = "reset" ;
389+ $scope . $on ( 'timer-started' , function ( ) {
390+ $scope . timerStatus = "started" ;
391+ } ) ;
392+ $scope . $on ( 'timer-stopped' , function ( ) {
393+ $scope . timerStatus = "stopped" ;
394+ } ) ;
395+ $scope . $on ( 'timer-reset' , function ( ) {
396+ $scope . timerStatus = "reset" ;
397+ } ) ;
398+ $scope . start = function ( ) {
399+ $scope . $broadcast ( 'timer-start' ) ;
400+ } ;
401+ $scope . stop = function ( ) {
402+ $scope . $broadcast ( 'timer-stop' ) ;
403+ } ;
404+ $scope . resume = function ( ) {
405+ $scope . $broadcast ( 'timer-resume' ) ;
406+ } ;
407+ $scope . toggle = function ( ) {
408+ switch ( $scope . timerStatus ) {
409+ case "started" :
410+ $scope . stop ( ) ;
411+ break ;
412+ case "stopped" :
413+ $scope . resume ( ) ;
414+ break ;
415+ case "reset" :
416+ $scope . start ( ) ;
417+ break ;
418+ }
419+ } ;
420+ $scope . addCDSeconds = function ( extraSeconds ) {
421+ $scope . $broadcast ( 'timer-add-cd-seconds' , extraSeconds ) ;
422+ } ;
423+ } ]
424+ } ;
425+ } ) ;
348426
349427/* commonjs package manager support (eg componentjs) */
350428if ( typeof module !== "undefined" && typeof exports !== "undefined" && module . exports === exports ) {
0 commit comments