Update mediamessage.js
authorportshner <shay@wads.ca>
Fri, 24 May 2013 21:06:59 +0000 (18:06 -0300)
committerportshner <shay@wads.ca>
Fri, 24 May 2013 21:06:59 +0000 (18:06 -0300)
Add youtube support to MediaType/MediaMessage

client/assets/src/views/mediamessage.js

index 5a6d131f817b5fd5b02e9fe89a30983d0717f318..c8defe89328db4cf5943b2a8b13b87cf1ecb6466 100644 (file)
@@ -89,6 +89,26 @@ _kiwi.view.MediaMessage = Backbone.View.extend({
             });
 
             return $('<div>Loading Reddit thread..</div>');
+        },
+          youtube: function () {
+            var that = this;
+               
+               $.ajax({
+                url: 'http://query.yahooapis.com/v1/public/yql',
+                    data: {
+                        q: "select * from json where url ='http://www.youtube.com/oembed?url="+ this.url + "&format=json'",
+                        format: "json"
+                    },
+                    dataType: "jsonp",
+                success: function (data) {
+                       that.$content.find('.content').html(data["query"]["results"]["json"]["html"]);
+                },
+                error: function (result) {
+                    console.log("Sorry no data found.");
+                }
+            });
+               
+        return $('<div>Loading video..</div>');
         }
     }
 
@@ -114,7 +134,12 @@ _kiwi.view.MediaMessage = Backbone.View.extend({
         if (matches) {
             html += '<span class="media reddit" data-type="reddit" data-url="' + url + '" title="Reddit thread"><a class="open"><i class="icon-chevron-right"></i></a></span>';
         }
-
+        
+        // Is youtube?
+        matches = (/youtube\.com\/watch\?v\=([a-zA-Z0-9_\-]+)?/gi).exec(url);
+        if (matches) {
+            html += '<span class="media youtube" data-type="youtube" data-url="' + url + '" title="YouTube Video"><a class="open"><i class="icon-chevron-right"></i></a></span>';
+        }
         return html;
     }
-});
\ No newline at end of file
+});