Skip to content

Commit

Permalink
feat: add data-allow-dupe and data-navigator-ignore
Browse files Browse the repository at this point in the history
these can be used by plugins like q&n to dupe a post
instead of relying on magic -1 index
  • Loading branch information
barisusakli committed Sep 2, 2023
1 parent bdeca04 commit 92f5c14
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions public/src/client/topic/posts.js
Expand Up @@ -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;
});
}

Expand All @@ -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));
Expand Down
8 changes: 4 additions & 4 deletions public/src/modules/navigator.js
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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());
Expand All @@ -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;
Expand Down Expand Up @@ -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);
};

Expand Down
2 changes: 1 addition & 1 deletion 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"
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"

0 comments on commit 92f5c14

Please sign in to comment.