Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / comment / js / node-new-comments-link.es6.js
index a2bdc35b9d7272b4950f55f303a27b73eacf0486..d3d0a0787078b735ce82e64c69888535a6917fc8 100644 (file)
@@ -6,52 +6,7 @@
  * installed.
  */
 
-(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);
-      });
-    },
-  };
-
+(function($, Drupal, drupalSettings) {
   /**
    * Hides a "new comment" element.
    *
    *   The placeholder element passed in as a parameter.
    */
   function hide($placeholder) {
-    return $placeholder
-      // Find the parent <li>.
-      .closest('.comment-new-comments')
-      // Find the preceding <li>, if any, and give it the 'last' class.
-      .prev()
-      .addClass('last')
-      // Go back to the parent <li> and hide it.
-      .end()
-      .hide();
+    return (
+      $placeholder
+        // Find the parent <li>.
+        .closest('.comment-new-comments')
+        // Find the preceding <li>, if any, and give it the 'last' class.
+        .prev()
+        .addClass('last')
+        // Go back to the parent <li> and hide it.
+        .end()
+        .hide()
+    );
   }
 
   /**
    *   The placeholder element passed in as a parameter.
    */
   function show($placeholder) {
-    return $placeholder
-      // Find the parent <li>.
-      .closest('.comment-new-comments')
-      // Find the preceding <li>, if any, and remove its 'last' class, if any.
-      .prev()
-      .removeClass('last')
-      // Go back to the parent <li> and show it.
-      .end()
-      .show();
+    return (
+      $placeholder
+        // Find the parent <li>.
+        .closest('.comment-new-comments')
+        // Find the preceding <li>, if any, and remove its 'last' class, if any.
+        .prev()
+        .removeClass('last')
+        // Go back to the parent <li> and show it.
+        .end()
+        .show()
+    );
   }
 
   /**
     let $placeholder;
     $placeholders.each((index, placeholder) => {
       $placeholder = $(placeholder);
-      const timestamp = parseInt($placeholder.attr('data-history-node-last-comment-timestamp'), 10);
+      const timestamp = parseInt(
+        $placeholder.attr('data-history-node-last-comment-timestamp'),
+        10,
+      );
       fieldName = $placeholder.attr('data-history-node-field-name');
-      const nodeID = $placeholder.closest('[data-history-node-id]').attr('data-history-node-id');
+      const nodeID = $placeholder
+        .closest('[data-history-node-id]')
+        .attr('data-history-node-id');
       const lastViewTimestamp = Drupal.history.getLastRead(nodeID);
 
       // Queue this placeholder's "X new comments" link to be downloaded from
      *   Data about new comment links indexed by nodeID.
      */
     function render(results) {
-      Object.keys(results || {}).forEach((nodeID) => {
+      Object.keys(results || {}).forEach(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'))
+            .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) {
       render(drupalSettings.comment.newCommentsLinks.node[fieldName]);
-    }
-    else {
+    } else {
       $.ajax({
         url: Drupal.url('comments/render_new_comments_node_links'),
         type: 'POST',
       });
     }
   }
-}(jQuery, 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);
+      });
+    },
+  };
+})(jQuery, Drupal, drupalSettings);