From: Nick Fisher Date: Fri, 19 Dec 2014 00:39:13 +0000 (+0100) Subject: Add SoundCloud embedding X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=a00899c01681fa0fe7d4347323ac406aa93ac9e0;p=KiwiIRC.git Add SoundCloud embedding Works on urls like: - soundcloud.com/:username - soundcloud.com/:username/:track - soundcloud.com/:username/sets/:playlist - soundcloud.com/groups/groupName --- diff --git a/client/src/views/mediamessage.js b/client/src/views/mediamessage.js index e876b9f..f86d99a 100644 --- a/client/src/views/mediamessage.js +++ b/client/src/views/mediamessage.js @@ -145,7 +145,7 @@ _kiwi.view.MediaMessage = Backbone.View.extend({ var spot = { url: 'https://embed.spotify.com/?uri=' + uri, width: 300, - height: 80 + height: 80 }; break; case "artist": @@ -162,6 +162,21 @@ _kiwi.view.MediaMessage = Backbone.View.extend({ return $(html); }, + soundcloud: function () { + var url = this.$el.data('url'), + $content = this.$content.find('.content'); + + $.getJSON('http://soundcloud.com/oembed', { url: url }) + .then(function (data) { + $content.empty().append( + $(data.html).attr('height', data.height - 100) + ); + }, function () { + $content.html(_kiwi.global.i18n.translate('client_views_mediamessage_notfound').fetch()); + }); + + return _kiwi.global.i18n.translate('client_models_applet_loading').fetch(); + }, custom: function() { var type = this.constructor.types[this.$el.data('index')]; @@ -172,7 +187,6 @@ _kiwi.view.MediaMessage = Backbone.View.extend({ return $(type.buildHtml(this.$el.data('url'))); } - } }, { @@ -246,6 +260,11 @@ _kiwi.view.MediaMessage = Backbone.View.extend({ html += ''; } + matches = (/(?:m\.)?(soundcloud\.com(?:\/.+))/i).exec(url); + if (matches) { + html += ''; + } + return html; } });