Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / modules / comment / js / comment-new-indicator.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, window) {
9   function processCommentNewIndicators($placeholders) {
10     var isFirstNewComment = true;
11     var newCommentString = Drupal.t('new');
12     var $placeholder = void 0;
13
14     $placeholders.each(function (index, placeholder) {
15       $placeholder = $(placeholder);
16       var timestamp = parseInt($placeholder.attr('data-comment-timestamp'), 10);
17       var $node = $placeholder.closest('[data-history-node-id]');
18       var nodeID = $node.attr('data-history-node-id');
19       var lastViewTimestamp = Drupal.history.getLastRead(nodeID);
20
21       if (timestamp > lastViewTimestamp) {
22         var $comment = $(placeholder).removeClass('hidden').text(newCommentString).closest('.js-comment').addClass('new');
23
24         if (isFirstNewComment) {
25           isFirstNewComment = false;
26           $comment.prev().before('<a id="new" />');
27
28           if (window.location.hash === '#new') {
29             window.scrollTo(0, $comment.offset().top - Drupal.displace.offsets.top);
30           }
31         }
32       }
33     });
34   }
35
36   Drupal.behaviors.commentNewIndicator = {
37     attach: function attach(context) {
38       var nodeIDs = [];
39       var $placeholders = $(context).find('[data-comment-timestamp]').once('history').filter(function () {
40         var $placeholder = $(this);
41         var commentTimestamp = parseInt($placeholder.attr('data-comment-timestamp'), 10);
42         var nodeID = $placeholder.closest('[data-history-node-id]').attr('data-history-node-id');
43         if (Drupal.history.needsServerCheck(nodeID, commentTimestamp)) {
44           nodeIDs.push(nodeID);
45           return true;
46         }
47
48         return false;
49       });
50
51       if ($placeholders.length === 0) {
52         return;
53       }
54
55       Drupal.history.fetchTimestamps(nodeIDs, function () {
56         processCommentNewIndicators($placeholders);
57       });
58     }
59   };
60 })(jQuery, Drupal, window);