summaryrefslogtreecommitdiff
path: root/src/static/js/pluginfw/plugins.js
diff options
context:
space:
mode:
authorEgil Moeller <egil.moller@freecode.no>2012-03-27 22:36:48 +0200
committerEgil Moeller <egil.moller@freecode.no>2012-03-27 22:36:48 +0200
commit6120a0b7aa0213a2699913b0629053d7aa4ff349 (patch)
treeffe2555ea8661fdb161d4c060d5d0cca51f2ebbc /src/static/js/pluginfw/plugins.js
parent668725b89273c6df0efb8aea731755e98a868c56 (diff)
parentbeec69ac1c7f87925133013f54d26d6497b0da04 (diff)
downloadetherpad-lite-6120a0b7aa0213a2699913b0629053d7aa4ff349.zip
Merge branch 'develop' of git://github.com/Pita/etherpad-lite
Diffstat (limited to 'src/static/js/pluginfw/plugins.js')
-rw-r--r--src/static/js/pluginfw/plugins.js36
1 files changed, 24 insertions, 12 deletions
diff --git a/src/static/js/pluginfw/plugins.js b/src/static/js/pluginfw/plugins.js
index 5017962b..058f1351 100644
--- a/src/static/js/pluginfw/plugins.js
+++ b/src/static/js/pluginfw/plugins.js
@@ -1,5 +1,7 @@
exports.isClient = typeof global != "object";
+var _;
+
if (!exports.isClient) {
var npm = require("npm/lib/npm.js");
var readInstalled = require("./read-installed.js");
@@ -11,6 +13,11 @@ if (!exports.isClient) {
var tsort = require("./tsort");
var util = require("util");
var extend = require("node.extend");
+ _ = require("underscore");
+}else{
+ var $, jQuery
+ $ = jQuery = require("ep_etherpad-lite/static/js/rjquery").$;
+ _ = require("ep_etherpad-lite/static/js/underscore");
}
exports.prefix = 'ep_';
@@ -27,17 +34,17 @@ exports.ensure = function (cb) {
}
exports.formatPlugins = function () {
- return Object.keys(exports.plugins).join(", ");
+ return _.keys(exports.plugins).join(", ");
}
exports.formatParts = function () {
- return exports.parts.map(function (part) { return part.full_name; }).join("\n");
+ return _.map(exports.parts, function (part) { return part.full_name; }).join("\n");
}
exports.formatHooks = function () {
var res = [];
- Object.keys(exports.hooks).forEach(function (hook_name) {
- exports.hooks[hook_name].forEach(function (hook) {
+ _.chain(exports.hooks).keys().forEach(function (hook_name) {
+ _.forEach(exports.hooks[hook_name], function (hook) {
res.push(hook.hook_name + ": " + hook.hook_fn_name + " from " + hook.part.full_name);
});
});
@@ -47,7 +54,7 @@ exports.formatHooks = function () {
exports.loadFn = function (path) {
var x = path.split(":");
var fn = require(x[0]);
- x[1].split(".").forEach(function (name) {
+ _.each(x[1].split("."), function (name) {
fn = fn[name];
});
return fn;
@@ -55,8 +62,8 @@ exports.loadFn = function (path) {
exports.extractHooks = function (parts, hook_set_name) {
var hooks = {};
- parts.forEach(function (part) {
- Object.keys(part[hook_set_name] || {}).forEach(function (hook_name) {
+ _.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];
var hook_fn = exports.loadFn(part[hook_set_name][hook_name]);
@@ -79,6 +86,9 @@ if (exports.isClient) {
exports.hooks = exports.extractHooks(exports.parts, "client_hooks");
exports.loaded = true;
cb();
+ }).error(function(xhr, s, err){
+ console.error("Failed to load plugin-definitions: " + err);
+ cb();
});
}
} else {
@@ -111,7 +121,7 @@ exports.getPackages = function (cb) {
if (er) cb(er, null);
var packages = {};
function flatten(deps) {
- Object.keys(deps).forEach(function (name) {
+ _.chain(deps).keys().each(function (name) {
if (name.indexOf(exports.prefix) == 0) {
packages[name] = extend({}, deps[name]);
// Delete anything that creates loops so that the plugin
@@ -143,7 +153,7 @@ exports.loadPlugin = function (packages, plugin_name, plugins, parts, cb) {
var plugin = JSON.parse(data);
plugin.package = packages[plugin_name];
plugins[plugin_name] = plugin;
- plugin.parts.forEach(function (part) {
+ _.each(plugin.parts, function (part) {
part.plugin = plugin_name;
part.full_name = plugin_name + "/" + part.name;
parts[part.full_name] = part;
@@ -158,11 +168,11 @@ exports.loadPlugin = function (packages, plugin_name, plugins, parts, cb) {
exports.partsToParentChildList = function (parts) {
var res = [];
- Object.keys(parts).forEach(function (name) {
- (parts[name].post || []).forEach(function (child_name) {
+ _.chain(parts).keys().forEach(function (name) {
+ _.each(parts[name].post || [], function (child_name) {
res.push([name, child_name]);
});
- (parts[name].pre || []).forEach(function (parent_name) {
+ _.each(parts[name].pre || [], function (parent_name) {
res.push([parent_name, name]);
});
if (!parts[name].pre && !parts[name].post) {
@@ -172,6 +182,8 @@ exports.partsToParentChildList = function (parts) {
return res;
}
+
+// Used only in Node, so no need for _
exports.sortParts = function(parts) {
return tsort(
exports.partsToParentChildList(parts)