+
+ /**
+ * 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);