Node.js based forum software built for the modern web
feat: invoke intents.trigger() on guest topic creation and reply actions
Julian Lam965e0dd9480f
diff --git a/public/src/client/category.js b/public/src/client/category.jsindex abcaed35a6..0205342311 100644--- a/public/src/client/category.js+++ b/public/src/client/category.js@@ -10,7 +10,8 @@ define('forum/category', ['alerts','api','clipboard',-], function (infinitescroll, navigator, topicList, sort, categorySelector, hooks, alerts, api, clipboard) {+ 'modules/intents',+], function (infinitescroll, navigator, topicList, sort, categorySelector, hooks, alerts, api, clipboard, intents) {const Category = {};$(window).on('action:ajaxify.start', function (ev, data) {@@ -52,6 +53,8 @@ define('forum/category', [new clipboard('[data-clipboard-text]');+ intents.addHandlers();+hooks.fire('action:topics.loaded', { topics: ajaxify.data.topics });hooks.fire('action:category.loaded', { cid: ajaxify.data.cid });};diff --git a/public/src/client/topic.js b/public/src/client/topic.jsindex d6ac87fa97..97a859ac7c 100644--- a/public/src/client/topic.js+++ b/public/src/client/topic.js@@ -17,11 +17,12 @@ define('forum/topic', ['alerts','bootbox','clipboard',+ 'modules/intents',], function (infinitescroll, threadTools, postTools,events, posts, navigator, sort, quickreply,components, storage, hooks, api, alerts,- bootbox, clipboard+ bootbox, clipboard, intents) {const Topic = {};let tid = '0';@@ -75,6 +76,8 @@ define('forum/topic', [handleTopicSearch();+ intents.addHandlers();+hooks.fire('action:topic.loaded', ajaxify.data);};diff --git a/public/src/modules/intents.js b/public/src/modules/intents.jsindex 6b762afe43..8e7227361d 100644--- a/public/src/modules/intents.js+++ b/public/src/modules/intents.js@@ -157,6 +157,22 @@ export function register() {});}+const INTENTS_GUEST_SELECTORS = '[component="topic/reply/guest"], [component="category/post/guest"]';++export function addHandlers() {+ document.removeEventListener('click', _intentsHandler);+ document.addEventListener('click', _intentsHandler, true); // capture phase+}++function _intentsHandler(e) {+ const target = e.target.closest(INTENTS_GUEST_SELECTORS);+ if (target) {+ e.preventDefault();+ e.stopPropagation();+ trigger('create', {});+ }+}+export function trigger(intent, parameters) {const map = list();const requiredIntent = intent.toLowerCase();