Sha256: b6ea6da0abb0a9d778750cd50e77bd14c03bd4712d1d5a43a0a49e29039c3e51
Contents?: true
Size: 1.05 KB
Versions: 11
Compression:
Stored size: 1.05 KB
Contents
(function($) { const COMPONENT_SELECTOR = '[data-thredded-topics]'; const TOPIC_SELECTOR = 'article'; const TOPIC_LINK_SELECTOR = 'h1 a'; const TOPIC_UNREAD_CLASS = 'thredded--topic-unread'; const TOPIC_READ_CLASS = 'thredded--topic-read'; const POSTS_COUNT_SELECTOR = '.thredded--topics--posts-count'; const POSTS_PER_PAGE = 50; function pageNumber(url) { const match = url.match(/\/page-(\d)$/); return match ? +match[1] : 1; } function totalPages(numPosts) { return Math.ceil(numPosts / POSTS_PER_PAGE); } class ThreddedTopics { init($nodes) { $nodes.on('click', TOPIC_LINK_SELECTOR, (evt) => { const $topic = $(evt.target).closest(TOPIC_SELECTOR); if (pageNumber($topic.find('a').prop('href')) == totalPages(+$topic.find(POSTS_COUNT_SELECTOR).text())) { $topic.addClass(TOPIC_READ_CLASS).removeClass(TOPIC_UNREAD_CLASS); } }); } } $(function() { var $nodes = $(COMPONENT_SELECTOR); if ($nodes.length) { new ThreddedTopics().init($nodes); } }); })(jQuery);
Version data entries
11 entries across 11 versions & 1 rubygems