Add SoundCloud embedding
authorNick Fisher <spadgos@gmail.com>
Fri, 19 Dec 2014 00:39:13 +0000 (01:39 +0100)
committerNick Fisher <spadgos@gmail.com>
Fri, 19 Dec 2014 01:04:28 +0000 (02:04 +0100)
Works on urls like:
- soundcloud.com/:username
- soundcloud.com/:username/:track
- soundcloud.com/:username/sets/:playlist
- soundcloud.com/groups/groupName

client/src/views/mediamessage.js

index e876b9f9227df9e70caa2c23c1d1bf51d5239fef..f86d99a9c3168e6d54ddefdca96b7bdcca8eeb2a 100644 (file)
@@ -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 += '<span class="media spotify" data-type="spotify" data-uri="' + uri + '" data-method="' + method + '" title="Spotify ' + method + '"><a class="open"><i class="fa fa-chevron-right"></i></a></span>';
         }
 
+        matches = (/(?:m\.)?(soundcloud\.com(?:\/.+))/i).exec(url);
+        if (matches) {
+            html += '<span class="media soundcloud" data-type="soundcloud" data-url="http://' + matches[1] + '" title="SoundCloud player"><a class="open"><i class="fa fa-chevron-right"></i></a></span>';
+        }
+
         return html;
     }
 });