Skip to content

Commit 4201ef0

Browse files
committed
Bower configuration
creating release folder with original timer.js file.
1 parent 3e45a7e commit 4201ef0

5 files changed

Lines changed: 209 additions & 10 deletions

File tree

‎Gruntfile.js‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,25 @@ module.exports = function ( grunt ) {
104104
expand: true
105105
}
106106
]
107+
},
108+
copy_appjs: {
109+
files: [
110+
{
111+
src : '<%= build_dir %>/app/js/timer.js',
112+
dest: '<%= compile_dir %>/',
113+
cwd: '.',
114+
filter: 'isFile',
115+
flatten: true,
116+
expand: true,
117+
rename: function(dest, src) {
118+
return dest + '<%= pkg.name %>.js';
119+
}
120+
}
121+
]
107122
}
108123
},
109124

125+
110126
/**
111127
* `grunt concat` concatenates multiple source files into a single file.
112128
*/
@@ -124,7 +140,7 @@ module.exports = function ( grunt ) {
124140
'<%= build_dir %>/app/**/*.js',
125141
'module.suffix'
126142
],
127-
dest: '<%= compile_dir %>/<%= pkg.name %>.js'
143+
dest: '<%= compile_dir %>/<%= pkg.name %>.min.js'
128144
}
129145
},
130146

