mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: pass module name to static:script.init, +comments
I feel it is difficult to know exactly what the original use-cases were for these hooks, so some comments may be helpful.
This commit is contained in:
@@ -324,6 +324,7 @@ ajaxify = window.ajaxify || {};
|
|||||||
scripts: [location + tpl_url],
|
scripts: [location + tpl_url],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Hint: useful if you want to load a module on a specific page (append module name to `scripts`)
|
||||||
$(window).trigger('action:script.load', data);
|
$(window).trigger('action:script.load', data);
|
||||||
|
|
||||||
// Require and parse modules
|
// Require and parse modules
|
||||||
@@ -338,12 +339,14 @@ ajaxify = window.ajaxify || {};
|
|||||||
}
|
}
|
||||||
if (typeof script === 'string') {
|
if (typeof script === 'string') {
|
||||||
return function (next) {
|
return function (next) {
|
||||||
require([script], function (script) {
|
require(['hooks', script], function (hooks, module) {
|
||||||
$(window).trigger('static:script.init', { tpl_url, module: script });
|
// Hint: useful if you want to override a loaded library (e.g. replace core client-side logic), or call a method other than .init()
|
||||||
if (script && script.init) {
|
hooks.fire('static:script.init', { tpl_url, name: script, module }).then(() => {
|
||||||
script.init();
|
if (module && module.init) {
|
||||||
|
module.init();
|
||||||
}
|
}
|
||||||
next();
|
next();
|
||||||
|
});
|
||||||
}, function () {
|
}, function () {
|
||||||
// ignore 404 error
|
// ignore 404 error
|
||||||
next();
|
next();
|
||||||
|
|||||||
Reference in New Issue
Block a user