Skip to content

Commit e0c51cf

Browse files
committed
Merge remote-tracking branch 'origin/master' into gh-pages
2 parents d1c7f85 + 8d10339 commit e0c51cf

28 files changed

+1478
-835
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

Gruntfile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ module.exports = function (grunt) {
6767
compile_all_js: {
6868
src: [
6969
'<%= dist_dir %>/<%= pkg.name %>.min.js',
70-
'bower_components/momentjs/min/moment-with-locales.min.js',
70+
'bower_components/moment/min/moment-with-locales.min.js',
7171
'bower_components/humanize-duration/humanize-duration.js'
7272
],
7373
dest: '<%= dist_dir %>/assets/js/<%= pkg.name %>-all.min.js'
@@ -143,7 +143,7 @@ module.exports = function (grunt) {
143143
testserver: {
144144
options: {
145145
port: 3030,
146-
base: 'dist'
146+
base: '.'
147147
}
148148
}
149149
},

app/js/_timer.js

Lines changed: 112 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,19 @@ var timerModule = angular.module('timer', [])
1212
autoStart: '&autoStart',
1313
language: '@?',
1414
fallback: '@?',
15-
maxTimeUnit: '='
15+
maxTimeUnit: '=',
16+
seconds: '=?',
17+
minutes: '=?',
18+
hours: '=?',
19+
days: '=?',
20+
months: '=?',
21+
years: '=?',
22+
secondsS: '=?',
23+
minutesS: '=?',
24+
hoursS: '=?',
25+
daysS: '=?',
26+
monthsS: '=?',
27+
yearsS: '=?'
1628
},
1729
controller: ['$scope', '$element', '$attrs', '$timeout', 'I18nService', '$interpolate', 'progressBarService', function ($scope, $element, $attrs, $timeout, I18nService, $interpolate, progressBarService) {
1830

@@ -57,7 +69,7 @@ var timerModule = angular.module('timer', [])
5769
$scope.startTime = null;
5870
$scope.endTime = null;
5971
$scope.timeoutId = null;
60-
$scope.countdown = $scope.countdownattr && parseInt($scope.countdownattr, 10) >= 0 ? parseInt($scope.countdownattr, 10) : undefined;
72+
$scope.countdown = angular.isNumber($scope.countdownattr) && parseInt($scope.countdownattr, 10) >= 0 ? parseInt($scope.countdownattr, 10) : undefined;
6173
$scope.isRunning = false;
6274

6375
$scope.$on('timer-start', function () {
@@ -102,49 +114,80 @@ var timerModule = angular.module('timer', [])
102114
}
103115
});
104116

105-
$scope.start = $element[0].start = function () {
117+
$scope.start = function () {
106118
$scope.startTime = $scope.startTimeAttr ? moment($scope.startTimeAttr) : moment();
107119
$scope.endTime = $scope.endTimeAttr ? moment($scope.endTimeAttr) : null;
108-
if (!$scope.countdown) {
109-
$scope.countdown = $scope.countdownattr && parseInt($scope.countdownattr, 10) > 0 ? parseInt($scope.countdownattr, 10) : undefined;
120+
if (!angular.isNumber($scope.countdown)) {
121+
$scope.countdown = angular.isNumber($scope.countdownattr) && parseInt($scope.countdownattr, 10) > 0 ? parseInt($scope.countdownattr, 10) : undefined;
110122
}
111123
resetTimeout();
112124
tick();
113125
$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+
});
114134
};
115135

116-
$scope.resume = $element[0].resume = function () {
136+
$scope.resume = function () {
117137
resetTimeout();
118138
if ($scope.countdownattr) {
119139
$scope.countdown += 1;
120140
}
121141
$scope.startTime = moment().diff((moment($scope.stoppedTime).diff(moment($scope.startTime))));
122142
tick();
123143
$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+
});
124152
};
125153

126-
$scope.stop = $scope.pause = $element[0].stop = $element[0].pause = function () {
154+
$scope.stop = $scope.pause = function () {
127155
var timeoutId = $scope.timeoutId;
128156
$scope.clear();
129-
$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+
});
130165
};
131166

