mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-06 12:31:33 +01:00
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
This commit is contained in:
@@ -189,7 +189,7 @@ define('forum/topic/posts', [
|
|||||||
}
|
}
|
||||||
|
|
||||||
data.posts = data.posts.filter(function (post) {
|
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 () {
|
html = html.filter(function () {
|
||||||
const $this = $(this);
|
const $this = $(this);
|
||||||
const pid = $this.attr('data-pid');
|
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"]');
|
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));
|
const removedEls = infinitescroll.removeExtra($('[component="post"]'), direction, Math.max(20, config.postsPerPage * 2));
|
||||||
|
|||||||
@@ -478,7 +478,7 @@ define('navigator', [
|
|||||||
|
|
||||||
navigator.update = function () {
|
navigator.update = function () {
|
||||||
let newIndex = index;
|
let newIndex = index;
|
||||||
const els = $(navigator.selector);
|
const els = $(navigator.selector).filter((i, el) => !el.getAttribute('data-navigator-ignore'));
|
||||||
if (els.length) {
|
if (els.length) {
|
||||||
newIndex = parseInt(els.first().attr('data-index'), 10) + 1;
|
newIndex = parseInt(els.first().attr('data-index'), 10) + 1;
|
||||||
}
|
}
|
||||||
@@ -585,7 +585,7 @@ define('navigator', [
|
|||||||
};
|
};
|
||||||
|
|
||||||
navigator.scrollTop = function (index) {
|
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);
|
navigator.scrollToIndex(index, true);
|
||||||
} else {
|
} else {
|
||||||
ajaxify.go(generateUrl());
|
ajaxify.go(generateUrl());
|
||||||
@@ -597,7 +597,7 @@ define('navigator', [
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($(navigator.selector + '[data-index="' + index + '"]').length) {
|
if ($(`${navigator.selector}[data-index="${index}"]:not([data-navigator-ignore])`).length) {
|
||||||
navigator.scrollToIndex(index, true);
|
navigator.scrollToIndex(index, true);
|
||||||
} else {
|
} else {
|
||||||
index = parseInt(index, 10) + 1;
|
index = parseInt(index, 10) + 1;
|
||||||
@@ -654,7 +654,7 @@ define('navigator', [
|
|||||||
};
|
};
|
||||||
|
|
||||||
navigator.scrollToPostIndex = function (postIndex, highlight, duration) {
|
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);
|
navigator.scrollToElement(scrollTo, highlight, duration, postIndex);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -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"
|
||||||
Reference in New Issue
Block a user