Updated Drupal to 8.6. This goes with the following updates because it's possible...
[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   function hide($placeholder) {
10     return $placeholder.closest('.comment-new-comments').prev().addClass('last').end().hide();
11   }
12
13   function remove($placeholder) {
14     hide($placeholder).remove();
15   }
16
17   function show($placeholder) {
18     return $placeholder.closest('.comment-new-comments').prev().removeClass('last').end().show();
19   }
20
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);
31
32       if (timestamp > lastViewTimestamp) {
33         $placeholdersToUpdate[nodeID] = $placeholder;
34       } else {
35           remove($placeholder);
36         }
37     });
38
39     var nodeIDs = Object.keys($placeholdersToUpdate);
40     if (nodeIDs.length === 0) {
41       return;
42     }
43
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]);
49         }
50       });
51     }
52
53     if (drupalSettings.comment && drupalSettings.comment.newCommentsLinks) {
54       render(drupalSettings.comment.newCommentsLinks.node[fieldName]);
55     } else {
56       $.ajax({
57         url: Drupal.url('comments/render_new_comments_node_links'),
58         type: 'POST',
59         data: { 'node_ids[]': nodeIDs, field_name: fieldName },
60         dataType: 'json',
61         success: render
62       });
63     }
64   }
65
66   Drupal.behaviors.nodeNewCommentsLink = {
67     attach: function attach(context) {
68       var nodeIDs = [];
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)) {
74           nodeIDs.push(nodeID);
75
76           hide($placeholder);
77           return true;
78         }
79
80         remove($placeholder);
81         return false;
82       });
83
84       if ($placeholders.length === 0) {
85         return;
86       }
87
88       Drupal.history.fetchTimestamps(nodeIDs, function () {
89         processNodeNewCommentLinks($placeholders);
90       });
91     }
92   };
93 })(jQuery, Drupal, drupalSettings);