-
- 'use strict';
-
- /**
- * Render "X new comments" links wherever necessary.
- *
- * @type {Drupal~behavior}
- *
- * @prop {Drupal~behaviorAttach} attach
- * Attaches new comment links behavior.
- */
- Drupal.behaviors.nodeNewCommentsLink = {
- attach: function (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.
- 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 this placeholder link until it is certain we'll need it.
- hide($placeholder);
- return true;
- }
- else {
- // 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, function () {
- processNodeNewCommentLinks($placeholders);
- });
- }
- };
-
- /**
- * Hides a "new comment" element.
- *
- * @param {jQuery} $placeholder
- * The placeholder element of the new comment link.
- *
- * @return {jQuery}
- * The placeholder element passed in as a parameter.
- */