diff --git a/client/index.html b/client/index.html
index 26c9210..b1e0562 100644
--- a/client/index.html
+++ b/client/index.html
@@ -286,7 +286,15 @@
-
+
+
+
+ <% plugins.forEach(function(file) { %>
+
+ <% }) %>
+
diff --git a/client/js/shout.js b/client/js/shout.js
index 3b5a2ac..691676c 100644
--- a/client/js/shout.js
+++ b/client/js/shout.js
@@ -61,7 +61,9 @@ $(function() {
});
function render(name, data) {
- return Handlebars.templates[name](data);
+ data = pluginHandle('onprerender', [name, data])[1];
+ var html = Handlebars.templates[name](data);
+ return pluginHandle('onpostrender', [name, html])[1];
}
Handlebars.registerHelper(
@@ -197,6 +199,8 @@ $(function() {
var chan = chat.find(target);
var from = data.msg.from;
+ data.msg = pluginHandle('onmessage', data.msg);
+
chan.find(".messages")
.append(render("msg", {messages: [data.msg]}))
.trigger("msg", [
@@ -416,6 +420,9 @@ $(function() {
clear();
return;
}
+ text = pluginHandle('oninput', text);
+ if (!text) return;
+
socket.emit("input", {
target: chat.data("id"),
text: text
@@ -751,6 +758,25 @@ $(function() {
});
}, 1000 * 10);
+ $.each(shoutPlugins, function(i, plugin) {
+ if ($.isFunction(plugin)) { plugin(socket); }
+ });
+
+ function pluginHandle(action, data) {
+ var val = data;
+
+ $.each(shoutPlugins, function(i, plugin) {
+ if ($.isFunction(plugin[action])) {
+ var newVal = plugin[action].apply(plugin, (val && !val.length) ? [val] : val);
+ if (newVal !== null && newVal !== undefined) {
+ val = newVal;
+ }
+ }
+ });
+
+ return val;
+ }
+
function clear() {
chat.find(".active .messages").empty();
chat.find(".active .show-more").addClass("show");
diff --git a/src/server.js b/src/server.js
index 7a11b6d..914f174 100644
--- a/src/server.js
+++ b/src/server.js
@@ -13,12 +13,28 @@ var manager = new ClientManager();
module.exports = function(options) {
config = Helper.getConfig();
- config = _.extend(config, options);
+ config = _.extend(config, options, {
+ plugins: []
+ });
var app = express()
.use(index)
.use(express.static("client"));
+ fs.readdir(Helper.HOME + '/plugins', function(err, files) {
+ if (err) {
+ if (err.code !== 'ENOENT') {
+ console.log(err);
+ }
+ return;
+ }
+ if (files.length) {
+ config.plugins = files;
+ app.use('/plugins', express.static(Helper.HOME + '/plugins'));
+ }
+
+ });
+
app.enable("trust proxy");
var server = null;