mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-02-01 03:12:42 +01:00
commit
d44c7f0bb5
4 changed files with 39 additions and 44 deletions
|
@ -71,6 +71,5 @@
|
||||||
, "pluginfw/client_plugins.js"
|
, "pluginfw/client_plugins.js"
|
||||||
, "pluginfw/shared.js"
|
, "pluginfw/shared.js"
|
||||||
, "pluginfw/hooks.js"
|
, "pluginfw/hooks.js"
|
||||||
, "pluginfw/parent_require.js"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -241,10 +241,11 @@ require.setGlobalKeyPath("require");\n\
|
||||||
|
|
||||||
// Inject my plugins into my child.
|
// Inject my plugins into my child.
|
||||||
iframeHTML.push('\
|
iframeHTML.push('\
|
||||||
<script type="text/javascript">\
|
<script type="text/javascript">\n\
|
||||||
parent_req = require("ep_etherpad-lite/static/js/pluginfw/parent_require");\
|
var hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks");\n\
|
||||||
parent_req.getRequirementFromParent(require, "ep_etherpad-lite/static/js/pluginfw/hooks");\
|
var plugins = require("ep_etherpad-lite/static/js/pluginfw/client_plugins");\n\
|
||||||
parent_req.getRequirementFromParent(require, "ep_etherpad-lite/static/js/pluginfw/client_plugins");\
|
hooks.plugins = plugins;\n\
|
||||||
|
plugins.adoptPluginsFromAncestorsOf(window);\n\
|
||||||
</script>\
|
</script>\
|
||||||
');
|
');
|
||||||
|
|
||||||
|
|
|
@ -34,3 +34,37 @@ exports.update = function (cb) {
|
||||||
callback();
|
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;
|
||||||
|
|
|
@ -1,39 +0,0 @@
|
||||||
/**
|
|
||||||
* This module allows passing require modules instances to
|
|
||||||
* embedded iframes in a page.
|
|
||||||
* For example, if a page has the "plugins" module initialized,
|
|
||||||
* it is important to use exactly the same "plugins" instance
|
|
||||||
* inside iframes as well. Otherwise, plugins cannot save any
|
|
||||||
* state.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instructs the require object that when a reqModuleName module
|
|
||||||
* needs to be loaded, that it iterates through the parents of the
|
|
||||||
* current window until it finds one who can execute "require"
|
|
||||||
* statements and asks it to perform require on reqModuleName.
|
|
||||||
*
|
|
||||||
* @params requireDefObj Require object which supports define
|
|
||||||
* statements. This object is accessible after loading require-kernel.
|
|
||||||
* @params reqModuleName Module name e.g. (ep_etherpad-lite/static/js/plugins)
|
|
||||||
*/
|
|
||||||
exports.getRequirementFromParent = function(requireDefObj, reqModuleName) {
|
|
||||||
// Force the 'undefinition' of the modules (if they already have been loaded).
|
|
||||||
delete (requireDefObj._definitions)[reqModuleName];
|
|
||||||
delete (requireDefObj._modules)[reqModuleName];
|
|
||||||
requireDefObj.define(reqModuleName, function(require, exports, module) {
|
|
||||||
var t = parent;
|
|
||||||
var max = 0; // make sure I don't go up more than 10 times
|
|
||||||
while (typeof(t) != "undefined") {
|
|
||||||
max++;
|
|
||||||
if (max==10)
|
|
||||||
break;
|
|
||||||
if (typeof(t.require) != "undefined") {
|
|
||||||
module.exports = t.require(reqModuleName);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
t = t.parent;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
Loading…
Reference in a new issue