@@ -242,7 +258,8 @@ module.exports = function ( grunt ) {
242258
*/
243259
grunt.registerTask( 'build', [
244260
'clean', 'jshint',
245-
'copy:build_appjs'
261+
'copy:build_appjs',
262+
'copy:copy_appjs'
246263

247264
]);
248265

‎angular-timer.js‎

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
angular.module('timer', [])
2+
.directive('timer', function ($timeout, $compile) {
3+
return {
4+
restrict: 'E',
5+
replace: false,
6+
scope: {
7+
interval: '=interval',
8+
startTimeAttr: '=startTime',
9+
countdownattr: '=countdown'
10+
},
11+
controller: function ($scope, $element) {
12+
if ($element.html().trim().length === 0) {
13+
$element.append($compile('<span>{{millis}}</span>')($scope));
14+
}
15+
16+
$scope.startTime = null;
17+
$scope.timeoutId = null;
18+
$scope.countdown = $scope.countdownattr && parseInt($scope.countdownattr, 10) > 0 ? parseInt($scope.countdownattr, 10) : undefined;
19+
$scope.isRunning = false;
20+
21+
$scope.$on('timer-start', function () {
22+
$scope.start();
23+
});
24+
25+
$scope.$on('timer-resume', function () {
26+
$scope.resume();
27+
});
28+
29+
$scope.$on('timer-stop', function () {
30+
$scope.stop();
31+
});
32+
33+
function resetTimeout() {
34+
if ($scope.timeoutId) {
35+
clearTimeout($scope.timeoutId);
36+
}
37+
}
38+
39+
$scope.start = $element[0].start = function () {
40+
$scope.startTime = $scope.startTimeAttr ? new Date($scope.startTimeAttr) : new Date();
41+
resetTimeout();
42+
tick();
43+
};
44+
45+
$scope.resume = $element[0].resume = function () {
46+
resetTimeout();
47+
$scope.startTime = new Date() - ($scope.stoppedTime - $scope.startTime);
48+
tick();
49+
};
50+
51+
$scope.stop = $element[0].stop = function () {
52+
$scope.stoppedTime = new Date();
53+
resetTimeout();
54+
$scope.timeoutId = null;
55+
};
56+
57+
$element.bind('$destroy', function () {
58+
resetTimeout();
59+
});
60+
61+
var tick = function () {
62+
if ($scope.countdown > 0) {
63+
$scope.countdown--;
64+
}
65+
else if ($scope.countdown <= 0) {
66+
$scope.stop();
67+
}
68+
69+
$scope.millis = new Date() - $scope.startTime;
70+
71+
if ($scope.countdown > 0) {
72+
$scope.millis = $scope.countdown * 1000;
73+
}
74+
75+
$scope.seconds = Math.floor(($scope.millis / 1000) % 60);
76+
$scope.minutes = Math.floor((($scope.millis / (1000 * 60)) % 60));
77+
$scope.hours = Math.floor((($scope.millis / (1000 * 60 * 60)) % 24));
78+
$scope.days = Math.floor((($scope.millis / (1000 * 60 * 60)) / 24));
79+
//We are not using $timeout for a reason. Please read here - https://github.com/siddii/angular-timer/pull/5
80+
$scope.timeoutId = setTimeout(function () {
81+
tick();
82+
$scope.$apply();
83+
}, $scope.interval);
84+
85+
$scope.$emit('timer-tick', {timeoutId: $scope.timeoutId, millis: $scope.millis});
86+
};
87+
88+
$scope.start();
89+
}
90+
};
91+
});

‎bootstrap/img/Thumbs.db‎

23.5 KB
Binary file not shown.

‎release/angular-timer.js‎

Lines changed: 91 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,91 @@
1-
/**
2-
* angular-timer - v1.0.0 - 2013-07-22
3-
* https://github.com/siddii/angular-timer
4-
*
5-
* Copyright (c) 2013 Siddique Hameed
6-
* Licensed MIT <https://github.com/siddii/angular-timer>
7-
*/
8-
angular.module("timer",[]).directive("timer",["$timeout","$compile",function(a,b){return{restrict:"E",replace:!1,scope:{interval:"=interval",startTimeAttr:"=startTime",countdownattr:"=countdown"},controller:["$scope","$element",function(a,c){function d(){a.timeoutId&&clearTimeout(a.timeoutId)}0===c.html().trim().length&&c.append(b("<span>{{millis}}</span>")(a)),a.startTime=null,a.timeoutId=null,a.countdown=a.countdownattr&&parseInt(a.countdownattr,10)>0?parseInt(a.countdownattr,10):void 0,a.isRunning=!1,a.$on("timer-start",function(){a.start()}),a.$on("timer-resume",function(){a.resume()}),a.$on("timer-stop",function(){a.stop()}),a.start=c[0].start=function(){a.startTime=a.startTimeAttr?new Date(a.startTimeAttr):new Date,d(),e()},a.resume=c[0].resume=function(){d(),a.startTime=new Date-(a.stoppedTime-a.startTime),e()},a.stop=c[0].stop=function(){a.stoppedTime=new Date,d(),a.timeoutId=null},c.bind("$destroy",function(){d()});var e=function(){a.countdown>0?a.countdown--:a.countdown<=0&&a.stop(),a.millis=new Date-a.startTime,a.countdown>0&&(a.millis=1e3*a.countdown),a.seconds=Math.floor(a.millis/1e3%60),a.minutes=Math.floor(a.millis/6e4%60),a.hours=Math.floor(a.millis/36e5%24),a.days=Math.floor(a.millis/36e5/24),a.timeoutId=setTimeout(function(){e(),a.$apply()},a.interval),a.$emit("timer-tick",{timeoutId:a.timeoutId,millis:a.millis})};a.start()}]}}]);
1+
angular.module('timer', [])
2+
.directive('timer', function ($timeout, $compile) {
3+
return {
4+
restrict: 'E',
5+
replace: false,
6+
scope: {
7+
interval: '=interval',
8+
startTimeAttr: '=startTime',
9+
countdownattr: '=countdown'
10+
},
11+
controller: function ($scope, $element) {
12+
if ($element.html().trim().length === 0) {
13+
$element.append($compile('<span>{{millis}}</span>')($scope));
14+
}
15+
16+
$scope.startTime = null;
17+
$scope.timeoutId = null;
18+
$scope.countdown = $scope.countdownattr && parseInt($scope.countdownattr, 10) > 0 ? parseInt($scope.countdownattr, 10) : undefined;
19+
$scope.isRunning = false;
20+
21+
$scope.$on('timer-start', function () {
22+
$scope.start();
23+
});
24+
25+
$scope.$on('timer-resume', function () {
26+
$scope.resume();
27+
});
28+
29+
$scope.$on('timer-stop', function () {
30+
$scope.stop();
31+
});
32+
33+
function resetTimeout() {
34+
if ($scope.timeoutId) {
35+
clearTimeout($scope.timeoutId);
36+
}
37+
}
38+
39+
$scope.start = $element[0].start = function () {
40+
$scope.startTime = $scope.startTimeAttr ? new Date($scope.startTimeAttr) : new Date();
41+
resetTimeout();
42+
tick();
43+
};
44+
45+
$scope.resume = $element[0].resume = function () {
46+
resetTimeout();
47+
$scope.startTime = new Date() - ($scope.stoppedTime - $scope.startTime);
48+
tick();
49+
};
50+
51+
$scope.stop = $element[0].stop = function () {
52+
$scope.stoppedTime = new Date();
53+
resetTimeout();
54+
$scope.timeoutId = null;
55+
};
56+
57+
$element.bind('$destroy', function () {
58+
resetTimeout();
59+
});
60+
61+
var tick = function () {
62+
if ($scope.countdown > 0) {
63+
$scope.countdown--;
64+
}
65+
else if ($scope.countdown <= 0) {
66+
$scope.stop();
67+
}
68+
69+
$scope.millis = new Date() - $scope.startTime;
70+
71+
if ($scope.countdown > 0) {
72+
$scope.millis = $scope.countdown * 1000;
73+
}
74+
75+
$scope.seconds = Math.floor(($scope.millis / 1000) % 60);
76+
$scope.minutes = Math.floor((($scope.millis / (1000 * 60)) % 60));
77+
$scope.hours = Math.floor((($scope.millis / (1000 * 60 * 60)) % 24));
78+
$scope.days = Math.floor((($scope.millis / (1000 * 60 * 60)) / 24));
79+
//We are not using $timeout for a reason. Please read here - https://github.com/siddii/angular-timer/pull/5
80+
$scope.timeoutId = setTimeout(function () {
81+
tick();
82+
$scope.$apply();
83+
}, $scope.interval);
84+
85+
$scope.$emit('timer-tick', {timeoutId: $scope.timeoutId, millis: $scope.millis});
86+
};
87+
88+
$scope.start();
89+
}
90+
};
91+
});

‎release/angular-timer.min.js‎

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)