|
1 | 1 | /** |
2 | | - * angular-timer - v1.0.12 - 2014-02-10 9:05 AM |
| 2 | + * angular-timer - v1.0.12 - 2014-03-18 4:02 PM |
3 | 3 | * https://github.com/siddii/angular-timer |
4 | 4 | * |
5 | 5 | * Copyright (c) 2014 Siddique Hameed |
|
8 | 8 | angular.module('timer', []) |
9 | 9 | .directive('timer', ['$compile', function ($compile) { |
10 | 10 | return { |
11 | | - restrict: 'E', |
| 11 | + restrict: 'EAC', |
12 | 12 | replace: false, |
13 | 13 | scope: { |
14 | 14 | interval: '=interval', |
@@ -102,12 +102,18 @@ angular.module('timer', []) |
102 | 102 | }); |
103 | 103 |
|
104 | 104 | function calculateTimeUnits() { |
105 | | - $scope.seconds = Math.floor(($scope.millis / 1000) % 60); |
106 | | - $scope.minutes = Math.floor((($scope.millis / (60000)) % 60)); |
107 | | - $scope.hours = Math.floor((($scope.millis / (3600000)) % 24)); |
108 | | - $scope.days = Math.floor((($scope.millis / (3600000)) / 24)); |
109 | | - } |
| 105 | + $scope.seconds = Math.floor(($scope.millis / 1000) % 60); |
| 106 | + $scope.minutes = Math.floor((($scope.millis / (60000)) % 60)); |
| 107 | + $scope.hours = Math.floor((($scope.millis / (3600000)) % 24)); |
| 108 | + $scope.days = Math.floor((($scope.millis / (3600000)) / 24)); |
| 109 | + |
| 110 | + //add leading zero if number is smaller than 10 |
| 111 | + $scope.sseconds = $scope.seconds < 10 ? '0' + $scope.seconds : $scope.seconds; |
| 112 | + $scope.mminutes = $scope.minutes < 10 ? '0' + $scope.minutes : $scope.minutes; |
| 113 | + $scope.hhours = $scope.hours < 10 ? '0' + $scope.hours : $scope.hours; |
| 114 | + $scope.ddays = $scope.days < 10 ? '0' + $scope.days : $scope.days; |
110 | 115 |
|
| 116 | + } |
111 | 117 | //determine initial values of time units and add AddSeconds functionality |
112 | 118 | if ($scope.countdownattr) { |
113 | 119 | $scope.millis = $scope.countdownattr * 1000; |
|
0 commit comments