diff --git a/core/modules/forum/forum.libraries.yml b/core/modules/forum/forum.libraries.yml index bf7079e..7e75c49 100644 --- a/core/modules/forum/forum.libraries.yml +++ b/core/modules/forum/forum.libraries.yml @@ -3,3 +3,26 @@ forum.index: css: component: css/forum.theme.css: {} + +drupal.forum-topic-new-indicator: + version: VERSION + js: + js/forum-topic-new-indicator: {} + dependencies: + - core/jquery + - core/jquery.once + - core/drupal + - history/api + - core/drupal.displace + +drupal.forum-reply-new-indicator: + version: VERSION + js: + js/forum-reply-new-indicator: {} + dependencies: + - core/jquery + - core/jquery.once + - core/drupal + - history/api + - core/drupal.displace + diff --git a/core/modules/forum/js/forum-reply-new-indicator.js b/core/modules/forum/js/forum-reply-new-indicator.js new file mode 100644 index 0000000..49b2c4f --- /dev/null +++ b/core/modules/forum/js/forum-reply-new-indicator.js @@ -0,0 +1,26 @@ +/** + * Attaches behaviors for a forum topic's "new replies" indicator on /forum/%tid. + * + * May only be loaded for authenticated users, with the History module + * installed. + */ +(function ($, Drupal, window) { + + "use strict"; + + /** + * Render "new replies" indicators wherever necessary. + */ + Drupal.behaviors.forumReplyNewIndicator = { + attach: function (context) { + // Collect all "new replies" forum indicator placeholders (and their corresponding + // node IDs) + var nodeIDs = []; + var $placeholders = $(context) + .find('[data-forum-reply-timestamp]') + .once('history') + .filter(function () { + var $placeholder = $(this); + var forumTimestamp = parseInt($placeholder.attr('data-forum-topic-timestamp'), 10); + + } diff --git a/core/modules/forum/js/forum-topic-new-indicator.js b/core/modules/forum/js/forum-topic-new-indicator.js new file mode 100644 index 0000000..f3d081a --- /dev/null +++ b/core/modules/forum/js/forum-topic-new-indicator.js @@ -0,0 +1,26 @@ +/** + * Attaches behaviors for the Forum module's "new topics" indicator on /forum. + * + * May only be loaded for authenticated users, with the History module + * installed. + */ +(function ($, Drupal, window) { + + "use strict"; + + /** + * Render "new topics" indicators wherever necessary. + */ + Drupal.behaviors.forumTopicNewIndicator = { + attach: function (context) { + // Collect all "new topics" forum indicator placeholders (and their corresponding + // node IDs) + var nodeIDs = []; + var $placeholders = $(context) + .find('[data-forum-topic-timestamp]') + .once('history') + .filter(function () { + var $placeholder = $(this); + var forumTimestamp = parseInt($placeholder.attr('data-forum-topic-timestamp'), 10); + + }