Update mediamessage.js
authorportshner <shay@wads.ca>
Fri, 24 May 2013 22:13:11 +0000 (19:13 -0300)
committerportshner <shay@wads.ca>
Fri, 24 May 2013 22:13:11 +0000 (19:13 -0300)
added IMGUR support for images

client/assets/src/views/mediamessage.js

index eb12989826ab52bbabc151893dab409419e85977..0ec3d8ee47796babd49c2be154dcea5df60b49f7 100644 (file)
@@ -55,7 +55,18 @@ _kiwi.view.MediaMessage = Backbone.View.extend({
             return $('<a href="' + this.url + '" target="_blank"><img height="100" src="' + this.url + '" /></a>');
         },
 
+        imgur: function () {
+            var that = this;
+
+            $.getJSON('http://api.imgur.com/oembed?url=' + this.url, function (data) {
+                var img_html = '<a href="' + this.url + '" target="_blank"><img height="100" src="' + data.url + '" /></a>';
+                that.$content.find('.content').html(img_html);
+            });
 
+            return $('<div>Loading image..</div>');
+        },
+
+        
         reddit: function () {
             var that = this;
             var matches = (/reddit\.com\/r\/([a-zA-Z0-9_\-]+)\/comments\/([a-z0-9]+)\/([^\/]+)?/gi).exec(this.url);
@@ -95,10 +106,11 @@ _kiwi.view.MediaMessage = Backbone.View.extend({
             var that = this;
             var yt_html = '<iframe width="480" height="270" src="http://www.youtube.com/embed/'+ ytid +'?feature=oembed" frameborder="0" allowfullscreen=""></iframe>';
             that.$content.find('.content').html(yt_html);
+
+            return $('');
         }
     }
-
-}, {
+    }, {
 
     // Build the closed media HTML from a URL
     buildHtml: function (url) {
@@ -108,6 +120,15 @@ _kiwi.view.MediaMessage = Backbone.View.extend({
         if (url.match(/(\.jpe?g|\.gif|\.bmp|\.png)\??$/i)) {
             html += '<span class="media image" data-type="image" data-url="' + url + '" title="Open Image"><a class="open"><i class="icon-chevron-right"></i></a></span>';
         }
+        
+        // is this an imgur link?
+        matches = (/imgur\.com\/[^/]*(?!=\.[^!.]+($|\?))/ig).exec(url);
+        if (matches) {
+                if (url.match(/(\.jpe?g|\.gif|\.bmp|\.png)\??$/i)) {
+             } else {
+                       html += '<span class="media imgur" data-type="imgur" data-url="' + url + '" title="Open Image"><a class="open"><i class="icon-chevron-right"></i></a></span>';
+             }
+            }
 
         // Is it a tweet?
         matches = (/https?:\/\/twitter.com\/([a-zA-Z0-9_]+)\/status\/([0-9]+)/ig).exec(url);
@@ -126,6 +147,7 @@ _kiwi.view.MediaMessage = Backbone.View.extend({
         if (matches) {
             html += '<span class="media youtube" data-type="youtube" data-url="' + url + '" data-ytid="' + matches[1] + '" title="YouTube Video"><a class="open"><i class="icon-chevron-right"></i></a></span>';
         }
+
         return html;
     }
 });