From: Louis T Date: Sun, 23 Mar 2014 23:06:08 +0000 (-0400) Subject: Add Spotify to mediamessage.js WITHOUT breaking prawnsalad's changes X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=8dcc48082d1708fa6ad5c5ada073dd51e9cecf12;p=KiwiIRC.git Add Spotify to mediamessage.js WITHOUT breaking prawnsalad's changes --- diff --git a/client/src/views/mediamessage.js b/client/src/views/mediamessage.js index 93907b1..f7f09d4 100644 --- a/client/src/views/mediamessage.js +++ b/client/src/views/mediamessage.js @@ -166,10 +166,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 += '';