diff --git a/src/node/server.js b/src/node/server.js
index d2ef9334..cca76c1f 100755
--- a/src/node/server.js
+++ b/src/node/server.js
@@ -29,6 +29,7 @@ var plugins = require("ep_etherpad-lite/static/js/pluginfw/plugins");
var hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks");
var npm = require("npm/lib/npm.js");
+hooks.plugins = plugins;
//set loglevel
log4js.setGlobalLogLevel(settings.loglevel);
diff --git a/src/node/utils/tar.json b/src/node/utils/tar.json
index 36276767..9bb2027e 100644
--- a/src/node/utils/tar.json
+++ b/src/node/utils/tar.json
@@ -68,7 +68,8 @@
, "security.js"
, "$security.js"
, "json2.js"
- , "pluginfw/plugins.js"
+ , "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 dabe5595..6bea8d22 100644
--- a/src/static/js/ace.js
+++ b/src/static/js/ace.js
@@ -244,7 +244,7 @@ require.setGlobalKeyPath("require");\n\
\
');
diff --git a/src/static/js/ace2_inner.js b/src/static/js/ace2_inner.js
index 07580faa..6bf6720f 100644
--- a/src/static/js/ace2_inner.js
+++ b/src/static/js/ace2_inner.js
@@ -23,7 +23,7 @@ var editor, _, $, jQuery, plugins, Ace2Common;
Ace2Common = require('./ace2_common');
-plugins = require('ep_etherpad-lite/static/js/pluginfw/plugins');
+plugins = require('ep_etherpad-lite/static/js/pluginfw/client_plugins');
$ = jQuery = require('./rjquery').$;
_ = require("./underscore");
diff --git a/src/static/js/pluginfw/client_plugins.js b/src/static/js/pluginfw/client_plugins.js
new file mode 100644
index 00000000..27350028
--- /dev/null
+++ b/src/static/js/pluginfw/client_plugins.js
@@ -0,0 +1,36 @@
+var $, jQuery;
+$ = jQuery = require("ep_etherpad-lite/static/js/rjquery").$;
+var _ = require("underscore");
+
+var pluginUtils = require('./shared');
+
+exports.loaded = false;
+exports.plugins = {};
+exports.parts = [];
+exports.hooks = {};
+exports.baseURL = '';
+
+exports.ensure = function (cb) {
+ if (!exports.loaded)
+ exports.update(cb);
+ else
+ cb();
+};
+
+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.
+ var callback = function () {setTimeout(cb, 0);};
+
+ jQuery.getJSON(exports.baseURL + 'pluginfw/plugin-definitions.json', function(data) {
+ exports.plugins = data.plugins;
+ exports.parts = data.parts;
+ exports.hooks = pluginUtils.extractHooks(exports.parts, "client_hooks");
+ exports.loaded = true;
+ callback();
+ }).error(function(xhr, s, err){
+ console.error("Failed to load plugin-definitions: " + err);
+ callback();
+ });
+};
diff --git a/src/static/js/pluginfw/plugins.js b/src/static/js/pluginfw/plugins.js
index 9a8b7ac5..12ba94a2 100644
--- a/src/static/js/pluginfw/plugins.js
+++ b/src/static/js/pluginfw/plugins.js
@@ -1,30 +1,21 @@
-exports.isClient = typeof global != "object";
+var npm = require("npm/lib/npm.js");
+var readInstalled = require("./read-installed.js");
+var relativize = require("npm/lib/utils/relativize.js");
+var readJson = require("npm/lib/utils/read-json.js");
+var path = require("path");
+var async = require("async");
+var fs = require("fs");
+var tsort = require("./tsort");
+var util = require("util");
+var _ = require("underscore");
-var _;
-
-if (!exports.isClient) {
- var npm = require("npm/lib/npm.js");
- var readInstalled = require("./read-installed.js");
- var relativize = require("npm/lib/utils/relativize.js");
- var readJson = require("npm/lib/utils/read-json.js");
- var path = require("path");
- var async = require("async");
- var fs = require("fs");
- var tsort = require("./tsort");
- var util = require("util");
- _ = require("underscore");
-}else{
- var $, jQuery;
- $ = jQuery = require("ep_etherpad-lite/static/js/rjquery").$;
- _ = require("ep_etherpad-lite/static/js/underscore");
-}
+var pluginUtils = require('./shared');
exports.prefix = 'ep_';
exports.loaded = false;
exports.plugins = {};
exports.parts = [];
exports.hooks = {};
-exports.baseURL = '';
exports.ensure = function (cb) {
if (!exports.loaded)
@@ -43,7 +34,7 @@ exports.formatParts = function () {
exports.formatHooks = function (hook_set_name) {
var res = [];
- var hooks = exports.extractHooks(exports.parts, hook_set_name || "hooks");
+ var hooks = pluginUtils.extractHooks(exports.parts, hook_set_name || "hooks");
_.chain(hooks).keys().forEach(function (hook_name) {
_.forEach(hooks[hook_name], function (hook) {
@@ -53,84 +44,6 @@ exports.formatHooks = function (hook_set_name) {
return "
" + res.join("\n") + "
";
};
-function loadFn(path, hookName) {
- var functionName
- , parts = path.split(":");
-
- // on windows: C:\foo\bar:xyz
- if(parts[0].length == 1) {
- if(parts.length == 3)
- functionName = parts.pop();
- path = parts.join(":");
- }else{
- path = parts[0];
- functionName = parts[1];
- }
-
- var fn = require(path);
- functionName = functionName ? functionName : hookName;
-
- _.each(functionName.split("."), function (name) {
- fn = fn[name];
- });
- return fn;
-};
-
-function extractHooks(parts, hook_set_name, normalizer) {
- var hooks = {};
- _.each(parts,function (part) {
- _.chain(part[hook_set_name] || {})
- .keys()
- .each(function (hook_name) {
- if (hooks[hook_name] === undefined) hooks[hook_name] = [];
-
- var hook_fn_name = part[hook_set_name][hook_name];
-
- /* On the server side, you can't just
- * require("pluginname/whatever") if the plugin is installed as
- * a dependency of another plugin! Bah, pesky little details of
- * npm... */
- if (normalizer) {
- hook_fn_name = normalizer(part, hook_fn_name);
- }
-
- try {
- var hook_fn = loadFn(hook_fn_name, hook_name);
- if (!hook_fn) {
- throw "Not a function";
- }
- } catch (exc) {
- console.error("Failed to load '" + hook_fn_name + "' for '" + part.full_name + "/" + hook_set_name + "/" + hook_name + "': " + exc.toString())
- }
- if (hook_fn) {
- hooks[hook_name].push({"hook_name": hook_name, "hook_fn": hook_fn, "hook_fn_name": hook_fn_name, "part": part});
- }
- });
- });
- return hooks;
-};
-
-
-if (exports.isClient) {
- 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.
- var callback = function () {setTimeout(cb, 0);};
-
- jQuery.getJSON(exports.baseURL + 'pluginfw/plugin-definitions.json', function(data) {
- exports.plugins = data.plugins;
- exports.parts = data.parts;
- exports.hooks = extractHooks(exports.parts, "client_hooks");
- exports.loaded = true;
- callback();
- }).error(function(xhr, s, err){
- console.error("Failed to load plugin-definitions: " + err);
- callback();
- });
- };
-} else {
-
exports.callInit = function (cb) {
var hooks = require("./hooks");
async.map(
@@ -171,7 +84,7 @@ exports.update = function (cb) {
if (err) cb(err);
exports.plugins = plugins;
exports.parts = sortParts(parts);
- exports.hooks = exports.extractHooks(exports.parts, "hooks", exports.pathNormalization);
+ exports.hooks = pluginUtils.extractHooks(exports.parts, "hooks", exports.pathNormalization);
exports.loaded = true;
exports.callInit(cb);
}
@@ -206,9 +119,6 @@ exports.getPackages = function (cb) {
});
};
-}
-
-
function loadPlugin(packages, plugin_name, plugins, parts, cb) {
var plugin_path = path.resolve(packages[plugin_name].path, "ep.json");
fs.readFile(
diff --git a/src/static/js/pluginfw/shared.js b/src/static/js/pluginfw/shared.js
new file mode 100644
index 00000000..4df71aee
--- /dev/null
+++ b/src/static/js/pluginfw/shared.js
@@ -0,0 +1,61 @@
+var _ = require("underscore");
+
+function loadFn(path, hookName) {
+ var functionName
+ , parts = path.split(":");
+
+ // on windows: C:\foo\bar:xyz
+ if (parts[0].length == 1) {
+ if (parts.length == 3) {
+ functionName = parts.pop();
+ }
+ path = parts.join(":");
+ } else {
+ path = parts[0];
+ functionName = parts[1];
+ }
+
+ var fn = require(path);
+ functionName = functionName ? functionName : hookName;
+
+ _.each(functionName.split("."), function (name) {
+ fn = fn[name];
+ });
+ return fn;
+};
+
+function extractHooks(parts, hook_set_name, normalizer) {
+ var hooks = {};
+ _.each(parts,function (part) {
+ _.chain(part[hook_set_name] || {})
+ .keys()
+ .each(function (hook_name) {
+ if (hooks[hook_name] === undefined) hooks[hook_name] = [];
+
+ var hook_fn_name = part[hook_set_name][hook_name];
+
+ /* On the server side, you can't just
+ * require("pluginname/whatever") if the plugin is installed as
+ * a dependency of another plugin! Bah, pesky little details of
+ * npm... */
+ if (normalizer) {
+ hook_fn_name = normalizer(part, hook_fn_name);
+ }
+
+ try {
+ var hook_fn = loadFn(hook_fn_name, hook_name);
+ if (!hook_fn) {
+ throw "Not a function";
+ }
+ } catch (exc) {
+ console.error("Failed to load '" + hook_fn_name + "' for '" + part.full_name + "/" + hook_set_name + "/" + hook_name + "': " + exc.toString())
+ }
+ if (hook_fn) {
+ hooks[hook_name].push({"hook_name": hook_name, "hook_fn": hook_fn, "hook_fn_name": hook_fn_name, "part": part});
+ }
+ });
+ });
+ return hooks;
+};
+
+exports.extractHooks = extractHooks;
diff --git a/src/templates/pad.html b/src/templates/pad.html
index c1264783..425e476d 100644
--- a/src/templates/pad.html
+++ b/src/templates/pad.html
@@ -369,7 +369,7 @@
document.domain = document.domain; // for comet
}
- var plugins = require('ep_etherpad-lite/static/js/pluginfw/plugins');
+ var plugins = require('ep_etherpad-lite/static/js/pluginfw/client_plugins');
var hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks');
plugins.baseURL = baseURL;
diff --git a/src/templates/timeslider.html b/src/templates/timeslider.html
index d02a5f64..469ddd94 100644
--- a/src/templates/timeslider.html
+++ b/src/templates/timeslider.html
@@ -175,7 +175,7 @@
document.domain = document.domain; // for comet
}
- var plugins = require('ep_etherpad-lite/static/js/pluginfw/plugins');
+ var plugins = require('ep_etherpad-lite/static/js/pluginfw/client_plugins');
plugins.baseURL = baseURL;
plugins.update(function () {