fix(hooks): fallback handling for core invocations of hooks.fire

+ .on() which is the same as .register()
This commit is contained in:
Julian Lam
2021-01-26 14:23:38 -05:00
parent 01c9b1847e
commit 412d285850
2 changed files with 5 additions and 0 deletions

View File

@@ -9,6 +9,7 @@ define('hooks', [], () => {
Hooks.loaded[hookName] = Hooks.loaded[hookName] || new Set();
Hooks.loaded[hookName].add(listener);
};
Hooks.on = Hooks.register;
Hooks.hasListeners = hookName => Hooks.loaded[hookName] && Hooks.loaded[hookName].length > 0;
@@ -19,6 +20,9 @@ define('hooks', [], () => {
const _fireActionHook = (hookName, data) => {
Hooks.loaded[hookName].forEach(listener => listener(data));
// Backwards compatibility (remove this when we eventually remove jQuery from NodeBB core)
$(window).trigger(hookName, data);
};
const _fireStaticHook = (hookName, data) => {

View File

@@ -64,6 +64,7 @@ JS.scripts = {
'public/src/modules/translator.js',
'public/src/modules/components.js',
'public/src/modules/hooks.js',
'public/src/modules/sort.js',
'public/src/modules/navigator.js',
'public/src/modules/topicSelect.js',