X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fcomment%2Fjs%2Fnode-new-comments-link.js;h=b7439940f61ac81bc5739ca3ef73af8ea865bcdc;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hp=37fdb58c5e17db80e08fc76de9a0698f80bf4562;hpb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;p=yaffs-website diff --git a/web/core/modules/comment/js/node-new-comments-link.js b/web/core/modules/comment/js/node-new-comments-link.js index 37fdb58c5..b7439940f 100644 --- a/web/core/modules/comment/js/node-new-comments-link.js +++ b/web/core/modules/comment/js/node-new-comments-link.js @@ -6,34 +6,6 @@ **/ (function ($, Drupal, drupalSettings) { - Drupal.behaviors.nodeNewCommentsLink = { - attach: function attach(context) { - var nodeIDs = []; - var $placeholders = $(context).find('[data-history-node-last-comment-timestamp]').once('history').filter(function () { - var $placeholder = $(this); - var lastCommentTimestamp = parseInt($placeholder.attr('data-history-node-last-comment-timestamp'), 10); - var nodeID = $placeholder.closest('[data-history-node-id]').attr('data-history-node-id'); - if (Drupal.history.needsServerCheck(nodeID, lastCommentTimestamp)) { - nodeIDs.push(nodeID); - - hide($placeholder); - return true; - } - - remove($placeholder); - return false; - }); - - if ($placeholders.length === 0) { - return; - } - - Drupal.history.fetchTimestamps(nodeIDs, function () { - processNodeNewCommentLinks($placeholders); - }); - } - }; - function hide($placeholder) { return $placeholder.closest('.comment-new-comments').prev().addClass('last').end().hide(); } @@ -70,12 +42,12 @@ } function render(results) { - for (var nodeID in results) { - if (results.hasOwnProperty(nodeID) && $placeholdersToUpdate.hasOwnProperty(nodeID)) { + Object.keys(results || {}).forEach(function (nodeID) { + if ($placeholdersToUpdate.hasOwnProperty(nodeID)) { $placeholdersToUpdate[nodeID].attr('href', results[nodeID].first_new_comment_link).text(Drupal.formatPlural(results[nodeID].new_comment_count, '1 new comment', '@count new comments')).removeClass('hidden'); show($placeholdersToUpdate[nodeID]); } - } + }); } if (drupalSettings.comment && drupalSettings.comment.newCommentsLinks) { @@ -90,4 +62,32 @@ }); } } + + Drupal.behaviors.nodeNewCommentsLink = { + attach: function attach(context) { + var nodeIDs = []; + var $placeholders = $(context).find('[data-history-node-last-comment-timestamp]').once('history').filter(function () { + var $placeholder = $(this); + var lastCommentTimestamp = parseInt($placeholder.attr('data-history-node-last-comment-timestamp'), 10); + var nodeID = $placeholder.closest('[data-history-node-id]').attr('data-history-node-id'); + if (Drupal.history.needsServerCheck(nodeID, lastCommentTimestamp)) { + nodeIDs.push(nodeID); + + hide($placeholder); + return true; + } + + remove($placeholder); + return false; + }); + + if ($placeholders.length === 0) { + return; + } + + Drupal.history.fetchTimestamps(nodeIDs, function () { + processNodeNewCommentLinks($placeholders); + }); + } + }; })(jQuery, Drupal, drupalSettings); \ No newline at end of file