2020-11-23 13:24:19 -05:00
|
|
|
let $, jQuery;
|
|
|
|
$ = jQuery = require('ep_etherpad-lite/static/js/rjquery').$;
|
|
|
|
const _ = require('underscore');
|
2012-05-28 18:39:32 -07:00
|
|
|
|
2020-11-23 13:24:19 -05:00
|
|
|
const pluginUtils = require('./shared');
|
|
|
|
const defs = require('./plugin_defs');
|
2012-05-28 18:39:32 -07:00
|
|
|
|
|
|
|
exports.baseURL = '';
|
|
|
|
|
|
|
|
exports.ensure = function (cb) {
|
2020-11-23 13:24:19 -05:00
|
|
|
if (!defs.loaded) exports.update(cb);
|
|
|
|
else cb();
|
2012-05-28 18:39:32 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.update = function (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-11-23 13:24:19 -05:00
|
|
|
const callback = function () { setTimeout(cb, 0); };
|
|
|
|
$.ajaxSetup({cache: false});
|
|
|
|
jQuery.getJSON(`${exports.baseURL}pluginfw/plugin-definitions.json`).done((data) => {
|
2020-09-06 15:27:18 -04:00
|
|
|
defs.plugins = data.plugins;
|
|
|
|
defs.parts = data.parts;
|
2020-11-23 13:24:19 -05:00
|
|
|
defs.hooks = pluginUtils.extractHooks(defs.parts, 'client_hooks');
|
2020-09-06 15:27:18 -04:00
|
|
|
defs.loaded = true;
|
2012-05-28 18:39:32 -07:00
|
|
|
callback();
|
2020-11-23 13:24:19 -05:00
|
|
|
}).fail((e) => {
|
|
|
|
console.error(`Failed to load plugin-definitions: ${err}`);
|
2020-06-07 12:01:14 +01:00
|
|
|
callback();
|
|
|
|
});
|
2012-05-28 18:39:32 -07:00
|
|
|
};
|
2012-09-11 20:45:14 -07:00
|
|
|
|
|
|
|
function adoptPluginsFromAncestorsOf(frame) {
|
|
|
|
// Bind plugins with parent;
|
2020-11-23 13:24:19 -05:00
|
|
|
let parentRequire = null;
|
2012-09-11 20:45:14 -07:00
|
|
|
try {
|
|
|
|
while (frame = frame.parent) {
|
2020-11-23 13:24:19 -05:00
|
|
|
if (typeof (frame.require) !== 'undefined') {
|
2012-09-11 20:45:14 -07:00
|
|
|
parentRequire = frame.require;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
// Silence (this can only be a XDomain issue).
|
|
|
|
}
|
|
|
|
if (parentRequire) {
|
2020-11-23 13:24:19 -05:00
|
|
|
const ancestorPluginDefs = parentRequire('ep_etherpad-lite/static/js/pluginfw/plugin_defs');
|
2020-09-06 15:27:18 -04:00
|
|
|
defs.hooks = ancestorPluginDefs.hooks;
|
|
|
|
defs.loaded = ancestorPluginDefs.loaded;
|
|
|
|
defs.parts = ancestorPluginDefs.parts;
|
|
|
|
defs.plugins = ancestorPluginDefs.plugins;
|
2020-11-23 13:24:19 -05:00
|
|
|
const ancestorPlugins = parentRequire('ep_etherpad-lite/static/js/pluginfw/client_plugins');
|
2020-09-06 15:27:18 -04:00
|
|
|
exports.baseURL = ancestorPlugins.baseURL;
|
|
|
|
exports.ensure = ancestorPlugins.ensure;
|
|
|
|
exports.update = ancestorPlugins.update;
|
2012-09-11 20:45:14 -07:00
|
|
|
} else {
|
2020-11-23 13:24:19 -05:00
|
|
|
throw new Error('Parent plugins could not be found.');
|
2012-09-11 20:45:14 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.adoptPluginsFromAncestorsOf = adoptPluginsFromAncestorsOf;
|