mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-16 10:46:14 +01:00
allowing plugins to subscribe to action:script.load and pass in function references
This commit is contained in:
@@ -253,15 +253,45 @@ $(document).ready(function () {
|
|||||||
|
|
||||||
$(window).trigger('action:script.load', data);
|
$(window).trigger('action:script.load', data);
|
||||||
|
|
||||||
require(data.scripts, function (script) {
|
// Require and parse modules
|
||||||
if (script && script.init) {
|
var outstanding = 0;
|
||||||
script.init();
|
var onReady = function () {
|
||||||
|
if (outstanding) {
|
||||||
|
return setTimeout(onReady, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (callback) {
|
data.scripts = data.scripts.filter(Boolean);
|
||||||
callback();
|
data.scripts.forEach(function (functionRef) {
|
||||||
|
functionRef();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
data.scripts.forEach(function (script, idx) {
|
||||||
|
switch (typeof script) {
|
||||||
|
case 'string':
|
||||||
|
++outstanding;
|
||||||
|
(function (idx) {
|
||||||
|
require([script], function (script) {
|
||||||
|
if (script && script.init) {
|
||||||
|
data.scripts[idx] = script.init;
|
||||||
|
}
|
||||||
|
--outstanding;
|
||||||
|
});
|
||||||
|
}(idx));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'function':
|
||||||
|
// No changes needed
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
// Neither? No comprende
|
||||||
|
data.scripts[idx] = undefined;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
onReady();
|
||||||
};
|
};
|
||||||
|
|
||||||
ajaxify.loadData = function (url, callback) {
|
ajaxify.loadData = function (url, callback) {
|
||||||
|
|||||||
Reference in New Issue
Block a user