2 * DO NOT EDIT THIS FILE.
3 * See the following change record for more information,
4 * https://www.drupal.org/node/2815083
8 (function ($, Drupal, window) {
9 Drupal.behaviors.trackerHistory = {
10 attach: function attach(context) {
12 var $nodeNewPlaceholders = $(context).find('[data-history-node-timestamp]').once('history').filter(function () {
13 var nodeTimestamp = parseInt(this.getAttribute('data-history-node-timestamp'), 10);
14 var nodeID = this.getAttribute('data-history-node-id');
15 if (Drupal.history.needsServerCheck(nodeID, nodeTimestamp)) {
23 var $newRepliesPlaceholders = $(context).find('[data-history-node-last-comment-timestamp]').once('history').filter(function () {
24 var lastCommentTimestamp = parseInt(this.getAttribute('data-history-node-last-comment-timestamp'), 10);
25 var nodeTimestamp = parseInt(this.previousSibling.previousSibling.getAttribute('data-history-node-timestamp'), 10);
27 if (lastCommentTimestamp === nodeTimestamp) {
30 var nodeID = this.previousSibling.previousSibling.getAttribute('data-history-node-id');
31 if (Drupal.history.needsServerCheck(nodeID, lastCommentTimestamp)) {
32 if (nodeIDs.indexOf(nodeID) === -1) {
41 if ($nodeNewPlaceholders.length === 0 && $newRepliesPlaceholders.length === 0) {
45 Drupal.history.fetchTimestamps(nodeIDs, function () {
46 processNodeNewIndicators($nodeNewPlaceholders);
47 processNewRepliesIndicators($newRepliesPlaceholders);
52 function processNodeNewIndicators($placeholders) {
53 var newNodeString = Drupal.t('new');
54 var updatedNodeString = Drupal.t('updated');
56 $placeholders.each(function (index, placeholder) {
57 var timestamp = parseInt(placeholder.getAttribute('data-history-node-timestamp'), 10);
58 var nodeID = placeholder.getAttribute('data-history-node-id');
59 var lastViewTimestamp = Drupal.history.getLastRead(nodeID);
61 if (timestamp > lastViewTimestamp) {
62 var message = lastViewTimestamp === 0 ? newNodeString : updatedNodeString;
63 $(placeholder).append('<span class="marker">' + message + '</span>');
68 function processNewRepliesIndicators($placeholders) {
69 var placeholdersToUpdate = {};
70 $placeholders.each(function (index, placeholder) {
71 var timestamp = parseInt(placeholder.getAttribute('data-history-node-last-comment-timestamp'), 10);
72 var nodeID = placeholder.previousSibling.previousSibling.getAttribute('data-history-node-id');
73 var lastViewTimestamp = Drupal.history.getLastRead(nodeID);
75 if (timestamp > lastViewTimestamp) {
76 placeholdersToUpdate[nodeID] = placeholder;
80 var nodeIDs = Object.keys(placeholdersToUpdate);
81 if (nodeIDs.length === 0) {
85 url: Drupal.url('comments/render_new_comments_node_links'),
87 data: { 'node_ids[]': nodeIDs },
89 success: function success(results) {
90 for (var nodeID in results) {
91 if (results.hasOwnProperty(nodeID) && placeholdersToUpdate.hasOwnProperty(nodeID)) {
92 var url = results[nodeID].first_new_comment_link;
93 var text = Drupal.formatPlural(results[nodeID].new_comment_count, '1 new', '@count new');
94 $(placeholdersToUpdate[nodeID]).append('<br /><a href="' + url + '">' + text + '</a>');
100 })(jQuery, Drupal, window);