diff options
author | Alex Pott <alex.a.pott@googlemail.com> | 2018-03-05 09:14:08 +0000 |
---|---|---|
committer | Alex Pott <alex.a.pott@googlemail.com> | 2018-03-05 09:14:08 +0000 |
commit | 7d2f3a3b761e092d2e60c22993b65854a29aa79a (patch) | |
tree | 26f219026e2c33fc19780437790ec13b4c90664b /core/modules/comment/js | |
parent | 8b5cbee4fbace86ed21369ef97b68369762b60bb (diff) | |
download | drupal-7d2f3a3b761e092d2e60c22993b65854a29aa79a.tar.gz drupal-7d2f3a3b761e092d2e60c22993b65854a29aa79a.zip |
Issue #2946603 by drpal, alexpott, dawehner: JS codestyle: no-use-before-define
Diffstat (limited to 'core/modules/comment/js')
-rw-r--r-- | core/modules/comment/js/comment-new-indicator.es6.js | 80 | ||||
-rw-r--r-- | core/modules/comment/js/comment-new-indicator.js | 50 | ||||
-rw-r--r-- | core/modules/comment/js/node-new-comments-link.es6.js | 90 | ||||
-rw-r--r-- | core/modules/comment/js/node-new-comments-link.js | 56 |
4 files changed, 138 insertions, 138 deletions
diff --git a/core/modules/comment/js/comment-new-indicator.es6.js b/core/modules/comment/js/comment-new-indicator.es6.js index dd1fadf3ad76..791853e6eed8 100644 --- a/core/modules/comment/js/comment-new-indicator.es6.js +++ b/core/modules/comment/js/comment-new-indicator.es6.js @@ -8,46 +8,6 @@ (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); - }); - }, - }; - - /** * Processes the markup for "new comment" indicators. * * @param {jQuery} $placeholders @@ -88,4 +48,44 @@ } }); } + + /** + * 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)); diff --git a/core/modules/comment/js/comment-new-indicator.js b/core/modules/comment/js/comment-new-indicator.js index bc7f55ec37df..88587d5724c3 100644 --- a/core/modules/comment/js/comment-new-indicator.js +++ b/core/modules/comment/js/comment-new-indicator.js @@ -6,31 +6,6 @@ **/ (function ($, Drupal, window) { - Drupal.behaviors.commentNewIndicator = { - attach: function attach(context) { - var nodeIDs = []; - var $placeholders = $(context).find('[data-comment-timestamp]').once('history').filter(function () { - var $placeholder = $(this); - var commentTimestamp = parseInt($placeholder.attr('data-comment-timestamp'), 10); - var 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; - } - - Drupal.history.fetchTimestamps(nodeIDs, function () { - processCommentNewIndicators($placeholders); - }); - } - }; - function processCommentNewIndicators($placeholders) { var isFirstNewComment = true; var newCommentString = Drupal.t('new'); @@ -57,4 +32,29 @@ } }); } + + Drupal.behaviors.commentNewIndicator = { + attach: function attach(context) { + var nodeIDs = []; + var $placeholders = $(context).find('[data-comment-timestamp]').once('history').filter(function () { + var $placeholder = $(this); + var commentTimestamp = parseInt($placeholder.attr('data-comment-timestamp'), 10); + var 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; + } + + Drupal.history.fetchTimestamps(nodeIDs, function () { + processCommentNewIndicators($placeholders); + }); + } + }; })(jQuery, Drupal, window);
\ No newline at end of file diff --git a/core/modules/comment/js/node-new-comments-link.es6.js b/core/modules/comment/js/node-new-comments-link.es6.js index a2bdc35b9d72..0f084d4cb3db 100644 --- a/core/modules/comment/js/node-new-comments-link.es6.js +++ b/core/modules/comment/js/node-new-comments-link.es6.js @@ -8,51 +8,6 @@ (function ($, Drupal, drupalSettings) { /** - * Render "X new comments" links wherever necessary. - * - * @type {Drupal~behavior} - * - * @prop {Drupal~behaviorAttach} attach - * Attaches new comment links behavior. - */ - Drupal.behaviors.nodeNewCommentsLink = { - attach(context) { - // Collect all "X new comments" node link 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-history-node-last-comment-timestamp]') - .once('history') - .filter(function () { - const $placeholder = $(this); - const lastCommentTimestamp = parseInt($placeholder.attr('data-history-node-last-comment-timestamp'), 10); - const nodeID = $placeholder.closest('[data-history-node-id]').attr('data-history-node-id'); - if (Drupal.history.needsServerCheck(nodeID, lastCommentTimestamp)) { - nodeIDs.push(nodeID); - // Hide this placeholder link until it is certain we'll need it. - hide($placeholder); - return true; - } - - // Remove this placeholder link from the DOM because we won't need - // it. - remove($placeholder); - return false; - }); - - if ($placeholders.length === 0) { - return; - } - - // Perform an AJAX request to retrieve node read timestamps. - Drupal.history.fetchTimestamps(nodeIDs, () => { - processNodeNewCommentLinks($placeholders); - }); - }, - }; - - /** * Hides a "new comment" element. * * @param {jQuery} $placeholder @@ -173,4 +128,49 @@ }); } } + + /** + * Render "X new comments" links wherever necessary. + * + * @type {Drupal~behavior} + * + * @prop {Drupal~behaviorAttach} attach + * Attaches new comment links behavior. + */ + Drupal.behaviors.nodeNewCommentsLink = { + attach(context) { + // Collect all "X new comments" node link 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-history-node-last-comment-timestamp]') + .once('history') + .filter(function () { + const $placeholder = $(this); + const lastCommentTimestamp = parseInt($placeholder.attr('data-history-node-last-comment-timestamp'), 10); + const nodeID = $placeholder.closest('[data-history-node-id]').attr('data-history-node-id'); + if (Drupal.history.needsServerCheck(nodeID, lastCommentTimestamp)) { + nodeIDs.push(nodeID); + // Hide this placeholder link until it is certain we'll need it. + hide($placeholder); + return true; + } + + // Remove this placeholder link from the DOM because we won't need + // it. + remove($placeholder); + return false; + }); + + if ($placeholders.length === 0) { + return; + } + + // Perform an AJAX request to retrieve node read timestamps. + Drupal.history.fetchTimestamps(nodeIDs, () => { + processNodeNewCommentLinks($placeholders); + }); + }, + }; }(jQuery, Drupal, drupalSettings)); diff --git a/core/modules/comment/js/node-new-comments-link.js b/core/modules/comment/js/node-new-comments-link.js index 1396018a5618..b7439940f61a 100644 --- a/core/modules/comment/js/node-new-comments-link.js +++ b/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(); } @@ -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 |