From 92f5c146fddcfb9109bab4cc7ca6ac4ed412fbe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Sat, 2 Sep 2023 00:07:35 -0400 Subject: [PATCH] feat: add data-allow-dupe and data-navigator-ignore these can be used by plugins like q&n to dupe a post instead of relying on magic -1 index --- public/src/client/topic/posts.js | 6 +++--- public/src/modules/navigator.js | 8 ++++---- src/views/partials/data/topic.tpl | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/public/src/client/topic/posts.js b/public/src/client/topic/posts.js index 6653941d64..3c2e009cde 100644 --- a/public/src/client/topic/posts.js +++ b/public/src/client/topic/posts.js @@ -189,7 +189,7 @@ define('forum/topic/posts', [ } data.posts = data.posts.filter(function (post) { - return post.index === -1 || $('[component="post"][data-pid="' + post.pid + '"]').length === 0; + return post.allowDupe || $('[component="post"][data-pid="' + post.pid + '"]').length === 0; }); } @@ -214,9 +214,9 @@ define('forum/topic/posts', [ html = html.filter(function () { const $this = $(this); const pid = $this.attr('data-pid'); - const index = parseInt($this.attr('data-index'), 10); + const allowDupe = $this.attr('data-allow-dupe'); const isPost = $this.is('[component="post"]'); - return !isPost || index === -1 || (pid && $('[component="post"][data-pid="' + pid + '"]').length === 0); + return !isPost || allowDupe || (pid && $('[component="post"][data-pid="' + pid + '"]').length === 0); }); const removedEls = infinitescroll.removeExtra($('[component="post"]'), direction, Math.max(20, config.postsPerPage * 2)); diff --git a/public/src/modules/navigator.js b/public/src/modules/navigator.js index 98c0752312..b0e75ec8e9 100644 --- a/public/src/modules/navigator.js +++ b/public/src/modules/navigator.js @@ -478,7 +478,7 @@ define('navigator', [ navigator.update = function () { let newIndex = index; - const els = $(navigator.selector); + const els = $(navigator.selector).filter((i, el) => !el.getAttribute('data-navigator-ignore')); if (els.length) { newIndex = parseInt(els.first().attr('data-index'), 10) + 1; } @@ -585,7 +585,7 @@ define('navigator', [ }; navigator.scrollTop = function (index) { - if ($(navigator.selector + '[data-index="' + index + '"]').length) { + if ($(`${navigator.selector}[data-index="${index}"]:not([data-navigator-ignore])`).length) { navigator.scrollToIndex(index, true); } else { ajaxify.go(generateUrl()); @@ -597,7 +597,7 @@ define('navigator', [ return; } - if ($(navigator.selector + '[data-index="' + index + '"]').length) { + if ($(`${navigator.selector}[data-index="${index}"]:not([data-navigator-ignore])`).length) { navigator.scrollToIndex(index, true); } else { index = parseInt(index, 10) + 1; @@ -654,7 +654,7 @@ define('navigator', [ }; navigator.scrollToPostIndex = function (postIndex, highlight, duration) { - const scrollTo = components.get('post', 'index', postIndex); + const scrollTo = $(`[component="post"][data-index="${postIndex}"]:not([data-navigator-ignore])`); navigator.scrollToElement(scrollTo, highlight, duration, postIndex); }; diff --git a/src/views/partials/data/topic.tpl b/src/views/partials/data/topic.tpl index ea6fea2a3c..4c3b70640c 100644 --- a/src/views/partials/data/topic.tpl +++ b/src/views/partials/data/topic.tpl @@ -1 +1 @@ -data-index="{posts.index}" data-pid="{posts.pid}" data-uid="{posts.uid}" data-timestamp="{posts.timestamp}" data-username="{posts.user.username}" data-userslug="{posts.user.userslug}" itemscope itemtype="http://schema.org/Comment" \ No newline at end of file +data-index="{posts.index}" data-pid="{posts.pid}" data-uid="{posts.uid}" data-timestamp="{posts.timestamp}" data-username="{posts.user.username}" data-userslug="{posts.user.userslug}"{{{ if posts.allowDupe }}} data-allow-dupe="1"{{{ end }}}{{{ if posts.navigatorIgnore }}} data-navigator-ignore="1"{{{ end }}} itemscope itemtype="http://schema.org/Comment" \ No newline at end of file