From 72a39489127e3d1f9eb8fe0c7d7c558480f27085 Mon Sep 17 00:00:00 2001 From: bunbutter Date: Thu, 28 Jul 2016 23:19:18 -0400 Subject: [PATCH] Option for the user to specify the timer pattern --- dist/js/timer.directive.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/js/timer.directive.min.js b/dist/js/timer.directive.min.js index 1b8c6cd..34c7556 100644 --- a/dist/js/timer.directive.min.js +++ b/dist/js/timer.directive.min.js @@ -1 +1 @@ -!function(){"use strict";function timer($interval){return{restrict:"E",link:function(scope,element,attrs){function setHtml(){element.html(getHumanizedDuration())}function startTimer(){interval=$interval(function(){duration=Number(duration)+Number(1e3),setHtml(),scope.$broadcast("timer-updated",duration)},1e3)}function stopTimer(){$interval.cancel(interval),scope.$broadcast("timer-stopped",duration),setHtml(),interval=void 0}function resetTimer(){$interval.cancel(interval),duration=0,setHtml(),scope.$broadcast("timer-reset"),interval=void 0}function destroyTimer(){$interval.cancel(interval),duration=0,scope.$broadcast("timer-destroyed"),interval=void 0}function getHumanizedDuration(){var inSeconds=duration/1e3,hours=Math.floor(inSeconds/3600).toFixed(0),minutes=Math.floor((inSeconds-3600*hours)/60).toFixed(0),seconds=inSeconds-3600*hours-(60*minutes).toFixed(0);return hours<10&&(hours="0"+hours),minutes<10&&(minutes="0"+minutes),seconds<10&&(seconds="0"+seconds),hours+":"+minutes+":"+seconds}var interval,duration=0;attrs.initDuration&&(duration=attrs.initDuration),setHtml(),element.on("$destroy",function(){destroyTimer()}),scope.$on("start-timer",function(event){startTimer()}),scope.$on("stop-timer",function(event){stopTimer()}),scope.$on("reset-timer",function(event){resetTimer()})}}}angular.module("angularjs-timer",[]).directive("timer",["$interval",timer])}(); \ No newline at end of file +!function(){"use strict";function timer($interval){return{restrict:"E",link:function(scope,element,attrs){function setHtml(){element.html(getHumanizedDuration())}function startTimer(){interval=$interval(function(){duration=Number(duration)+Number(1e3),setHtml(),scope.$broadcast("timer-updated",duration)},1e3)}function stopTimer(){$interval.cancel(interval),scope.$broadcast("timer-stopped",duration),setHtml(),interval=void 0}function resetTimer(){$interval.cancel(interval),duration=0,setHtml(),scope.$broadcast("timer-reset"),interval=void 0}function destroyTimer(){$interval.cancel(interval),duration=0,scope.$broadcast("timer-destroyed"),interval=void 0}function getHumanizedDuration(){var inSeconds=duration/1e3,displayTime=displayPattern,hours=0,minutes=0;if(displayTime.indexOf("hh")>=0&&(hours=Math.floor(inSeconds/3600).toFixed(0),displayTime=hours<10?displayTime.replace(/hh/g,"0"+String(hours)):displayTime.replace(/hh/g,String(hours))),displayTime.indexOf("mm")>=0&&(minutes=Math.floor((inSeconds-3600*hours)/60).toFixed(0),displayTime=minutes<10?displayTime.replace(/mm/g,"0"+String(minutes)):displayTime.replace(/mm/g,String(minutes))),displayTime.indexOf("ss")>=0){var seconds=inSeconds-3600*hours-(60*minutes).toFixed(0);displayTime=seconds<10?displayTime.replace(/ss/g,"0"+String(seconds)):displayTime.replace(/ss/g,String(seconds))}return displayTime}var interval,duration=0;attrs.initDuration&&(duration=attrs.initDuration);var displayPattern="hh:mm:ss";attrs.displayPattern&&(displayPattern=attrs.displayPattern),setHtml(),element.on("$destroy",function(){destroyTimer()}),scope.$on("start-timer",function(event){startTimer()}),scope.$on("stop-timer",function(event){stopTimer()}),scope.$on("reset-timer",function(event){resetTimer()})}}}angular.module("angularjs-timer",[]).directive("timer",["$interval",timer])}(); \ No newline at end of file