Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

cleanup

  • Loading branch information...
commit 92751421bafa95674eb5641927a944ba5763795f 1 parent 87281fc
@sirkitree sirkitree authored
Showing with 14 additions and 14 deletions.
  1. +14 −14 app/scripts/directives/clock.js
View
28 app/scripts/directives/clock.js
@@ -1,23 +1,23 @@
'use strict';
angular.module('fivefifteenApp.directives', [])
- .directive('clock', ['$timeout', 'DataFactory', function (
- $timeout, DataFactory) {
+ .directive('clock', ['$timeout', 'DataFactory', function ($timeout, DataFactory) {
return function (scope, element) {
- var timeoutId; // timeoutId, so that we can cancel the time updates
- if (!DataFactory.initTime) {
+ var timeoutId,
+ current = new Date(),
+ elapsed = new Date();
+
+ if (angular.isUndefined(DataFactory.initTime)) {
DataFactory.initTime = new Date();
}
var init = DataFactory.initTime;
-
- var current = new Date();
- var elapsed = new Date();
+
elapsed.setTime(current.getTime() - init.getTime());
element.text('Minute/s elapsed: ' + elapsed.getMinutes());
-
- // schedule update in one second
+
+ // Schedule update in one second.
function updateLater() {
- // save the timeoutId for canceling
+ // Save the timeoutId for canceling.
timeoutId = $timeout(function() {
var current = new Date();
var elapsed = new Date();
@@ -26,13 +26,13 @@ angular.module('fivefifteenApp.directives', [])
updateLater(); // schedule another update
}, 1000);
}
-
- // listen on DOM destroy (removal) event, and cancel the next UI update
- // to prevent updating time ofter the DOM element was removed.
+
+ // Listen on DOM destroy (removal) event, and cancel the next UI update
+ // to prevent updating time after the DOM element was removed.
element.bind('$destroy', function() {
$timeout.cancel(timeoutId);
});
-
+
updateLater(); // kick off the UI update process.
};
}]);
Please sign in to comment.
Something went wrong with that request. Please try again.