etherpad-lite/src/static/js/pluginfw/client_plugins.js

59 lines
1.8 KiB
JavaScript
Raw Normal View History

2020-12-16 06:10:41 +03:30
'use strict';
2020-11-23 13:24:19 -05:00
const pluginUtils = require('./shared');
const defs = require('./plugin_defs');
exports.baseURL = '';
2020-12-16 06:10:41 +03:30
exports.ensure = (cb) => !defs.loaded ? exports.update(cb) : cb();
2020-12-16 06:10:41 +03:30
exports.update = (cb) => {
// It appears that this response (see #620) may interrupt the current thread
// of execution on Firefox. This schedules the response in the run-loop,
// which appears to fix the issue.
2020-12-16 06:10:41 +03:30
const callback = () => setTimeout(cb, 0);
2021-02-15 08:52:38 +01:00
jQuery.getJSON(
`${exports.baseURL}pluginfw/plugin-definitions.json?v=${clientVars.randomVersionString}`
).done((data) => {
defs.plugins = data.plugins;
defs.parts = data.parts;
2020-11-23 13:24:19 -05:00
defs.hooks = pluginUtils.extractHooks(defs.parts, 'client_hooks');
defs.loaded = true;
callback();
2020-12-16 06:10:41 +03:30
}).fail((err) => {
2020-11-23 13:24:19 -05:00
console.error(`Failed to load plugin-definitions: ${err}`);
2020-06-07 12:01:14 +01:00
callback();
});
};
2020-12-16 06:10:41 +03:30
const adoptPluginsFromAncestorsOf = (frame) => {
// Bind plugins with parent;
2020-11-23 13:24:19 -05:00
let parentRequire = null;
try {
2020-12-16 06:10:41 +03:30
while ((frame = frame.parent)) {
2020-11-23 13:24:19 -05:00
if (typeof (frame.require) !== 'undefined') {
parentRequire = frame.require;
break;
}
}
} catch (error) {
// Silence (this can only be a XDomain issue).
2020-12-16 06:10:41 +03:30
console.error(error);
}
2020-12-16 06:10:41 +03:30
if (!parentRequire) throw new Error('Parent plugins could not be found.');
const ancestorPluginDefs = parentRequire('ep_etherpad-lite/static/js/pluginfw/plugin_defs');
defs.hooks = ancestorPluginDefs.hooks;
defs.loaded = ancestorPluginDefs.loaded;
defs.parts = ancestorPluginDefs.parts;
defs.plugins = ancestorPluginDefs.plugins;
const ancestorPlugins = parentRequire('ep_etherpad-lite/static/js/pluginfw/client_plugins');
exports.baseURL = ancestorPlugins.baseURL;
exports.ensure = ancestorPlugins.ensure;
exports.update = ancestorPlugins.update;
};
exports.adoptPluginsFromAncestorsOf = adoptPluginsFromAncestorsOf;