From 93944953640cc2fd2af05f63cd32b809ca2b7e6b Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Mon, 28 May 2012 18:58:55 -0700 Subject: [PATCH] Inject plugins into hooks. --- src/static/js/pluginfw/hooks.js | 17 ++++++++--------- src/templates/pad.html | 2 ++ src/templates/timeslider.html | 3 +++ 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/static/js/pluginfw/hooks.js b/src/static/js/pluginfw/hooks.js index 44f5fc3f0..d9a14d857 100644 --- a/src/static/js/pluginfw/hooks.js +++ b/src/static/js/pluginfw/hooks.js @@ -1,4 +1,3 @@ -var plugins = require("./plugins"); var async = require("async"); var _ = require("underscore"); @@ -71,8 +70,8 @@ exports.flatten = function (lst) { exports.callAll = function (hook_name, args) { if (!args) args = {}; - if (plugins.hooks[hook_name] === undefined) return []; - return _.flatten(_.map(plugins.hooks[hook_name], function (hook) { + if (exports.plugins.hooks[hook_name] === undefined) return []; + return _.flatten(_.map(exports.plugins.hooks[hook_name], function (hook) { return hookCallWrapper(hook, hook_name, args); }), true); } @@ -80,9 +79,9 @@ exports.callAll = function (hook_name, args) { exports.aCallAll = function (hook_name, args, cb) { if (!args) args = {}; if (!cb) cb = function () {}; - if (plugins.hooks[hook_name] === undefined) return cb(null, []); + if (exports.plugins.hooks[hook_name] === undefined) return cb(null, []); async.map( - plugins.hooks[hook_name], + exports.plugins.hooks[hook_name], function (hook, cb) { hookCallWrapper(hook, hook_name, args, function (res) { cb(null, res); }); }, @@ -94,8 +93,8 @@ exports.aCallAll = function (hook_name, args, cb) { exports.callFirst = function (hook_name, args) { if (!args) args = {}; - if (plugins.hooks[hook_name] === undefined) return []; - return exports.syncMapFirst(plugins.hooks[hook_name], function (hook) { + if (exports.plugins.hooks[hook_name] === undefined) return []; + return exports.syncMapFirst(exports.plugins.hooks[hook_name], function (hook) { return hookCallWrapper(hook, hook_name, args); }); } @@ -103,9 +102,9 @@ exports.callFirst = function (hook_name, args) { exports.aCallFirst = function (hook_name, args, cb) { if (!args) args = {}; if (!cb) cb = function () {}; - if (plugins.hooks[hook_name] === undefined) return cb(null, []); + if (exports.plugins.hooks[hook_name] === undefined) return cb(null, []); exports.mapFirst( - plugins.hooks[hook_name], + exports.plugins.hooks[hook_name], function (hook, cb) { hookCallWrapper(hook, hook_name, args, function (res) { cb(null, res); }); }, diff --git a/src/templates/pad.html b/src/templates/pad.html index 1f179785a..c12647831 100644 --- a/src/templates/pad.html +++ b/src/templates/pad.html @@ -374,6 +374,8 @@ plugins.baseURL = baseURL; plugins.update(function () { + hooks.plugins = plugins; + // Call documentReady hook $(function() { hooks.aCallAll('documentReady'); diff --git a/src/templates/timeslider.html b/src/templates/timeslider.html index 02af9f6cc..d02a5f644 100644 --- a/src/templates/timeslider.html +++ b/src/templates/timeslider.html @@ -179,6 +179,9 @@ plugins.baseURL = baseURL; plugins.update(function () { + var hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks'); + hooks.plugins = plugins; + var timeslider = require('ep_etherpad-lite/static/js/timeslider') timeslider.baseURL = baseURL; timeslider.init();