mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
refactor(hooks): deprecate action:script.load client-side hook
Use `static:script.init` instead.
This commit is contained in:
@@ -319,9 +319,22 @@ ajaxify = window.ajaxify || {};
|
|||||||
if (tpl_url.startsWith('admin')) {
|
if (tpl_url.startsWith('admin')) {
|
||||||
location = '';
|
location = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
require(['hooks', location + tpl_url], (hooks, module) => {
|
||||||
|
if (module && module.init) {
|
||||||
|
module.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
hooks.fire('static:script.init', { tpl_url }).then(ajaxify.loadExtraScripts.bind(null, tpl_url, callback));
|
||||||
|
}, function () {
|
||||||
|
// ignore 404 error
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
ajaxify.loadExtraScripts = (tpl_url, callback) => {
|
||||||
var data = {
|
var data = {
|
||||||
tpl_url: tpl_url,
|
tpl_url: tpl_url,
|
||||||
scripts: [location + tpl_url],
|
scripts: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
$(window).trigger('action:script.load', data);
|
$(window).trigger('action:script.load', data);
|
||||||
@@ -329,6 +342,16 @@ ajaxify = window.ajaxify || {};
|
|||||||
// Require and parse modules
|
// Require and parse modules
|
||||||
var outstanding = data.scripts.length;
|
var outstanding = data.scripts.length;
|
||||||
|
|
||||||
|
if (outstanding && !app.flags.actionScriptLoadDeprecation) {
|
||||||
|
console.group('Deprecation Notice');
|
||||||
|
console.warn('The "action:script.load" event has been deprecated and will be removed in NodeBB v1.18.0. Please attach a listener to the "static:script.init" client-side hook instead');
|
||||||
|
data.scripts.forEach((script) => {
|
||||||
|
console.info(`Affected script: ${typeof script === 'function' ? script.name || 'anonymous ' + script.toString() : script}`);
|
||||||
|
});
|
||||||
|
console.groupEnd();
|
||||||
|
app.flags.actionScriptLoadDeprecation = 1;
|
||||||
|
}
|
||||||
|
|
||||||
data.scripts.map(function (script) {
|
data.scripts.map(function (script) {
|
||||||
if (typeof script === 'function') {
|
if (typeof script === 'function') {
|
||||||
return function (next) {
|
return function (next) {
|
||||||
|
|||||||
Reference in New Issue
Block a user