diff --git a/src/node/utils/tar.json b/src/node/utils/tar.json index 9bb2027e..080da442 100644 --- a/src/node/utils/tar.json +++ b/src/node/utils/tar.json @@ -71,6 +71,5 @@ , "pluginfw/client_plugins.js" , "pluginfw/shared.js" , "pluginfw/hooks.js" - , "pluginfw/parent_require.js" ] } diff --git a/src/static/js/ace.js b/src/static/js/ace.js index 6bea8d22..db62deb4 100644 --- a/src/static/js/ace.js +++ b/src/static/js/ace.js @@ -241,10 +241,11 @@ require.setGlobalKeyPath("require");\n\ // Inject my plugins into my child. iframeHTML.push('\ -\ '); diff --git a/src/static/js/pluginfw/client_plugins.js b/src/static/js/pluginfw/client_plugins.js index 27350028..feb2a14f 100644 --- a/src/static/js/pluginfw/client_plugins.js +++ b/src/static/js/pluginfw/client_plugins.js @@ -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; diff --git a/src/static/js/pluginfw/parent_require.js b/src/static/js/pluginfw/parent_require.js deleted file mode 100644 index cd3b9218..00000000 --- a/src/static/js/pluginfw/parent_require.js +++ /dev/null @@ -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; - } - }); -}