From f1452889b5e80f3dfea907ec377e153c2798664a Mon Sep 17 00:00:00 2001 From: Darren Date: Sun, 23 Mar 2014 22:33:38 +0000 Subject: [PATCH] Custom media messages in plugin support --- client/src/app.js | 8 ++++++-- client/src/views/mediamessage.js | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/client/src/app.js b/client/src/app.js index c15b769..8349f69 100644 --- a/client/src/app.js +++ b/client/src/app.js @@ -24,15 +24,19 @@ _kiwi.global = { // TODO: think of a better term for this as it will also refer to queries channels: undefined, // TODO: Limited access to panels list + addMediaMessageType: function(match, buildHtml) { + _kiwi.view.MediaMessage.addType(match, buildHtml); + }, + // Event managers for plugins components: { EventComponent: function(event_source, proxy_event_name) { function proxyEvent(event_name, event_data) { if (proxy_event_name !== 'all') { event_data = event_name.event_data; - event_name = event_name.event_name + event_name = event_name.event_name; } -//console.log(proxy_event_name, event_name, event_data); + this.trigger(event_name, event_data); } diff --git a/client/src/views/mediamessage.js b/client/src/views/mediamessage.js index 369c1dd..bd5b572 100644 --- a/client/src/views/mediamessage.js +++ b/client/src/views/mediamessage.js @@ -136,10 +136,31 @@ _kiwi.view.MediaMessage = Backbone.View.extend({ } }, { + /** + * Add a media message type to append HTML after a matching URL + * match() should return true if it wants to handle this URL + * buildHtml() should return the HTML string to append after the URL in the message + */ + addType: function(match, buildHtml) { + if (typeof match !== 'function' || typeof buildHtml !== 'function') + return; + + this.types = this.types || []; + this.types.push({match: match, buildHtml: buildHtml}); + }, + + // Build the closed media HTML from a URL buildHtml: function (url) { var html = '', matches; + _.each(this.types || [], function(type) { + if (!type.match(url)) + return; + + html += type.buildHtml(url); + }); + // Is it an image? if (url.match(/(\.jpe?g|\.gif|\.bmp|\.png)\??$/i)) { html += ''; -- 2.25.1