Kiwi API: addMediaMessageType()
authorDarren <darren@darrenwhitlen.com>
Wed, 16 Apr 2014 22:29:23 +0000 (23:29 +0100)
committerDarren <darren@darrenwhitlen.com>
Wed, 16 Apr 2014 22:29:23 +0000 (23:29 +0100)
client/src/views/mediamessage.js

index f7f09d4c1198f64711c6d251bd031adc021fb59d..908b83bf395a1e24f19752f8842e8e5e99fb7e62 100644 (file)
@@ -163,13 +163,23 @@ _kiwi.view.MediaMessage = Backbone.View.extend({
         },
 
 
+        custom: function() {
+            var type = this.constructor.types[this.$el.data('index')];
+
+            if (!type)
+                return;
+
+            return $(type.buildHtml(this.$el.data('url')));
+        }
+
+
     }
     }, {
 
     /**
      * 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
+     * match() should return a truthy value if it wants to handle this URL
+     * buildHtml() should return the HTML string to be used within the drop down
      */
     addType: function(match, buildHtml) {
         if (typeof match !== 'function' || typeof buildHtml !== 'function')
@@ -184,11 +194,12 @@ _kiwi.view.MediaMessage = Backbone.View.extend({
     buildHtml: function (url) {
         var html = '', matches;
 
-        _.each(this.types || [], function(type) {
+        _.each(this.types || [], function(type, type_idx) {
             if (!type.match(url))
                 return;
 
-            html += type.buildHtml(url);
+            // Add which media type should handle this media message. Will be read when it's clicked on
+            html += '<span class="media" title="Open" data-type="custom" data-index="'+type_idx+'" data-url="' + _.escape(url) + '"><a class="open"><i class="icon-chevron-right"></i></a></span>';
         });
 
         // Is it an image?