Added the Search API Synonym module to deal specifically with licence and license...
[yaffs-website] / web / core / modules / tracker / js / tracker-history.js
1 /**
2 * DO NOT EDIT THIS FILE.
3 * See the following change record for more information,
4 * https://www.drupal.org/node/2815083
5 * @preserve
6 **/
7
8 (function ($, Drupal, window) {
9   function processNodeNewIndicators($placeholders) {
10     var newNodeString = Drupal.t('new');
11     var updatedNodeString = Drupal.t('updated');
12
13     $placeholders.each(function (index, placeholder) {
14       var timestamp = parseInt(placeholder.getAttribute('data-history-node-timestamp'), 10);
15       var nodeID = placeholder.getAttribute('data-history-node-id');
16       var lastViewTimestamp = Drupal.history.getLastRead(nodeID);
17
18       if (timestamp > lastViewTimestamp) {
19         var message = lastViewTimestamp === 0 ? newNodeString : updatedNodeString;
20         $(placeholder).append('<span class="marker">' + message + '</span>');
21       }
22     });
23   }
24
25   function processNewRepliesIndicators($placeholders) {
26     var placeholdersToUpdate = {};
27     $placeholders.each(function (index, placeholder) {
28       var timestamp = parseInt(placeholder.getAttribute('data-history-node-last-comment-timestamp'), 10);
29       var nodeID = placeholder.previousSibling.previousSibling.getAttribute('data-history-node-id');
30       var lastViewTimestamp = Drupal.history.getLastRead(nodeID);
31
32       if (timestamp > lastViewTimestamp) {
33         placeholdersToUpdate[nodeID] = placeholder;
34       }
35     });
36
37     var nodeIDs = Object.keys(placeholdersToUpdate);
38     if (nodeIDs.length === 0) {
39       return;
40     }
41     $.ajax({
42       url: Drupal.url('comments/render_new_comments_node_links'),
43       type: 'POST',
44       data: { 'node_ids[]': nodeIDs },
45       dataType: 'json',
46       success: function success(results) {
47         Object.keys(results || {}).forEach(function (nodeID) {
48           if (placeholdersToUpdate.hasOwnProperty(nodeID)) {
49             var url = results[nodeID].first_new_comment_link;
50             var text = Drupal.formatPlural(results[nodeID].new_comment_count, '1 new', '@count new');
51             $(placeholdersToUpdate[nodeID]).append('<br /><a href="' + url + '">' + text + '</a>');
52           }
53         });
54       }
55     });
56   }
57
58   Drupal.behaviors.trackerHistory = {
59     attach: function attach(context) {
60       var nodeIDs = [];
61       var $nodeNewPlaceholders = $(context).find('[data-history-node-timestamp]').once('history').filter(function () {
62         var nodeTimestamp = parseInt(this.getAttribute('data-history-node-timestamp'), 10);
63         var nodeID = this.getAttribute('data-history-node-id');
64         if (Drupal.history.needsServerCheck(nodeID, nodeTimestamp)) {
65           nodeIDs.push(nodeID);
66           return true;
67         }
68
69         return false;
70       });
71
72       var $newRepliesPlaceholders = $(context).find('[data-history-node-last-comment-timestamp]').once('history').filter(function () {
73         var lastCommentTimestamp = parseInt(this.getAttribute('data-history-node-last-comment-timestamp'), 10);
74         var nodeTimestamp = parseInt(this.previousSibling.previousSibling.getAttribute('data-history-node-timestamp'), 10);
75
76         if (lastCommentTimestamp === nodeTimestamp) {
77           return false;
78         }
79         var nodeID = this.previousSibling.previousSibling.getAttribute('data-history-node-id');
80         if (Drupal.history.needsServerCheck(nodeID, lastCommentTimestamp)) {
81           if (nodeIDs.indexOf(nodeID) === -1) {
82             nodeIDs.push(nodeID);
83           }
84           return true;
85         }
86
87         return false;
88       });
89
90       if ($nodeNewPlaceholders.length === 0 && $newRepliesPlaceholders.length === 0) {
91         return;
92       }
93
94       Drupal.history.fetchTimestamps(nodeIDs, function () {
95         processNodeNewIndicators($nodeNewPlaceholders);
96         processNewRepliesIndicators($newRepliesPlaceholders);
97       });
98     }
99   };
100 })(jQuery, Drupal, window);