Blame view

resources/js/livescores/frLsMatchDirective.js 2.77 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
  import frLsMatch from '../../../public/views/ng/common/frLsMatch.html';
  import '../vendor/jquery.scrollTo-min';
  import '../common/services/frMatchViewHelper';
  import '../common/directives/formations';
  
  angular.module('footyroom').requires.push('fr.matchViewHelper', 'fr.formations');
  
  angular.module('footyroom').directive('frLsMatch', [function () {
      return {
          restrict: 'A',
          scope: true,
          template: frLsMatch,
          controller: ['$scope', '$element', 'matchViewHelper', '$rootScope', function ($scope, $element, matchViewHelper, $rootScope) {
              var minutesJob;
  
              $scope.incidentIdToName = $rootScope.incidentIdToName;
  
              init();
  
              function init() {
                  // Normalize score.
                  matchViewHelper.setScore($scope.match);
  
                  // Update minutes automatically.
                  minutesJob = matchViewHelper.startMinutesJob($scope.match);
  
                  // Add watcher on match incidents so that we can process them everytime they change.
                  $scope.$watchCollection('match.incidents', function (newValue, oldValue) {
                      if (newValue === oldValue) {
                          return;
                      }
  
                      matchViewHelper.setMainIncidents($scope.match);
                  });
  
                  // Process incidents for the first time.
                  matchViewHelper.setMainIncidents($scope.match);
              }
  
              $scope.$on('$destroy', function () {
                  matchViewHelper.stopMinutesJob(minutesJob);
              });
  
              $scope.onClick = function () {
                  if ($scope.openedMatch === $scope.match) {
                      $scope.openedMatch = null;
                  } else {
                      $scope.openedMatch = $scope.match;
                  }
              };
  
              $scope.clickMatchCenter = function ($event) {
                  if ($scope.isMatchCenterOpen()) {
                      $scope.joinMatch($scope.match.matchId);
                      $element.find('ls-join-match').litelay({ spinner: true });
                  }
              };
  
              $scope.isMatchCenterOpen = function () {
                  return (new Date($scope.match.datetime) - new Date() <= 1800000);
              };
  
              $scope.$watch('match._subscribed', function (newValue, oldValue) {
                  if (newValue === true) {
                      $scope.incidents = $scope.match.incidents;
  
                      $element.find('ls-join-match').litelay({ off: true });
  
                      setTimeout(function () {
                          $('body').scrollTo($element, 400, { offset: -65 });
                      }, 10);
                  } else {
                      $scope.incidents = $scope.mainIncidents;
                  }
              });
          }],
      };
  }]);