Skip to content

Commit dd537e2

Browse files
committed
Merge branch 'itslenny-master'
2 parents cd809d3 + e5987f6 commit dd537e2

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

app/js/timer.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var timerModule = angular.module('timer', [])
1+
angular.module('timer', [])
22
.directive('timer', ['$compile', function ($compile) {
33
return {
44
restrict: 'EAC',
@@ -8,6 +8,7 @@ var timerModule = angular.module('timer', [])
88
startTimeAttr: '=startTime',
99
endTimeAttr: '=endTime',
1010
countdownattr: '=countdown',
11+
finishCallback: '&finishCallback',
1112
autoStart: '&autoStart',
1213
maxTimeUnit: '='
1314
},
@@ -219,6 +220,7 @@ var timerModule = angular.module('timer', [])
219220
$scope.stop();
220221
$scope.millis = 0;
221222
calculateTimeUnits();
223+
if($scope.finishCallback) $scope.$eval($scope.finishCallback);
222224
return;
223225
}
224226
calculateTimeUnits();
@@ -236,6 +238,7 @@ var timerModule = angular.module('timer', [])
236238
}
237239
else if ($scope.countdown <= 0) {
238240
$scope.stop();
241+
if($scope.finishCallback) $scope.$eval($scope.finishCallback);
239242
}
240243
};
241244

docs/docs.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,13 @@ angular.module('timer-demo',['timer']).controller('TimerDemoController',['$scope
3434
}
3535
});
3636
};
37+
38+
$scope.callbackTimer={};
39+
$scope.callbackTimer.status='Running';
40+
$scope.callbackTimer.callbackCount=0;
41+
$scope.callbackTimer.finished=function(){
42+
$scope.callbackTimer.status='COMPLETE!!';
43+
$scope.callbackTimer.callbackCount++;
44+
$scope.$apply();
45+
};
3746
}]);

index.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,26 @@ <h3 class="WithoutMaxTimeUnit">
214214
</div>
215215
</section>
216216

217+
218+
<section id="finish-callback-timer">
219+
<h3>Countdown Finished Callback</h3>
220+
221+
<div class="bs-docs-example">
222+
<p>
223+
A countdown timer that updates a value once the callback is reached
224+
<code ng-non-bindable="">
225+
&lt;timer countdown="3" interval="1000" finish-callback="callbackTimer.finished()"&gt;{{seconds}} second{{secondsS}}&lt;/timer&gt;
226+
</code>
227+
228+
<h3 class="counter">
229+
<timer countdown="3" interval="1000" finish-callback="callbackTimer.finished()">{{seconds}} second{{secondsS}} </timer>
230+
</h3>
231+
Timer: <span class="timer-status">{{callbackTimer.status}}</span>
232+
Callbacks: <span class="timer-callbacks">{{callbackTimer.callbackCount}}</span>
233+
234+
</div>
235+
</section>
236+
217237
<section id="markup">
218238
<h3>
219239
Markup</h3>

test/e2e/scenarios.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,18 @@ describe('Angular Timer E2E Tests', function () {
142142
expect(element('#clock-timer-leading-zero timer').html()).toMatch(/00 minutes,/);
143143
expect(element('#clock-timer-leading-zero timer').html()).toMatch(/11 seconds./);
144144
});
145+
146+
it('Countdown finish - Should fire callback on completion', function () {
147+
148+
149+
expect(element('#finish-callback-timer .timer-status').html()).toBe('Running');
150+
expect(element('#finish-callback-timer .timer-callbacks').html()).toBe('0');
151+
152+
sleep(5);
153+
expect(element('#finish-callback-timer .timer-status').html()).toBe('COMPLETE!!');
154+
expect(element('#finish-callback-timer .timer-callbacks').html()).toBe('1');
155+
156+
});
145157

146158
it('Countdown timer with maxTimeUnit- should display time value from lower to specified maxTimeUnit', function() {
147159
var timer1Val = element('#max-time-unit-countdown-timer .WithMaxTimeUnitAsMinute timer').text();

0 commit comments

Comments
 (0)