summaryrefslogtreecommitdiff
path: root/source/libs/on-new-comments.ts
diff options
context:
space:
mode:
authorGravatar Flo Edelmann <florian-edelmann@online.de> 2020-04-01 17:17:51 +0200
committerGravatar GitHub <noreply@github.com> 2020-04-01 17:17:51 +0200
commit073b65379a8e5f6a6cb1597b2339416d30a25686 (patch)
tree4c50dd5da5265702e3c89e8ed8d71abf76e5db2b /source/libs/on-new-comments.ts
parent52991fea170973356c3fd54edd14b8ff046c053a (diff)
downloadrefined-github-073b65379a8e5f6a6cb1597b2339416d30a25686.tar.gz
refined-github-073b65379a8e5f6a6cb1597b2339416d30a25686.tar.zst
refined-github-073b65379a8e5f6a6cb1597b2339416d30a25686.zip
Fix `hide-inactive-deployments` and "Load more..." detection (#2948)
Diffstat (limited to 'source/libs/on-new-comments.ts')
-rw-r--r--source/libs/on-new-comments.ts12
1 files changed, 9 insertions, 3 deletions
diff --git a/source/libs/on-new-comments.ts b/source/libs/on-new-comments.ts
index 265ad867..3a6724aa 100644
--- a/source/libs/on-new-comments.ts
+++ b/source/libs/on-new-comments.ts
@@ -1,5 +1,5 @@
import select from 'select-dom';
-import delegate, {DelegateSubscription} from 'delegate-it';
+import delegate, {DelegateSubscription, DelegateEvent} from 'delegate-it';
const discussionsWithListeners = new WeakSet();
const handlers = new Set<VoidFunction>();
@@ -11,6 +11,12 @@ function run(): void {
handlers.forEach(async callback => callback());
}
+// The form is detached just before the `page:loaded` event is triggered so the event won’t bubble up and `delegate` won’t catch it.
+// This intermediate handler is required to catch the `page:loaded` event on the detached element.
+function paginationSubmitHandler({delegateTarget: form}: DelegateEvent): void {
+ form.addEventListener('page:loaded', run, {once: true});
+}
+
function removeListeners(): void {
for (const subscription of delegates) {
subscription.destroy();
@@ -38,8 +44,8 @@ function addListeners(): void {
childList: true
});
- // When hidden comments are loaded by clicking "Load more..."
- delegates.add(delegate('.js-ajax-pagination', 'page:loaded', run));
+ // When hidden comments are loaded by clicking "Load more…"
+ delegates.add(delegate('.js-ajax-pagination', 'submit', paginationSubmitHandler));
// Outdated comment are loaded later using an include-fragment element
delegates.add(delegate('details.outdated-comment > include-fragment', 'load', run, true));