annotate core/modules/comment/js/comment-new-indicator.js @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 129ea1e6d783
children
rev   line source
Chris@0 1 /**
Chris@0 2 * DO NOT EDIT THIS FILE.
Chris@0 3 * See the following change record for more information,
Chris@0 4 * https://www.drupal.org/node/2815083
Chris@0 5 * @preserve
Chris@0 6 **/
Chris@0 7
Chris@0 8 (function ($, Drupal, window) {
Chris@0 9 function processCommentNewIndicators($placeholders) {
Chris@0 10 var isFirstNewComment = true;
Chris@0 11 var newCommentString = Drupal.t('new');
Chris@0 12 var $placeholder = void 0;
Chris@0 13
Chris@0 14 $placeholders.each(function (index, placeholder) {
Chris@0 15 $placeholder = $(placeholder);
Chris@0 16 var timestamp = parseInt($placeholder.attr('data-comment-timestamp'), 10);
Chris@0 17 var $node = $placeholder.closest('[data-history-node-id]');
Chris@0 18 var nodeID = $node.attr('data-history-node-id');
Chris@0 19 var lastViewTimestamp = Drupal.history.getLastRead(nodeID);
Chris@0 20
Chris@0 21 if (timestamp > lastViewTimestamp) {
Chris@0 22 var $comment = $(placeholder).removeClass('hidden').text(newCommentString).closest('.js-comment').addClass('new');
Chris@0 23
Chris@0 24 if (isFirstNewComment) {
Chris@0 25 isFirstNewComment = false;
Chris@0 26 $comment.prev().before('<a id="new" />');
Chris@0 27
Chris@0 28 if (window.location.hash === '#new') {
Chris@0 29 window.scrollTo(0, $comment.offset().top - Drupal.displace.offsets.top);
Chris@0 30 }
Chris@0 31 }
Chris@0 32 }
Chris@0 33 });
Chris@0 34 }
Chris@17 35
Chris@17 36 Drupal.behaviors.commentNewIndicator = {
Chris@17 37 attach: function attach(context) {
Chris@17 38 var nodeIDs = [];
Chris@17 39 var $placeholders = $(context).find('[data-comment-timestamp]').once('history').filter(function () {
Chris@17 40 var $placeholder = $(this);
Chris@17 41 var commentTimestamp = parseInt($placeholder.attr('data-comment-timestamp'), 10);
Chris@17 42 var nodeID = $placeholder.closest('[data-history-node-id]').attr('data-history-node-id');
Chris@17 43 if (Drupal.history.needsServerCheck(nodeID, commentTimestamp)) {
Chris@17 44 nodeIDs.push(nodeID);
Chris@17 45 return true;
Chris@17 46 }
Chris@17 47
Chris@17 48 return false;
Chris@17 49 });
Chris@17 50
Chris@17 51 if ($placeholders.length === 0) {
Chris@17 52 return;
Chris@17 53 }
Chris@17 54
Chris@17 55 Drupal.history.fetchTimestamps(nodeIDs, function () {
Chris@17 56 processCommentNewIndicators($placeholders);
Chris@17 57 });
Chris@17 58 }
Chris@17 59 };
Chris@0 60 })(jQuery, Drupal, window);