From f443e24034fb74a2c57309fcc55f2c6e1859e7c0 Mon Sep 17 00:00:00 2001 From: Darren Date: Fri, 23 Nov 2012 23:26:19 +0000 Subject: [PATCH] Client: Inline media refactor + twitter type --- client/assets/dev/view.js | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/client/assets/dev/view.js b/client/assets/dev/view.js index fbccdd5..b14d90b 100644 --- a/client/assets/dev/view.js +++ b/client/assets/dev/view.js @@ -1220,8 +1220,9 @@ _kiwi.view.MediaMessage = Backbone.View.extend({ open: function () { // Create the content div if we haven't already if (!this.$content) { - this.$content = $('
Close media
'); - this.$content.append(''); + this.$content = $('
Close media
'); + console.log(this.$el.data('type'), this.mediaTypes); + this.$content.find('.content').append(this.mediaTypes[this.$el.data('type')].apply(this, []) || 'Not found :('); } // Now show the content if not already @@ -1233,20 +1234,46 @@ _kiwi.view.MediaMessage = Backbone.View.extend({ this.$el.append(this.$content); this.$content.slideDown(); } + }, + + + + // Generate the media content for each recognised type + mediaTypes: { + twitter: function () { + var tweet_id = this.$el.data('tweetid'); + var that = this; + + $.getJSON('https://api.twitter.com/1/statuses/oembed.json?id=' + tweet_id + '&callback=?', function (data) { + that.$content.find('div').html(data.html); + }); + + return $('
Loading tweet..
'); + }, + + + image: function () { + return $(''); + } } }, { // Build the closed media HTML from a URL buildHtml: function (url) { - var html = ''; + var html = '', matches; // Is it an image? if (url.match(/(\.jpe?g|\.gif|\.bmp|\.png)\??$/i)) { - html += ''; + html += ''; + } + + // Is it a tweet? + matches = (/https?:\/\/twitter.com\/([a-zA-Z0-9_]+)\/status\/([0-9]+)/ig).exec(url); + if (matches) { + html += ''; } return html; } -} -); \ No newline at end of file +}); \ No newline at end of file -- 2.25.1