132-
$scope.clear = $element[0].clear = function () {
167+
$scope.clear = function () {
133168
// same as stop but without the event being triggered
134169
$scope.stoppedTime = moment();
135170
resetTimeout();
136171
$scope.timeoutId = null;
137172
$scope.isRunning = false;
138173
};
139174

140-
$scope.reset = $element[0].reset = function () {
175+
$scope.reset = function () {
141176
$scope.startTime = $scope.startTimeAttr ? moment($scope.startTimeAttr) : moment();
142177
$scope.endTime = $scope.endTimeAttr ? moment($scope.endTimeAttr) : null;
143-
$scope.countdown = $scope.countdownattr && parseInt($scope.countdownattr, 10) > 0 ? parseInt($scope.countdownattr, 10) : undefined;
178+
$scope.countdown = angular.isNumber($scope.countdownattr) && parseInt($scope.countdownattr, 10) > 0 ? parseInt($scope.countdownattr, 10) : undefined;
144179
resetTimeout();
145180
tick();
146181
$scope.isRunning = false;
147182
$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+
});
148191
};
149192

150193
$element.bind('$destroy', function () {
@@ -237,18 +280,15 @@ var timerModule = angular.module('timer', [])
237280
if ($scope.countdownattr) {
238281
$scope.millis = $scope.countdownattr * 1000;
239282

240-
$scope.addCDSeconds = $element[0].addCDSeconds = function (extraSeconds) {
283+
$scope.addCDSeconds = function (extraSeconds) {
241284
$scope.countdown += extraSeconds;
242-
$scope.$digest();
243285
if (!$scope.isRunning) {
244286
$scope.start();
245287
}
246288
};
247289

248290
$scope.$on('timer-add-cd-seconds', function (e, extraSeconds) {
249-
$timeout(function () {
250-
$scope.addCDSeconds(extraSeconds);
251-
});
291+
$scope.addCDSeconds(extraSeconds);
252292
});
253293

254294
$scope.$on('timer-set-countdown-seconds', function (e, countdownSeconds) {
@@ -294,11 +334,20 @@ var timerModule = angular.module('timer', [])
294334

295335
//We are not using $timeout for a reason. Please read here - https://github.com/siddii/angular-timer/pull/5
296336
$scope.timeoutId = setTimeout(function () {
297-
tick();
298-
$scope.$digest();
337+
tick();
338+
// since you choose not to use $timeout, at least preserve angular cycle two way data binding
339+
// by calling $scope.$apply() instead of $scope.$digest()
340+
$scope.$apply();
299341
}, $scope.interval - adjustment);
300342

301-
$scope.$emit('timer-tick', {timeoutId: $scope.timeoutId, millis: $scope.millis});
343+
$scope.$emit('timer-tick', {
344+
timeoutId: $scope.timeoutId,
345+
millis: $scope.millis,
346+
seconds: $scope.seconds,
347+
minutes: $scope.minutes,
348+
hours: $scope.hours,
349+
days: $scope.days
350+
});
302351

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

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

app/js/i18nService.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ app.factory('I18nService', function() {
2121
this.language = this.fallback;
2222
}
2323

24-
//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
24+
// It should be handle by the user's application itself, and not inside the directive
25+
// moment init
26+
// moment.locale(this.language);
2627

2728
//human duration init, using it because momentjs does not allow accurate time (
2829
// momentJS: a few moment ago, human duration : 4 seconds ago
@@ -44,13 +45,13 @@ app.factory('I18nService', function() {
4445

4546
if (typeof this.timeHumanizer != 'undefined'){
4647
time = {
47-
'millis' : this.timeHumanizer(diffFromAlarm, { units: ["milliseconds"] }),
48-
'seconds' : this.timeHumanizer(diffFromAlarm, { units: ["seconds"] }),
49-
'minutes' : this.timeHumanizer(diffFromAlarm, { units: ["minutes", "seconds"] }) ,
50-
'hours' : this.timeHumanizer(diffFromAlarm, { units: ["hours", "minutes", "seconds"] }) ,
51-
'days' : this.timeHumanizer(diffFromAlarm, { units: ["days", "hours", "minutes", "seconds"] }) ,
52-
'months' : this.timeHumanizer(diffFromAlarm, { units: ["months", "days", "hours", "minutes", "seconds"] }) ,
53-
'years' : this.timeHumanizer(diffFromAlarm, { units: ["years", "months", "days", "hours", "minutes", "seconds"] })
48+
'millis' : this.timeHumanizer(diffFromAlarm, { units: ["ms"] }),
49+
'seconds' : this.timeHumanizer(diffFromAlarm, { units: ["s"] }),
50+
'minutes' : this.timeHumanizer(diffFromAlarm, { units: ["m", "s"] }) ,
51+
'hours' : this.timeHumanizer(diffFromAlarm, { units: ["h", "m", "s"] }) ,
52+
'days' : this.timeHumanizer(diffFromAlarm, { units: ["d", "h", "m", "s"] }) ,
53+
'months' : this.timeHumanizer(diffFromAlarm, { units: ["mo", "d", "h", "m", "s"] }) ,
54+
'years' : this.timeHumanizer(diffFromAlarm, { units: ["y", "mo", "d", "h", "m", "s"] })
5455
};
5556
}
5657
else {

bower.json

Lines changed: 8 additions & 5 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": {
@@ -10,8 +10,8 @@
1010
},
1111
"dependencies": {
1212
"angular": ">= 1.0.7",
13-
"momentjs": "~2.9.0",
14-
"humanize-duration": "~2.8.0"
13+
"moment": "~2.9.0",
14+
"humanize-duration": "~3.10.0"
1515
},
1616
"devDependencies": {
1717
"bootstrap": "2.3.2",
@@ -22,5 +22,8 @@
2222
"ignore": [
2323
"node_modules",
2424
"bower_components"
25-
]
25+
],
26+
"resolutions": {
27+
"moment": "~2.9.0"
28+
}
2629
}

bower_components/humanize-duration/.bower.json

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,26 @@
22
"name": "humanize-duration",
33
"authors": [
44
"Evan Hahn <[email protected]> (http://evanhahn.com)",
5+
"Óli Tómas Freysson (https://github.com/olitomas)",
56
"Martin Prins (https://github.com/magarcia)",
67
"Filipi Siqueira (https://github.com/filipi777)",
78
"Peter Rekdal Sunde (https://github.com/peters)",
89
"Michał Janiec (https://github.com/mjjaniec)",
910
"Eileen Li (https://github.com/eileen3)",
1011
"Tommy Brunn (https://github.com/Nevon)",
1112
"Giovanni Pellerano (https://github.com/evilaliv3)",
12-
"Rahma Sghaier (https://twitter.com/sghaierrahma)"
13+
"Rahma Sghaier (https://twitter.com/sghaierrahma)",
14+
"Evgenios Kastanias (https://github.com/evgenios)",
15+
"Oleksii Mylotskyi (https://github.com/spalax)",
16+
"Matthew Brandly (https://github.com/brandly)",
17+
"Patrik Simek (https://github.com/patriksimek)",
18+
"Toni Helminen (https://github.com/tonihelminen)",
19+
"Vidmantas Drasutis (https://github.com/drasius2)",
20+
"Manh Tuan (https://github.com/J2TeaM)",
21+
"Leonard Lee (https://github.com/sheeeng)",
22+
"Jesse Jackson (https://github.com/jsejcksn)"
1323
],
14-
"version": "2.8.0",
24+
"version": "3.10.0",
1525
"description": "Convert millisecond durations to English and many other languages.",
1626
"main": "humanize-duration.js",
1727
"homepage": "https://github.com/EvanHahn/HumanizeDuration.js",
@@ -26,7 +36,7 @@
2636
"years",
2737
"months"
2838
],
29-
"license": "WTFPL",
39+
"license": "Unlicense",
3040
"ignore": [
3141
"**/.*",
3242
"node_modules",
@@ -38,13 +48,13 @@
3848
"type": "git",
3949
"url": "git://github.com/EvanHahn/HumanizeDuration.js.git"
4050
},
41-
"_release": "2.8.0",
51+
"_release": "3.10.0",
4252
"_resolution": {
4353
"type": "version",
44-
"tag": "v2.8.0",
45-
"commit": "dcab6eaf100968c008351c70ae3dea9a8a86d929"
54+
"tag": "v3.10.0",
55+
"commit": "18243414dc4ce75d93f6a501f0e88130f2126421"
4656
},
47-
"_source": "git://github.com/EvanHahn/HumanizeDuration.js.git",
48-
"_target": "~2.8.0",
57+
"_source": "https://github.com/EvanHahn/HumanizeDuration.js.git",
58+
"_target": "~3.10.0",
4959
"_originalSource": "humanize-duration"
5060
}

bower_components/humanize-duration/CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ How to contribute
33

44
This assumes you have Node and npm installed.
55

6-
1. Fork the repo.
6+
1. Fork the repo on GitHub.
77
1. Clone the repo.
88
1. Run `npm install`.
9-
1. Make your changes. Please add tests! If adding a new language, define some tests in *test/definitions*.
9+
1. Make your changes. _Please add tests!_ If adding a new language, define some tests in *test/definitions*.
1010
1. Update `HISTORY.md` with your changes.
1111
1. If adding a new language, add it to the README.
12-
1. Credit yourself in the README and in `package.json`.
12+
1. Credit yourself in the README, in `package.json`, and in `bower.json`.
1313
1. Make sure `npm test` doesn't have any errors.
1414
1. Make sure `npm run hint` doesn't give any JSHint errors.
1515
1. Submit your pull request!

0 commit comments

Comments
 (0)