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 Drupal.behaviors.commentNewIndicator = {
10 attach: function attach(context) {
12 var $placeholders = $(context).find('[data-comment-timestamp]').once('history').filter(function () {
13 var $placeholder = $(this);
14 var commentTimestamp = parseInt($placeholder.attr('data-comment-timestamp'), 10);
15 var nodeID = $placeholder.closest('[data-history-node-id]').attr('data-history-node-id');
16 if (Drupal.history.needsServerCheck(nodeID, commentTimestamp)) {
24 if ($placeholders.length === 0) {
28 Drupal.history.fetchTimestamps(nodeIDs, function () {
29 processCommentNewIndicators($placeholders);
34 function processCommentNewIndicators($placeholders) {
35 var isFirstNewComment = true;
36 var newCommentString = Drupal.t('new');
37 var $placeholder = void 0;
39 $placeholders.each(function (index, placeholder) {
40 $placeholder = $(placeholder);
41 var timestamp = parseInt($placeholder.attr('data-comment-timestamp'), 10);
42 var $node = $placeholder.closest('[data-history-node-id]');
43 var nodeID = $node.attr('data-history-node-id');
44 var lastViewTimestamp = Drupal.history.getLastRead(nodeID);
46 if (timestamp > lastViewTimestamp) {
47 var $comment = $(placeholder).removeClass('hidden').text(newCommentString).closest('.js-comment').addClass('new');
49 if (isFirstNewComment) {
50 isFirstNewComment = false;
51 $comment.prev().before('<a id="new" />');
53 if (window.location.hash === '#new') {
54 window.scrollTo(0, $comment.offset().top - Drupal.displace.offsets.top);
60 })(jQuery, Drupal, window);