Chris@0: /** Chris@0: * DO NOT EDIT THIS FILE. Chris@0: * See the following change record for more information, Chris@0: * https://www.drupal.org/node/2815083 Chris@0: * @preserve Chris@0: **/ Chris@0: Chris@0: (function ($, Drupal, window) { Chris@0: function processCommentNewIndicators($placeholders) { Chris@0: var isFirstNewComment = true; Chris@0: var newCommentString = Drupal.t('new'); Chris@0: var $placeholder = void 0; Chris@0: Chris@0: $placeholders.each(function (index, placeholder) { Chris@0: $placeholder = $(placeholder); Chris@0: var timestamp = parseInt($placeholder.attr('data-comment-timestamp'), 10); Chris@0: var $node = $placeholder.closest('[data-history-node-id]'); Chris@0: var nodeID = $node.attr('data-history-node-id'); Chris@0: var lastViewTimestamp = Drupal.history.getLastRead(nodeID); Chris@0: Chris@0: if (timestamp > lastViewTimestamp) { Chris@0: var $comment = $(placeholder).removeClass('hidden').text(newCommentString).closest('.js-comment').addClass('new'); Chris@0: Chris@0: if (isFirstNewComment) { Chris@0: isFirstNewComment = false; Chris@0: $comment.prev().before(''); Chris@0: Chris@0: if (window.location.hash === '#new') { Chris@0: window.scrollTo(0, $comment.offset().top - Drupal.displace.offsets.top); Chris@0: } Chris@0: } Chris@0: } Chris@0: }); Chris@0: } Chris@17: Chris@17: Drupal.behaviors.commentNewIndicator = { Chris@17: attach: function attach(context) { Chris@17: var nodeIDs = []; Chris@17: var $placeholders = $(context).find('[data-comment-timestamp]').once('history').filter(function () { Chris@17: var $placeholder = $(this); Chris@17: var commentTimestamp = parseInt($placeholder.attr('data-comment-timestamp'), 10); Chris@17: var nodeID = $placeholder.closest('[data-history-node-id]').attr('data-history-node-id'); Chris@17: if (Drupal.history.needsServerCheck(nodeID, commentTimestamp)) { Chris@17: nodeIDs.push(nodeID); Chris@17: return true; Chris@17: } Chris@17: Chris@17: return false; Chris@17: }); Chris@17: Chris@17: if ($placeholders.length === 0) { Chris@17: return; Chris@17: } Chris@17: Chris@17: Drupal.history.fetchTimestamps(nodeIDs, function () { Chris@17: processCommentNewIndicators($placeholders); Chris@17: }); Chris@17: } Chris@17: }; Chris@0: })(jQuery, Drupal, window);