X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fcomment%2Fjs%2Fnode-new-comments-link.es6.js;fp=web%2Fcore%2Fmodules%2Fcomment%2Fjs%2Fnode-new-comments-link.es6.js;h=d3d0a0787078b735ce82e64c69888535a6917fc8;hp=a2bdc35b9d7272b4950f55f303a27b73eacf0486;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hpb=74df008bdbb3a11eeea356744f39b802369bda3c
diff --git a/web/core/modules/comment/js/node-new-comments-link.es6.js b/web/core/modules/comment/js/node-new-comments-link.es6.js
index a2bdc35b9..d3d0a0787 100644
--- a/web/core/modules/comment/js/node-new-comments-link.es6.js
+++ b/web/core/modules/comment/js/node-new-comments-link.es6.js
@@ -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.
*
@@ -62,15 +17,17 @@
* The placeholder element passed in as a parameter.
*/
function hide($placeholder) {
- return $placeholder
- // Find the parent
.
- .closest('.comment-new-comments')
- // Find the preceding , if any, and give it the 'last' class.
- .prev()
- .addClass('last')
- // Go back to the parent and hide it.
- .end()
- .hide();
+ return (
+ $placeholder
+ // Find the parent .
+ .closest('.comment-new-comments')
+ // Find the preceding , if any, and give it the 'last' class.
+ .prev()
+ .addClass('last')
+ // Go back to the parent and hide it.
+ .end()
+ .hide()
+ );
}
/**
@@ -93,15 +50,17 @@
* The placeholder element passed in as a parameter.
*/
function show($placeholder) {
- return $placeholder
- // Find the parent .
- .closest('.comment-new-comments')
- // Find the preceding , if any, and remove its 'last' class, if any.
- .prev()
- .removeClass('last')
- // Go back to the parent and show it.
- .end()
- .show();
+ return (
+ $placeholder
+ // Find the parent .
+ .closest('.comment-new-comments')
+ // Find the preceding , if any, and remove its 'last' class, if any.
+ .prev()
+ .removeClass('last')
+ // Go back to the parent and show it.
+ .end()
+ .show()
+ );
}
/**
@@ -117,9 +76,14 @@
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
@@ -149,11 +113,17 @@
* 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]);
}
@@ -162,8 +132,7 @@
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',
@@ -173,4 +142,54 @@
});
}
}
-}(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);