Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / comment / js / node-new-comments-link.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, drupalSettings) {
9   Drupal.behaviors.nodeNewCommentsLink = {
10     attach: function attach(context) {
11       var nodeIDs = [];
12       var $placeholders = $(context).find('[data-history-node-last-comment-timestamp]').once('history').filter(function () {
13         var $placeholder = $(this);
14         var lastCommentTimestamp = parseInt($placeholder.attr('data-history-node-last-comment-timestamp'), 10);
15         var nodeID = $placeholder.closest('[data-history-node-id]').attr('data-history-node-id');
16         if (Drupal.history.needsServerCheck(nodeID, lastCommentTimestamp)) {
17           nodeIDs.push(nodeID);
18
19           hide($placeholder);
20           return true;
21         }
22
23         remove($placeholder);
24         return false;
25       });
26
27       if ($placeholders.length === 0) {
28         return;
29       }
30
31       Drupal.history.fetchTimestamps(nodeIDs, function () {
32         processNodeNewCommentLinks($placeholders);
33       });
34     }
35   };
36
37   function hide($placeholder) {
38     return $placeholder.closest('.comment-new-comments').prev().addClass('last').end().hide();
39   }
40
41   function remove($placeholder) {
42     hide($placeholder).remove();
43   }
44
45   function show($placeholder) {
46     return $placeholder.closest('.comment-new-comments').prev().removeClass('last').end().show();
47   }
48
49   function processNodeNewCommentLinks($placeholders) {
50     var $placeholdersToUpdate = {};
51     var fieldName = 'comment';
52     var $placeholder = void 0;
53     $placeholders.each(function (index, placeholder) {
54       $placeholder = $(placeholder);
55       var timestamp = parseInt($placeholder.attr('data-history-node-last-comment-timestamp'), 10);
56       fieldName = $placeholder.attr('data-history-node-field-name');
57       var nodeID = $placeholder.closest('[data-history-node-id]').attr('data-history-node-id');
58       var lastViewTimestamp = Drupal.history.getLastRead(nodeID);
59
60       if (timestamp > lastViewTimestamp) {
61         $placeholdersToUpdate[nodeID] = $placeholder;
62       } else {
63           remove($placeholder);
64         }
65     });
66
67     var nodeIDs = Object.keys($placeholdersToUpdate);
68     if (nodeIDs.length === 0) {
69       return;
70     }
71
72     function render(results) {
73       for (var nodeID in results) {
74         if (results.hasOwnProperty(nodeID) && $placeholdersToUpdate.hasOwnProperty(nodeID)) {
75           $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');
76           show($placeholdersToUpdate[nodeID]);
77         }
78       }
79     }
80
81     if (drupalSettings.comment && drupalSettings.comment.newCommentsLinks) {
82       render(drupalSettings.comment.newCommentsLinks.node[fieldName]);
83     } else {
84       $.ajax({
85         url: Drupal.url('comments/render_new_comments_node_links'),
86         type: 'POST',
87         data: { 'node_ids[]': nodeIDs, field_name: fieldName },
88         dataType: 'json',
89         success: render
90       });
91     }
92   }
93 })(jQuery, Drupal, drupalSettings);