X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fcomment%2Fjs%2Fcomment-new-indicator.es6.js;fp=web%2Fcore%2Fmodules%2Fcomment%2Fjs%2Fcomment-new-indicator.es6.js;h=9ae82461c8c8cbb1d4f3d75df99cc55f758ec263;hp=dd1fadf3ad76765b5a6df2181bdee9daae3e239f;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hpb=74df008bdbb3a11eeea356744f39b802369bda3c diff --git a/web/core/modules/comment/js/comment-new-indicator.es6.js b/web/core/modules/comment/js/comment-new-indicator.es6.js index dd1fadf3a..9ae82461c 100644 --- a/web/core/modules/comment/js/comment-new-indicator.es6.js +++ b/web/core/modules/comment/js/comment-new-indicator.es6.js @@ -6,47 +6,7 @@ * installed. */ -(function ($, Drupal, window) { - /** - * Renders "new" comment indicators wherever necessary. - * - * @type {Drupal~behavior} - * - * @prop {Drupal~behaviorAttach} attach - * Attaches "new" comment indicators behavior. - */ - Drupal.behaviors.commentNewIndicator = { - attach(context) { - // Collect all "new" comment indicator placeholders (and their - // corresponding node IDs) newer than 30 days ago that have not already - // been read after their last comment timestamp. - const nodeIDs = []; - const $placeholders = $(context) - .find('[data-comment-timestamp]') - .once('history') - .filter(function () { - const $placeholder = $(this); - const commentTimestamp = parseInt($placeholder.attr('data-comment-timestamp'), 10); - const nodeID = $placeholder.closest('[data-history-node-id]').attr('data-history-node-id'); - if (Drupal.history.needsServerCheck(nodeID, commentTimestamp)) { - nodeIDs.push(nodeID); - return true; - } - - return false; - }); - - if ($placeholders.length === 0) { - return; - } - - // Fetch the node read timestamps from the server. - Drupal.history.fetchTimestamps(nodeIDs, () => { - processCommentNewIndicators($placeholders); - }); - }, - }; - +(function($, Drupal, window) { /** * Processes the markup for "new comment" indicators. * @@ -60,7 +20,10 @@ $placeholders.each((index, placeholder) => { $placeholder = $(placeholder); - const timestamp = parseInt($placeholder.attr('data-comment-timestamp'), 10); + const timestamp = parseInt( + $placeholder.attr('data-comment-timestamp'), + 10, + ); const $node = $placeholder.closest('[data-history-node-id]'); const nodeID = $node.attr('data-history-node-id'); const lastViewTimestamp = Drupal.history.getLastRead(nodeID); @@ -82,10 +45,58 @@ // If the URL points to the first new comment, then scroll to that // comment. if (window.location.hash === '#new') { - window.scrollTo(0, $comment.offset().top - Drupal.displace.offsets.top); + window.scrollTo( + 0, + $comment.offset().top - Drupal.displace.offsets.top, + ); } } } }); } -}(jQuery, Drupal, window)); + + /** + * Renders "new" comment indicators wherever necessary. + * + * @type {Drupal~behavior} + * + * @prop {Drupal~behaviorAttach} attach + * Attaches "new" comment indicators behavior. + */ + Drupal.behaviors.commentNewIndicator = { + attach(context) { + // Collect all "new" comment indicator placeholders (and their + // corresponding node IDs) newer than 30 days ago that have not already + // been read after their last comment timestamp. + const nodeIDs = []; + const $placeholders = $(context) + .find('[data-comment-timestamp]') + .once('history') + .filter(function() { + const $placeholder = $(this); + const commentTimestamp = parseInt( + $placeholder.attr('data-comment-timestamp'), + 10, + ); + const nodeID = $placeholder + .closest('[data-history-node-id]') + .attr('data-history-node-id'); + if (Drupal.history.needsServerCheck(nodeID, commentTimestamp)) { + nodeIDs.push(nodeID); + return true; + } + + return false; + }); + + if ($placeholders.length === 0) { + return; + } + + // Fetch the node read timestamps from the server. + Drupal.history.fetchTimestamps(nodeIDs, () => { + processCommentNewIndicators($placeholders); + }); + }, + }; +})(jQuery, Drupal, window);