import 'bootstrap/js/dropdown'; import './comment/frCommenter'; angular.module('footyroom') .controller('MarketCountdown', ['$scope', '$interval', '$window', function ($scope, $interval, $window) { var config = $window.DataStore.transferWindows || {}; // Promise value returned from $interval. var countdown; // Date object of market close time. var endTime; function tick() { $scope.totalSeconds = Math.floor((endTime.getTime() - (new Date()).getTime()) / 1000); if ($scope.totalSeconds < 0) { $scope.totalSeconds = 0; } $scope.seconds = Math.floor($scope.totalSeconds % 60); $scope.minutes = Math.floor($scope.totalSeconds % 3600 / 60); $scope.hours = Math.floor($scope.totalSeconds % 86400 / 3600); $scope.days = Math.floor($scope.totalSeconds / 86400); } $scope.$watch('league', function () { // Cancel previous interval if defined. $interval.cancel(countdown); endTime = new Date(config[$scope.league]); // Initial tick, so that we don't have to wait 1 second before interval // kicks in. tick(); countdown = $interval(tick, 1000); }); }]);