Update Composer, update everything
This commit is contained in:
parent
ea3e94409f
commit
dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions
25
web/core/modules/comment/js/comment-by-viewer.es6.js
Normal file
25
web/core/modules/comment/js/comment-by-viewer.es6.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
/**
|
||||
* @file
|
||||
* Attaches behaviors for the Comment module's "by-viewer" class.
|
||||
*/
|
||||
|
||||
(function($, Drupal, drupalSettings) {
|
||||
/**
|
||||
* Add 'by-viewer' class to comments written by the current user.
|
||||
*
|
||||
* @type {Drupal~behavior}
|
||||
*/
|
||||
Drupal.behaviors.commentByViewer = {
|
||||
attach(context) {
|
||||
const currentUserID = parseInt(drupalSettings.user.uid, 10);
|
||||
$('[data-comment-user-id]')
|
||||
.filter(function() {
|
||||
return (
|
||||
parseInt(this.getAttribute('data-comment-user-id'), 10) ===
|
||||
currentUserID
|
||||
);
|
||||
})
|
||||
.addClass('by-viewer');
|
||||
},
|
||||
};
|
||||
})(jQuery, Drupal, drupalSettings);
|
|
@ -1,26 +1,17 @@
|
|||
/**
|
||||
* @file
|
||||
* Attaches behaviors for the Comment module's "by-viewer" class.
|
||||
*/
|
||||
* DO NOT EDIT THIS FILE.
|
||||
* See the following change record for more information,
|
||||
* https://www.drupal.org/node/2815083
|
||||
* @preserve
|
||||
**/
|
||||
|
||||
(function ($, Drupal, drupalSettings) {
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Add 'by-viewer' class to comments written by the current user.
|
||||
*
|
||||
* @type {Drupal~behavior}
|
||||
*/
|
||||
Drupal.behaviors.commentByViewer = {
|
||||
attach: function (context) {
|
||||
attach: function attach(context) {
|
||||
var currentUserID = parseInt(drupalSettings.user.uid, 10);
|
||||
$('[data-comment-user-id]')
|
||||
.filter(function () {
|
||||
return parseInt(this.getAttribute('data-comment-user-id'), 10) === currentUserID;
|
||||
})
|
||||
.addClass('by-viewer');
|
||||
$('[data-comment-user-id]').filter(function () {
|
||||
return parseInt(this.getAttribute('data-comment-user-id'), 10) === currentUserID;
|
||||
}).addClass('by-viewer');
|
||||
}
|
||||
};
|
||||
|
||||
})(jQuery, Drupal, drupalSettings);
|
||||
})(jQuery, Drupal, drupalSettings);
|
102
web/core/modules/comment/js/comment-new-indicator.es6.js
Normal file
102
web/core/modules/comment/js/comment-new-indicator.es6.js
Normal file
|
@ -0,0 +1,102 @@
|
|||
/**
|
||||
* @file
|
||||
* Attaches behaviors for the Comment module's "new" indicator.
|
||||
*
|
||||
* May only be loaded for authenticated users, with the History module
|
||||
* installed.
|
||||
*/
|
||||
|
||||
(function($, Drupal, window) {
|
||||
/**
|
||||
* Processes the markup for "new comment" indicators.
|
||||
*
|
||||
* @param {jQuery} $placeholders
|
||||
* The elements that should be processed.
|
||||
*/
|
||||
function processCommentNewIndicators($placeholders) {
|
||||
let isFirstNewComment = true;
|
||||
const newCommentString = Drupal.t('new');
|
||||
let $placeholder;
|
||||
|
||||
$placeholders.each((index, placeholder) => {
|
||||
$placeholder = $(placeholder);
|
||||
const timestamp = parseInt(
|
||||
$placeholder.attr('data-comment-timestamp'),
|
||||
10,
|
||||
);
|
||||
const $node = $placeholder.closest('[data-history-node-id]');
|
||||
const nodeID = $node.attr('data-history-node-id');
|
||||
const lastViewTimestamp = Drupal.history.getLastRead(nodeID);
|
||||
|
||||
if (timestamp > lastViewTimestamp) {
|
||||
// Turn the placeholder into an actual "new" indicator.
|
||||
const $comment = $(placeholder)
|
||||
.removeClass('hidden')
|
||||
.text(newCommentString)
|
||||
.closest('.js-comment')
|
||||
// Add 'new' class to the comment, so it can be styled.
|
||||
.addClass('new');
|
||||
|
||||
// Insert "new" anchor just before the "comment-<cid>" anchor if
|
||||
// this is the first new comment in the DOM.
|
||||
if (isFirstNewComment) {
|
||||
isFirstNewComment = false;
|
||||
$comment.prev().before('<a id="new" />');
|
||||
// If the URL points to the first new comment, then scroll to that
|
||||
// comment.
|
||||
if (window.location.hash === '#new') {
|
||||
window.scrollTo(
|
||||
0,
|
||||
$comment.offset().top - Drupal.displace.offsets.top,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
|
@ -1,66 +1,15 @@
|
|||
/**
|
||||
* @file
|
||||
* Attaches behaviors for the Comment module's "new" indicator.
|
||||
*
|
||||
* May only be loaded for authenticated users, with the History module
|
||||
* installed.
|
||||
*/
|
||||
* DO NOT EDIT THIS FILE.
|
||||
* See the following change record for more information,
|
||||
* https://www.drupal.org/node/2815083
|
||||
* @preserve
|
||||
**/
|
||||
|
||||
(function ($, Drupal, window) {
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Renders "new" comment indicators wherever necessary.
|
||||
*
|
||||
* @type {Drupal~behavior}
|
||||
*
|
||||
* @prop {Drupal~behaviorAttach} attach
|
||||
* Attaches "new" comment indicators behavior.
|
||||
*/
|
||||
Drupal.behaviors.commentNewIndicator = {
|
||||
attach: function (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.
|
||||
var nodeIDs = [];
|
||||
var $placeholders = $(context)
|
||||
.find('[data-comment-timestamp]')
|
||||
.once('history')
|
||||
.filter(function () {
|
||||
var $placeholder = $(this);
|
||||
var commentTimestamp = parseInt($placeholder.attr('data-comment-timestamp'), 10);
|
||||
var nodeID = $placeholder.closest('[data-history-node-id]').attr('data-history-node-id');
|
||||
if (Drupal.history.needsServerCheck(nodeID, commentTimestamp)) {
|
||||
nodeIDs.push(nodeID);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
if ($placeholders.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Fetch the node read timestamps from the server.
|
||||
Drupal.history.fetchTimestamps(nodeIDs, function () {
|
||||
processCommentNewIndicators($placeholders);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Processes the markup for "new comment" indicators.
|
||||
*
|
||||
* @param {jQuery} $placeholders
|
||||
* The elements that should be processed.
|
||||
*/
|
||||
function processCommentNewIndicators($placeholders) {
|
||||
var isFirstNewComment = true;
|
||||
var newCommentString = Drupal.t('new');
|
||||
var $placeholder;
|
||||
var $placeholder = void 0;
|
||||
|
||||
$placeholders.each(function (index, placeholder) {
|
||||
$placeholder = $(placeholder);
|
||||
|
@ -70,21 +19,12 @@
|
|||
var lastViewTimestamp = Drupal.history.getLastRead(nodeID);
|
||||
|
||||
if (timestamp > lastViewTimestamp) {
|
||||
// Turn the placeholder into an actual "new" indicator.
|
||||
var $comment = $(placeholder)
|
||||
.removeClass('hidden')
|
||||
.text(newCommentString)
|
||||
.closest('.js-comment')
|
||||
// Add 'new' class to the comment, so it can be styled.
|
||||
.addClass('new');
|
||||
var $comment = $(placeholder).removeClass('hidden').text(newCommentString).closest('.js-comment').addClass('new');
|
||||
|
||||
// Insert "new" anchor just before the "comment-<cid>" anchor if
|
||||
// this is the first new comment in the DOM.
|
||||
if (isFirstNewComment) {
|
||||
isFirstNewComment = false;
|
||||
$comment.prev().before('<a id="new" />');
|
||||
// If the URL points to the first new comment, then scroll to that
|
||||
// comment.
|
||||
|
||||
if (window.location.hash === '#new') {
|
||||
window.scrollTo(0, $comment.offset().top - Drupal.displace.offsets.top);
|
||||
}
|
||||
|
@ -93,4 +33,28 @@
|
|||
});
|
||||
}
|
||||
|
||||
})(jQuery, Drupal, window);
|
||||
Drupal.behaviors.commentNewIndicator = {
|
||||
attach: function attach(context) {
|
||||
var nodeIDs = [];
|
||||
var $placeholders = $(context).find('[data-comment-timestamp]').once('history').filter(function () {
|
||||
var $placeholder = $(this);
|
||||
var commentTimestamp = parseInt($placeholder.attr('data-comment-timestamp'), 10);
|
||||
var 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;
|
||||
}
|
||||
|
||||
Drupal.history.fetchTimestamps(nodeIDs, function () {
|
||||
processCommentNewIndicators($placeholders);
|
||||
});
|
||||
}
|
||||
};
|
||||
})(jQuery, Drupal, window);
|
195
web/core/modules/comment/js/node-new-comments-link.es6.js
Normal file
195
web/core/modules/comment/js/node-new-comments-link.es6.js
Normal file
|
@ -0,0 +1,195 @@
|
|||
/**
|
||||
* @file
|
||||
* Attaches behaviors for the Comment module's "X new comments" link.
|
||||
*
|
||||
* May only be loaded for authenticated users, with the History module
|
||||
* installed.
|
||||
*/
|
||||
|
||||
(function($, Drupal, drupalSettings) {
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
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()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a "new comment" element.
|
||||
*
|
||||
* @param {jQuery} $placeholder
|
||||
* The placeholder element of the new comment link.
|
||||
*/
|
||||
function remove($placeholder) {
|
||||
hide($placeholder).remove();
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows 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.
|
||||
*/
|
||||
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()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes new comment links and adds appropriate text in relevant cases.
|
||||
*
|
||||
* @param {jQuery} $placeholders
|
||||
* The placeholder elements of the current page.
|
||||
*/
|
||||
function processNodeNewCommentLinks($placeholders) {
|
||||
// Figure out which placeholders need the "x new comments" links.
|
||||
const $placeholdersToUpdate = {};
|
||||
let fieldName = 'comment';
|
||||
let $placeholder;
|
||||
$placeholders.each((index, placeholder) => {
|
||||
$placeholder = $(placeholder);
|
||||
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 lastViewTimestamp = Drupal.history.getLastRead(nodeID);
|
||||
|
||||
// Queue this placeholder's "X new comments" link to be downloaded from
|
||||
// the server.
|
||||
if (timestamp > lastViewTimestamp) {
|
||||
$placeholdersToUpdate[nodeID] = $placeholder;
|
||||
}
|
||||
// No "X new comments" link necessary; remove it from the DOM.
|
||||
else {
|
||||
remove($placeholder);
|
||||
}
|
||||
});
|
||||
|
||||
// Perform an AJAX request to retrieve node view timestamps.
|
||||
const nodeIDs = Object.keys($placeholdersToUpdate);
|
||||
if (nodeIDs.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the "X new comments" links.
|
||||
*
|
||||
* Either use the data embedded in the page or perform an AJAX request to
|
||||
* retrieve the same data.
|
||||
*
|
||||
* @param {object} results
|
||||
* Data about new comment links indexed by nodeID.
|
||||
*/
|
||||
function render(results) {
|
||||
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',
|
||||
),
|
||||
)
|
||||
.removeClass('hidden');
|
||||
show($placeholdersToUpdate[nodeID]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (drupalSettings.comment && drupalSettings.comment.newCommentsLinks) {
|
||||
render(drupalSettings.comment.newCommentsLinks.node[fieldName]);
|
||||
} else {
|
||||
$.ajax({
|
||||
url: Drupal.url('comments/render_new_comments_node_links'),
|
||||
type: 'POST',
|
||||
data: { 'node_ids[]': nodeIDs, field_name: fieldName },
|
||||
dataType: 'json',
|
||||
success: render,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
|
@ -1,120 +1,27 @@
|
|||
/**
|
||||
* @file
|
||||
* Attaches behaviors for the Comment module's "X new comments" link.
|
||||
*
|
||||
* May only be loaded for authenticated users, with the History module
|
||||
* installed.
|
||||
*/
|
||||
* DO NOT EDIT THIS FILE.
|
||||
* See the following change record for more information,
|
||||
* https://www.drupal.org/node/2815083
|
||||
* @preserve
|
||||
**/
|
||||
|
||||
(function ($, Drupal, drupalSettings) {
|
||||
|
||||
'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.
|
||||
*/
|
||||
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.closest('.comment-new-comments').prev().addClass('last').end().hide();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a "new comment" element.
|
||||
*
|
||||
* @param {jQuery} $placeholder
|
||||
* The placeholder element of the new comment link.
|
||||
*/
|
||||
function remove($placeholder) {
|
||||
hide($placeholder).remove();
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows 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.
|
||||
*/
|
||||
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.closest('.comment-new-comments').prev().removeClass('last').end().show();
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes new comment links and adds appropriate text in relevant cases.
|
||||
*
|
||||
* @param {jQuery} $placeholders
|
||||
* The placeholder elements of the current page.
|
||||
*/
|
||||
function processNodeNewCommentLinks($placeholders) {
|
||||
// Figure out which placeholders need the "x new comments" links.
|
||||
var $placeholdersToUpdate = {};
|
||||
var fieldName = 'comment';
|
||||
var $placeholder;
|
||||
var $placeholder = void 0;
|
||||
$placeholders.each(function (index, placeholder) {
|
||||
$placeholder = $(placeholder);
|
||||
var timestamp = parseInt($placeholder.attr('data-history-node-last-comment-timestamp'), 10);
|
||||
|
@ -122,56 +29,65 @@
|
|||
var nodeID = $placeholder.closest('[data-history-node-id]').attr('data-history-node-id');
|
||||
var lastViewTimestamp = Drupal.history.getLastRead(nodeID);
|
||||
|
||||
// Queue this placeholder's "X new comments" link to be downloaded from
|
||||
// the server.
|
||||
if (timestamp > lastViewTimestamp) {
|
||||
$placeholdersToUpdate[nodeID] = $placeholder;
|
||||
}
|
||||
// No "X new comments" link necessary; remove it from the DOM.
|
||||
else {
|
||||
remove($placeholder);
|
||||
}
|
||||
} else {
|
||||
remove($placeholder);
|
||||
}
|
||||
});
|
||||
|
||||
// Perform an AJAX request to retrieve node view timestamps.
|
||||
var nodeIDs = Object.keys($placeholdersToUpdate);
|
||||
if (nodeIDs.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the "X new comments" links.
|
||||
*
|
||||
* Either use the data embedded in the page or perform an AJAX request to
|
||||
* retrieve the same data.
|
||||
*
|
||||
* @param {object} results
|
||||
* Data about new comment links indexed by nodeID.
|
||||
*/
|
||||
function render(results) {
|
||||
for (var nodeID in results) {
|
||||
if (results.hasOwnProperty(nodeID) && $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'))
|
||||
.removeClass('hidden');
|
||||
Object.keys(results || {}).forEach(function (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')).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',
|
||||
data: {'node_ids[]': nodeIDs, 'field_name': fieldName},
|
||||
data: { 'node_ids[]': nodeIDs, field_name: fieldName },
|
||||
dataType: 'json',
|
||||
success: render
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
})(jQuery, Drupal, drupalSettings);
|
||||
Drupal.behaviors.nodeNewCommentsLink = {
|
||||
attach: function attach(context) {
|
||||
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($placeholder);
|
||||
return true;
|
||||
}
|
||||
|
||||
remove($placeholder);
|
||||
return false;
|
||||
});
|
||||
|
||||
if ($placeholders.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
Drupal.history.fetchTimestamps(nodeIDs, function () {
|
||||
processNodeNewCommentLinks($placeholders);
|
||||
});
|
||||
}
|
||||
};
|
||||
})(jQuery, Drupal, drupalSettings);
|
Reference in a new issue