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, drupalSettings) {
9 function hide($placeholder) {
10 return $placeholder.closest('.comment-new-comments').prev().addClass('last').end().hide();
13 function remove($placeholder) {
14 hide($placeholder).remove();
17 function show($placeholder) {
18 return $placeholder.closest('.comment-new-comments').prev().removeClass('last').end().show();
21 function processNodeNewCommentLinks($placeholders) {
22 var $placeholdersToUpdate = {};
23 var fieldName = 'comment';
24 var $placeholder = void 0;
25 $placeholders.each(function (index, placeholder) {
26 $placeholder = $(placeholder);
27 var timestamp = parseInt($placeholder.attr('data-history-node-last-comment-timestamp'), 10);
28 fieldName = $placeholder.attr('data-history-node-field-name');
29 var nodeID = $placeholder.closest('[data-history-node-id]').attr('data-history-node-id');
30 var lastViewTimestamp = Drupal.history.getLastRead(nodeID);
32 if (timestamp > lastViewTimestamp) {
33 $placeholdersToUpdate[nodeID] = $placeholder;
39 var nodeIDs = Object.keys($placeholdersToUpdate);
40 if (nodeIDs.length === 0) {
44 function render(results) {
45 Object.keys(results || {}).forEach(function (nodeID) {
46 if ($placeholdersToUpdate.hasOwnProperty(nodeID)) {
47 $placeholdersToUpdate[nodeID].attr('href', results[nodeID].first_new_comment_link).text(Drupal.formatPlural(results[nodeID].new_comment_count, '1 new comment', '@count new comments')).removeClass('hidden');
48 show($placeholdersToUpdate[nodeID]);
53 if (drupalSettings.comment && drupalSettings.comment.newCommentsLinks) {
54 render(drupalSettings.comment.newCommentsLinks.node[fieldName]);
57 url: Drupal.url('comments/render_new_comments_node_links'),
59 data: { 'node_ids[]': nodeIDs, field_name: fieldName },
66 Drupal.behaviors.nodeNewCommentsLink = {
67 attach: function attach(context) {
69 var $placeholders = $(context).find('[data-history-node-last-comment-timestamp]').once('history').filter(function () {
70 var $placeholder = $(this);
71 var lastCommentTimestamp = parseInt($placeholder.attr('data-history-node-last-comment-timestamp'), 10);
72 var nodeID = $placeholder.closest('[data-history-node-id]').attr('data-history-node-id');
73 if (Drupal.history.needsServerCheck(nodeID, lastCommentTimestamp)) {
84 if ($placeholders.length === 0) {
88 Drupal.history.fetchTimestamps(nodeIDs, function () {
89 processNodeNewCommentLinks($placeholders);
93 })(jQuery, Drupal, drupalSettings);