Blame view

resources/js/transfers.js 1.19 KB
e77200db5   nologostudio.ru   Initial commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
  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);
      });
  }]);