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 processCommentNewIndicators($placeholders) {
10 var isFirstNewComment = true;
11 var newCommentString = Drupal.t('new');
12 var $placeholder = void 0;
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);
21 if (timestamp > lastViewTimestamp) {
22 var $comment = $(placeholder).removeClass('hidden').text(newCommentString).closest('.js-comment').addClass('new');
24 if (isFirstNewComment) {
25 isFirstNewComment = false;
26 $comment.prev().before('<a id="new" />');
28 if (window.location.hash === '#new') {
29 window.scrollTo(0, $comment.offset().top - Drupal.displace.offsets.top);
36 Drupal.behaviors.commentNewIndicator = {
37 attach: function attach(context) {
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)) {
51 if ($placeholders.length === 0) {
55 Drupal.history.fetchTimestamps(nodeIDs, function () {
56 processCommentNewIndicators($placeholders);
60 })(jQuery, Drupal, window);