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 function processNodeNewIndicators($placeholders) {
10 var newNodeString = Drupal.t('new');
11 var updatedNodeString = Drupal.t('updated');
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);
18 if (timestamp > lastViewTimestamp) {
19 var message = lastViewTimestamp === 0 ? newNodeString : updatedNodeString;
20 $(placeholder).append('<span class="marker">' + message + '</span>');
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);
32 if (timestamp > lastViewTimestamp) {
33 placeholdersToUpdate[nodeID] = placeholder;
37 var nodeIDs = Object.keys(placeholdersToUpdate);
38 if (nodeIDs.length === 0) {
42 url: Drupal.url('comments/render_new_comments_node_links'),
44 data: { 'node_ids[]': nodeIDs },
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>');
58 Drupal.behaviors.trackerHistory = {
59 attach: function attach(context) {
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)) {
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);
76 if (lastCommentTimestamp === nodeTimestamp) {
79 var nodeID = this.previousSibling.previousSibling.getAttribute('data-history-node-id');
80 if (Drupal.history.needsServerCheck(nodeID, lastCommentTimestamp)) {
81 if (nodeIDs.indexOf(nodeID) === -1) {
90 if ($nodeNewPlaceholders.length === 0 && $newRepliesPlaceholders.length === 0) {
94 Drupal.history.fetchTimestamps(nodeIDs, function () {
95 processNodeNewIndicators($nodeNewPlaceholders);
96 processNewRepliesIndicators($newRepliesPlaceholders);
100 })(jQuery, Drupal, window);