Skip to content

Commit bc7b707

Browse files
authored
Merge pull request #1 from siddii/master
1.3.5
2 parents 2e94082 + a704c4e commit bc7b707

File tree

12 files changed

+250
-126
lines changed

12 files changed

+250
-126
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ node_js:
55
notifications:
66
email: true
77

8-
before_script:
8+
install:
9+
- npm install
910
- npm install -g grunt-cli
1011
- npm install bower
1112
- bower install
12-
1313
script:
1414
- grunt tests

app/js/_timer.js

Lines changed: 91 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ var timerModule = angular.module('timer', [])
114114
}
115115
});
116116

117-
$scope.start = $element[0].start = function () {
117+
$scope.start = function () {
118118
$scope.startTime = $scope.startTimeAttr ? moment($scope.startTimeAttr) : moment();
119119
$scope.endTime = $scope.endTimeAttr ? moment($scope.endTimeAttr) : null;
120120
if (!angular.isNumber($scope.countdown)) {
@@ -123,40 +123,71 @@ var timerModule = angular.module('timer', [])
123123
resetTimeout();
124124
tick();
125125
$scope.isRunning = true;
126+
$scope.$emit('timer-started', {
127+
timeoutId: $scope.timeoutId,
128+
millis: $scope.millis,
129+
seconds: $scope.seconds,
130+
minutes: $scope.minutes,
131+
hours: $scope.hours,
132+
days: $scope.days
133+
});
126134
};
127135

128-
$scope.resume = $element[0].resume = function () {
136+
$scope.resume = function () {
129137
resetTimeout();
130138
if ($scope.countdownattr) {
131139
$scope.countdown += 1;
132140
}
133141
$scope.startTime = moment().diff((moment($scope.stoppedTime).diff(moment($scope.startTime))));
134142
tick();
135143
$scope.isRunning = true;
144+
$scope.$emit('timer-started', {
145+
timeoutId: $scope.timeoutId,
146+
millis: $scope.millis,
147+
seconds: $scope.seconds,
148+
minutes: $scope.minutes,
149+
hours: $scope.hours,
150+
days: $scope.days
151+
});
136152
};
137153

138-
$scope.stop = $scope.pause = $element[0].stop = $element[0].pause = function () {
154+
$scope.stop = $scope.pause = function () {
139155
var timeoutId = $scope.timeoutId;
140156
$scope.clear();
141-
$scope.$emit('timer-stopped', {timeoutId: timeoutId, millis: $scope.millis, seconds: $scope.seconds, minutes: $scope.minutes, hours: $scope.hours, days: $scope.days});
157+
$scope.$emit('timer-stopped', {
158+
timeoutId: timeoutId,
159+
millis: $scope.millis,
160+
seconds: $scope.seconds,
161+
minutes: $scope.minutes,
162+
hours: $scope.hours,
163+
days: $scope.days
164+
});
142165
};
143166

144-
$scope.clear = $element[0].clear = function () {
167+
$scope.clear = function () {
145168
// same as stop but without the event being triggered
146169
$scope.stoppedTime = moment();
147170
resetTimeout();
148171
$scope.timeoutId = null;
149172
$scope.isRunning = false;
150173
};
151174

152-
$scope.reset = $element[0].reset = function () {
175+
$scope.reset = function () {
153176
$scope.startTime = $scope.startTimeAttr ? moment($scope.startTimeAttr) : moment();
154177
$scope.endTime = $scope.endTimeAttr ? moment($scope.endTimeAttr) : null;
155178
$scope.countdown = angular.isNumber($scope.countdownattr) && parseInt($scope.countdownattr, 10) > 0 ? parseInt($scope.countdownattr, 10) : undefined;
156179
resetTimeout();
157180
tick();
158181
$scope.isRunning = false;
159182
$scope.clear();
183+
$scope.$emit('timer-reset', {
184+
timeoutId: timeoutId,
185+
millis: $scope.millis,
186+
seconds: $scope.seconds,
187+
minutes: $scope.minutes,
188+
hours: $scope.hours,
189+
days: $scope.days
190+
});
160191
};
161192

162193
$element.bind('$destroy', function () {
@@ -249,18 +280,15 @@ var timerModule = angular.module('timer', [])
249280
if ($scope.countdownattr) {
250281
$scope.millis = $scope.countdownattr * 1000;
251282

252-
$scope.addCDSeconds = $element[0].addCDSeconds = function (extraSeconds) {
283+
$scope.addCDSeconds = function (extraSeconds) {
253284
$scope.countdown += extraSeconds;
254-
$scope.$digest();
255285
if (!$scope.isRunning) {
256286
$scope.start();
257287
}
258288
};
259289

260290
$scope.$on('timer-add-cd-seconds', function (e, extraSeconds) {
261-
$timeout(function () {
262-
$scope.addCDSeconds(extraSeconds);
263-
});
291+
$scope.addCDSeconds(extraSeconds);
264292
});
265293

266294
$scope.$on('timer-set-countdown-seconds', function (e, countdownSeconds) {
@@ -310,7 +338,14 @@ var timerModule = angular.module('timer', [])
310338
$scope.$digest();
311339
}, $scope.interval - adjustment);
312340

313-
$scope.$emit('timer-tick', {timeoutId: $scope.timeoutId, millis: $scope.millis, timerElement: $element[0]});
341+
$scope.$emit('timer-tick', {
342+
timeoutId: $scope.timeoutId,
343+
millis: $scope.millis,
344+
seconds: $scope.seconds,
345+
minutes: $scope.minutes,
346+
hours: $scope.hours,
347+
days: $scope.days
348+
});
314349

315350
if ($scope.countdown > 0) {
316351
$scope.countdown--;
@@ -337,7 +372,50 @@ var timerModule = angular.module('timer', [])
337372
}
338373
}]
339374
};
340-
}]);
375+
}])
376+
.directive('timerControls', function() {
377+
return {
378+
restrict: 'EA',
379+
scope: true,
380+
controller: ['$scope', function($scope) {
381+
$scope.timerStatus = "reset";
382+
$scope.$on('timer-started', function() {
383+
$scope.timerStatus = "started";
384+
});
385+
$scope.$on('timer-stopped', function() {
386+
$scope.timerStatus = "stopped";
387+
});
388+
$scope.$on('timer-reset', function() {
389+
$scope.timerStatus = "reset";
390+
});
391+
$scope.timerStart = function() {
392+
$scope.$broadcast('timer-start');
393+
};
394+
$scope.timerStop = function() {
395+
$scope.$broadcast('timer-stop');
396+
};
397+
$scope.timerResume = function() {
398+
$scope.$broadcast('timer-resume');
399+
};
400+
$scope.timerToggle = function() {
401+
switch ($scope.timerStatus) {
402+
case "started":
403+
$scope.timerStop();
404+
break;
405+
case "stopped":
406+
$scope.timerResume();
407+
break;
408+
case "reset":
409+
$scope.timerStart();
410+
break;
411+
}
412+
};
413+
$scope.timerAddCDSeconds = function(extraSeconds) {
414+
$scope.$broadcast('timer-add-cd-seconds', extraSeconds);
415+
};
416+
}]
417+
};
418+
});
341419

342420
/* commonjs package manager support (eg componentjs) */
343421
if (typeof module !== "undefined" && typeof exports !== "undefined" && module.exports === exports){

app/js/i18nService.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ app.factory('I18nService', function() {
2222
}
2323

2424
//moment init
25-
moment.locale(this.language); //@TODO maybe to remove, it should be handle by the user's application itself, and not inside the directive
25+
moment.locale(this.language); // @TODO maybe to remove, it should be handle by the user's application itself, and not inside the directive
2626

2727
//human duration init, using it because momentjs does not allow accurate time (
2828
// momentJS: a few moment ago, human duration : 4 seconds ago

bower.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"author": "Siddique Hameed",
2+
"author": "Adrian Wardell",
33
"name": "angular-timer",
4-
"version": "1.3.3",
4+
"version": "1.3.4",
55
"homepage": "https://github.com/siddii/angular-timer",
66
"description": "Angular-Timer : A simple AngularJS directive demonstrating re-usability & interoperability",
77
"repository": {

0 commit comments

Comments
 (0)