From b3996e54d6f335ebdd1abeb4b6036509f3311116 Mon Sep 17 00:00:00 2001 From: Louis T Date: Sun, 23 Mar 2014 18:48:22 -0400 Subject: [PATCH] Add spotify to medamessage.js --- client/src/views/mediamessage.js | 62 ++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 22 deletions(-) diff --git a/client/src/views/mediamessage.js b/client/src/views/mediamessage.js index bd5b572..93907b1 100644 --- a/client/src/views/mediamessage.js +++ b/client/src/views/mediamessage.js @@ -132,35 +132,44 @@ _kiwi.view.MediaMessage = Backbone.View.extend({ }); return $('
' + _kiwi.global.i18n.translate('client_views_mediamessage_load_gist').fetch() + '...
'); - } - } - }, { + }, - /** - * 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}); - }, + spotify: function () { + var uri = this.$el.data('uri'); + var method = this.$el.data('method'); + var that = this; + + switch (method) { + case "track": + case "album": + var spot = { + url: 'https://embed.spotify.com/?uri=' + uri, + width: 300, + height: 80 + }; + break; + case "artist": + var spot = { + url: 'https://embed.spotify.com/follow/1/?uri=' + uri +'&size=detail&theme=dark', + width: 300, + height: 56 + }; + break; + }; + + var html = ''; + + return $(html); + }, + } + }, { + // 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 += ''; @@ -196,6 +205,15 @@ _kiwi.view.MediaMessage = Backbone.View.extend({ html += ''; } + // Is this a spotify link? + matches = (/http:\/\/(?:play|open\.)?spotify.com\/(album|track|artist)\/([a-zA-Z0-9]+)\/?/i).exec(url); + if (matches) { + // Make it a Spotify URI! (spotify::) + var method = matches[1], + uri = "spotify:" + matches[1] + ":" + matches[2]; + html += ''; + } + return html; } }); -- 2.25.1