X-Git-Url: https://yaffs.net/gitweb/?a=blobdiff_plain;ds=inline;f=web%2Fcore%2Fmodules%2Ftracker%2Fjs%2Ftracker-history.es6.js;fp=web%2Fcore%2Fmodules%2Ftracker%2Fjs%2Ftracker-history.es6.js;h=dd79f15b9332156c8e6c7c47b2e9ba7aa0845473;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hp=13090008d65e663550408c120c488e0c8db3971c;hpb=74df008bdbb3a11eeea356744f39b802369bda3c;p=yaffs-website
diff --git a/web/core/modules/tracker/js/tracker-history.es6.js b/web/core/modules/tracker/js/tracker-history.es6.js
index 13090008d..dd79f15b9 100644
--- a/web/core/modules/tracker/js/tracker-history.es6.js
+++ b/web/core/modules/tracker/js/tracker-history.es6.js
@@ -3,7 +3,75 @@
*
* May only be loaded for authenticated users, with the History module enabled.
*/
-(function ($, Drupal, window) {
+(function($, Drupal, window) {
+ function processNodeNewIndicators($placeholders) {
+ const newNodeString = Drupal.t('new');
+ const updatedNodeString = Drupal.t('updated');
+
+ $placeholders.each((index, placeholder) => {
+ const timestamp = parseInt(
+ placeholder.getAttribute('data-history-node-timestamp'),
+ 10,
+ );
+ const nodeID = placeholder.getAttribute('data-history-node-id');
+ const lastViewTimestamp = Drupal.history.getLastRead(nodeID);
+
+ if (timestamp > lastViewTimestamp) {
+ const message =
+ lastViewTimestamp === 0 ? newNodeString : updatedNodeString;
+ $(placeholder).append(`${message}`);
+ }
+ });
+ }
+
+ function processNewRepliesIndicators($placeholders) {
+ // Figure out which placeholders need the "x new" replies links.
+ const placeholdersToUpdate = {};
+ $placeholders.each((index, placeholder) => {
+ const timestamp = parseInt(
+ placeholder.getAttribute('data-history-node-last-comment-timestamp'),
+ 10,
+ );
+ const nodeID = placeholder.previousSibling.previousSibling.getAttribute(
+ 'data-history-node-id',
+ );
+ const lastViewTimestamp = Drupal.history.getLastRead(nodeID);
+
+ // Queue this placeholder's "X new" replies link to be downloaded from the
+ // server.
+ if (timestamp > lastViewTimestamp) {
+ placeholdersToUpdate[nodeID] = placeholder;
+ }
+ });
+
+ // Perform an AJAX request to retrieve node view timestamps.
+ const nodeIDs = Object.keys(placeholdersToUpdate);
+ if (nodeIDs.length === 0) {
+ return;
+ }
+ $.ajax({
+ url: Drupal.url('comments/render_new_comments_node_links'),
+ type: 'POST',
+ data: { 'node_ids[]': nodeIDs },
+ dataType: 'json',
+ success(results) {
+ Object.keys(results || {}).forEach(nodeID => {
+ if (placeholdersToUpdate.hasOwnProperty(nodeID)) {
+ const url = results[nodeID].first_new_comment_link;
+ const text = Drupal.formatPlural(
+ results[nodeID].new_comment_count,
+ '1 new',
+ '@count new',
+ );
+ $(placeholdersToUpdate[nodeID]).append(
+ `
${text}`,
+ );
+ }
+ });
+ },
+ });
+ }
+
/**
* Render "new" and "updated" node indicators, as well as "X new" replies links.
*/
@@ -15,8 +83,11 @@
const $nodeNewPlaceholders = $(context)
.find('[data-history-node-timestamp]')
.once('history')
- .filter(function () {
- const nodeTimestamp = parseInt(this.getAttribute('data-history-node-timestamp'), 10);
+ .filter(function() {
+ const nodeTimestamp = parseInt(
+ this.getAttribute('data-history-node-timestamp'),
+ 10,
+ );
const nodeID = this.getAttribute('data-history-node-id');
if (Drupal.history.needsServerCheck(nodeID, nodeTimestamp)) {
nodeIDs.push(nodeID);
@@ -31,14 +102,24 @@
const $newRepliesPlaceholders = $(context)
.find('[data-history-node-last-comment-timestamp]')
.once('history')
- .filter(function () {
- const lastCommentTimestamp = parseInt(this.getAttribute('data-history-node-last-comment-timestamp'), 10);
- const nodeTimestamp = parseInt(this.previousSibling.previousSibling.getAttribute('data-history-node-timestamp'), 10);
+ .filter(function() {
+ const lastCommentTimestamp = parseInt(
+ this.getAttribute('data-history-node-last-comment-timestamp'),
+ 10,
+ );
+ const nodeTimestamp = parseInt(
+ this.previousSibling.previousSibling.getAttribute(
+ 'data-history-node-timestamp',
+ ),
+ 10,
+ );
// Discard placeholders that have zero comments.
if (lastCommentTimestamp === nodeTimestamp) {
return false;
}
- const nodeID = this.previousSibling.previousSibling.getAttribute('data-history-node-id');
+ const nodeID = this.previousSibling.previousSibling.getAttribute(
+ 'data-history-node-id',
+ );
if (Drupal.history.needsServerCheck(nodeID, lastCommentTimestamp)) {
if (nodeIDs.indexOf(nodeID) === -1) {
nodeIDs.push(nodeID);
@@ -49,7 +130,10 @@
return false;
});
- if ($nodeNewPlaceholders.length === 0 && $newRepliesPlaceholders.length === 0) {
+ if (
+ $nodeNewPlaceholders.length === 0 &&
+ $newRepliesPlaceholders.length === 0
+ ) {
return;
}
@@ -60,57 +144,4 @@
});
},
};
-
- function processNodeNewIndicators($placeholders) {
- const newNodeString = Drupal.t('new');
- const updatedNodeString = Drupal.t('updated');
-
- $placeholders.each((index, placeholder) => {
- const timestamp = parseInt(placeholder.getAttribute('data-history-node-timestamp'), 10);
- const nodeID = placeholder.getAttribute('data-history-node-id');
- const lastViewTimestamp = Drupal.history.getLastRead(nodeID);
-
- if (timestamp > lastViewTimestamp) {
- const message = (lastViewTimestamp === 0) ? newNodeString : updatedNodeString;
- $(placeholder).append(`${message}`);
- }
- });
- }
-
- function processNewRepliesIndicators($placeholders) {
- // Figure out which placeholders need the "x new" replies links.
- const placeholdersToUpdate = {};
- $placeholders.each((index, placeholder) => {
- const timestamp = parseInt(placeholder.getAttribute('data-history-node-last-comment-timestamp'), 10);
- const nodeID = placeholder.previousSibling.previousSibling.getAttribute('data-history-node-id');
- const lastViewTimestamp = Drupal.history.getLastRead(nodeID);
-
- // Queue this placeholder's "X new" replies link to be downloaded from the
- // server.
- if (timestamp > lastViewTimestamp) {
- placeholdersToUpdate[nodeID] = placeholder;
- }
- });
-
- // Perform an AJAX request to retrieve node view timestamps.
- const nodeIDs = Object.keys(placeholdersToUpdate);
- if (nodeIDs.length === 0) {
- return;
- }
- $.ajax({
- url: Drupal.url('comments/render_new_comments_node_links'),
- type: 'POST',
- data: { 'node_ids[]': nodeIDs },
- dataType: 'json',
- success(results) {
- Object.keys(results || {}).forEach((nodeID) => {
- if (placeholdersToUpdate.hasOwnProperty(nodeID)) {
- const url = results[nodeID].first_new_comment_link;
- const text = Drupal.formatPlural(results[nodeID].new_comment_count, '1 new', '@count new');
- $(placeholdersToUpdate[nodeID]).append(`
${text}`);
- }
- });
- },
- });
- }
-}(jQuery, Drupal, window));
+})(jQuery, Drupal, window);