annotate core/modules/comment/js/comment-new-indicator.js @ 4:a9cd425dd02b

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:11:55 +0000
parents c75dbcec494b
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@4 35
Chris@4 36 Drupal.behaviors.commentNewIndicator = {
Chris@4 37 attach: function attach(context) {
Chris@4 38 var nodeIDs = [];
Chris@4 39 var $placeholders = $(context).find('[data-comment-timestamp]').once('history').filter(function () {
Chris@4 40 var $placeholder = $(this);
Chris@4 41 var commentTimestamp = parseInt($placeholder.attr('data-comment-timestamp'), 10);
Chris@4 42 var nodeID = $placeholder.closest('[data-history-node-id]').attr('data-history-node-id');
Chris@4 43 if (Drupal.history.needsServerCheck(nodeID, commentTimestamp)) {
Chris@4 44 nodeIDs.push(nodeID);
Chris@4 45 return true;
Chris@4 46 }
Chris@4 47
Chris@4 48 return false;
Chris@4 49 });
Chris@4 50
Chris@4 51 if ($placeholders.length === 0) {
Chris@4 52 return;
Chris@4 53 }
Chris@4 54
Chris@4 55 Drupal.history.fetchTimestamps(nodeIDs, function () {
Chris@4 56 processCommentNewIndicators($placeholders);
Chris@4 57 });
Chris@4 58 }
Chris@4 59 };
Chris@0 60 })(jQuery, Drupal, window);