mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-02-01 03:12:42 +01:00
makes plugin architecture work in client-side from inside IFrames as well
This commit is contained in:
parent
0431c15325
commit
1a64a6c1c5
2 changed files with 42 additions and 0 deletions
|
@ -261,6 +261,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">\
|
||||||
|
parent_req = require("./pluginfw/parent_require.js");\
|
||||||
|
parent_req.getRequirementFromParent(require, "ep_etherpad-lite/static/js/pluginfw/hooks");\
|
||||||
|
parent_req.getRequirementFromParent(require, "ep_etherpad-lite/static/js/pluginfw/plugins");\
|
||||||
|
parent_req.getRequirementFromParent(require, "./pluginfw/hooks");\
|
||||||
|
parent_req.getRequirementFromParent(require, "./pluginfw/plugins");\
|
||||||
require.define("/plugins", null);\n\
|
require.define("/plugins", null);\n\
|
||||||
require.define("/plugins.js", function (require, exports, module) {\
|
require.define("/plugins.js", function (require, exports, module) {\
|
||||||
module.exports = require("ep_etherpad-lite/static/js/plugins");\
|
module.exports = require("ep_etherpad-lite/static/js/plugins");\
|
||||||
|
|
37
src/static/js/pluginfw/parent_require.js
Normal file
37
src/static/js/pluginfw/parent_require.js
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
/**
|
||||||
|
* 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) {
|
||||||
|
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