mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-20 23:46:14 -04:00
Replace ParentRequire hack.
Instead of hacking with the internals of require, make client_plugins aware and capable of sharing behavior.
This commit is contained in:
parent
1258ed3a0d
commit
b691606c4e
4 changed files with 39 additions and 44 deletions
|
@ -34,3 +34,37 @@ exports.update = function (cb) {
|
|||
callback();
|
||||
});
|
||||
};
|
||||
|
||||
function adoptPlugins(plugins) {
|
||||
var keys = [
|
||||
'loaded', 'plugins', 'parts', 'hooks', 'baseURL', 'ensure', 'update'];
|
||||
|
||||
for (var i = 0, ii = keys.length; i < ii; i++) {
|
||||
var key = keys[i];
|
||||
exports[key] = plugins[key];
|
||||
}
|
||||
}
|
||||
|
||||
function adoptPluginsFromAncestorsOf(frame) {
|
||||
// Bind plugins with parent;
|
||||
var 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).
|
||||
}
|
||||
if (parentRequire) {
|
||||
var ancestorPlugins = parentRequire("ep_etherpad-lite/static/js/pluginfw/client_plugins");
|
||||
exports.adoptPlugins(ancestorPlugins);
|
||||
} else {
|
||||
throw new Error("Parent plugins could not be found.")
|
||||
}
|
||||
}
|
||||
|
||||
exports.adoptPlugins = adoptPlugins;
|
||||
exports.adoptPluginsFromAncestorsOf = adoptPluginsFromAncestorsOf;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue