2023-06-25 13:22:01 +02:00
|
|
|
// @ts-nocheck
|
2023-06-25 00:05:01 +02:00
|
|
|
import * as pluginUtils from "./shared.js";
|
|
|
|
import * as defs from "./plugin_defs.js";
|
2020-12-16 06:10:41 +03:30
|
|
|
'use strict';
|
2023-06-25 13:22:01 +02:00
|
|
|
|
2020-12-16 06:10:41 +03:30
|
|
|
const adoptPluginsFromAncestorsOf = (frame) => {
|
2023-06-25 00:05:01 +02:00
|
|
|
// Bind plugins with parent;
|
|
|
|
let parentRequire = null;
|
|
|
|
try {
|
|
|
|
while ((frame = frame.parent)) {
|
|
|
|
if (typeof (frame.require) !== 'undefined') {
|
|
|
|
parentRequire = frame.require;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (error) {
|
|
|
|
// Silence (this can only be a XDomain issue).
|
|
|
|
console.error(error);
|
2012-09-11 20:45:14 -07:00
|
|
|
}
|
2023-06-25 00:05:01 +02:00
|
|
|
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');
|
|
|
|
ancestorPlugins.baseURL;
|
|
|
|
ancestorPlugins.ensure;
|
|
|
|
ancestorPlugins.update;
|
|
|
|
};
|
|
|
|
export const baseURL = '';
|
|
|
|
export const ensure = (cb) => !defs.loaded ? exports.update(cb) : cb();
|
|
|
|
export const 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.
|
|
|
|
const callback = () => setTimeout(cb, 0);
|
|
|
|
jQuery.getJSON(`${exports.baseURL}pluginfw/plugin-definitions.json?v=${clientVars.randomVersionString}`).done((data) => {
|
|
|
|
defs.plugins = data.plugins;
|
|
|
|
defs.parts = data.parts;
|
|
|
|
defs.hooks = pluginUtils.extractHooks(defs.parts, 'client_hooks');
|
|
|
|
defs.loaded = true;
|
|
|
|
callback();
|
|
|
|
}).fail((err) => {
|
|
|
|
console.error(`Failed to load plugin-definitions: ${err}`);
|
|
|
|
callback();
|
|
|
|
});
|
2020-12-16 06:10:41 +03:30
|
|
|
};
|
2023-06-25 00:05:01 +02:00
|
|
|
export { adoptPluginsFromAncestorsOf as baseURL };
|
|
|
|
export { adoptPluginsFromAncestorsOf as ensure };
|
|
|
|
export { adoptPluginsFromAncestorsOf as update };
|
|
|
|
export { adoptPluginsFromAncestorsOf };
|