Custom media messages in plugin support
authorDarren <darren@darrenwhitlen.com>
Sun, 23 Mar 2014 22:33:38 +0000 (22:33 +0000)
committerDarren <darren@darrenwhitlen.com>
Sun, 23 Mar 2014 22:33:38 +0000 (22:33 +0000)
client/src/app.js
client/src/views/mediamessage.js

index c15b76937c240240515f0dd2470d329e3f71f83a..8349f697aa7be36f603d6eb05ff7650522bc2061 100644 (file)
@@ -24,15 +24,19 @@ _kiwi.global = {
     // TODO: think of a better term for this as it will also refer to queries\r
     channels: undefined, // TODO: Limited access to panels list\r
 \r
+    addMediaMessageType: function(match, buildHtml) {\r
+        _kiwi.view.MediaMessage.addType(match, buildHtml);\r
+    },\r
+\r
     // Event managers for plugins\r
     components: {\r
         EventComponent: function(event_source, proxy_event_name) {\r
             function proxyEvent(event_name, event_data) {\r
                 if (proxy_event_name !== 'all') {\r
                     event_data = event_name.event_data;\r
-                    event_name = event_name.event_name\r
+                    event_name = event_name.event_name;\r
                 }\r
-//console.log(proxy_event_name, event_name, event_data);\r
+\r
                 this.trigger(event_name, event_data);\r
             }\r
 \r
index 369c1ddaa500b74e6ee13827e71ea8ecebc0537a..bd5b5726d7e406143c05c12caf6e46c34ddc89ba 100644 (file)
@@ -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 += '<span class="media image" data-type="image" data-url="' + url + '" title="Open Image"><a class="open"><i class="icon-chevron-right"></i></a></span>';