From b9149cd0fb2d0362b58320341f6db653f5feff03 Mon Sep 17 00:00:00 2001 From: Darren Date: Sat, 24 Nov 2012 01:42:41 +0000 Subject: [PATCH] Client: Reddit thread media --- client/assets/css/style.css | 28 ++++++++++++++++++++++- client/assets/dev/view.js | 45 +++++++++++++++++++++++++++++++++++-- 2 files changed, 70 insertions(+), 3 deletions(-) diff --git a/client/assets/css/style.css b/client/assets/css/style.css index 90c6cdd..a138328 100644 --- a/client/assets/css/style.css +++ b/client/assets/css/style.css @@ -343,8 +343,34 @@ html, body { height:100%; } #kiwi.theme_relaxed .messages .msg .media { margin-left:0.5em; } #kiwi.theme_relaxed .messages .msg .media .media_close { font-size:0.9em; } -#kiwi.theme_relaxed .messages .msg .media .media_content { margin:10px 0 0 10px; } +#kiwi.theme_relaxed .messages .msg .media .media_content { margin:10px 0 0 10px; overflow:hidden; } #kiwi.theme_relaxed .messages .msg .media .media_content img { padding:3px; border:1px solid gray; } +#kiwi.theme_relaxed .messages .msg .media .media_content > .content { + background: white; + overflow: hidden; + padding: 10px; + border: #DDD 1px solid; + border-top-color: #EEE; + border-bottom-color: #BBB; + -webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15); + -moz-box-shadow: 0 1px 3px rgba(0,0,0,0.15); + box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15); + border-radius: 5px; + float: left; +} + +#kiwi.theme_relaxed .messages .msg .media.twitter .media_content > .content { + background: transparent; + border:none; + overflow: hidden; + box-shadow: none; + padding: 0; +} +#kiwi.theme_relaxed .messages .msg .media.reddit .thumbnail_nsfw { + display: inline-block; + float: left; +} +#kiwi.theme_relaxed .messages .msg .media.reddit .thumbnail { float:left; margin-right: 0.5em; } #kiwi.theme_relaxed #memberlists { diff --git a/client/assets/dev/view.js b/client/assets/dev/view.js index b14d90b..539f6df 100644 --- a/client/assets/dev/view.js +++ b/client/assets/dev/view.js @@ -1221,7 +1221,6 @@ _kiwi.view.MediaMessage = Backbone.View.extend({ // Create the content div if we haven't already if (!this.$content) { 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 :('); } @@ -1245,7 +1244,7 @@ _kiwi.view.MediaMessage = Backbone.View.extend({ 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); + that.$content.find('.content').html(data.html); }); return $('
Loading tweet..
'); @@ -1254,6 +1253,42 @@ _kiwi.view.MediaMessage = Backbone.View.extend({ image: function () { return $(''); + }, + + + reddit: function () { + var that = this; + var matches = (/reddit\.com\/r\/([a-zA-Z0-9_\-]+)\/comments\/([a-z0-9]+)\/([^\/]+)?/gi).exec(this.url); + + $.getJSON('http://www.' + matches[0] + '.json?jsonp=?', function (data) { + console.log('Loaded reddit data', data); + var post = data[0].data.children[0].data; + var thumb = ''; + + // Show a thumbnail if there is one + if (post.thumbnail) { + //post.thumbnail = 'http://www.eurotunnel.com/uploadedImages/commercial/back-steps-icon-arrow.png'; + + // Hide the thumbnail if an over_18 image + if (post.over_18) { + thumb = ''; + thumb += '

Show
NSFW

'; + thumb += ''; + thumb += '
'; + } else { + thumb = ''; + } + } + + // Build the template string up + var tmpl = '
' + thumb + '<%- title %>
Posted by <%- author %>.    '; + tmpl += ' <%- ups %>    <%- downs %>
'; + tmpl += '<%- num_comments %> comments made. View post
'; + + that.$content.find('.content').html(_.template(tmpl, post)); + }); + + return $('
Loading Reddit thread..
'); } } @@ -1274,6 +1309,12 @@ _kiwi.view.MediaMessage = Backbone.View.extend({ html += ''; } + // Is reddit? + matches = (/reddit\.com\/r\/([a-zA-Z0-9_\-]+)\/comments\/([a-z0-9]+)\/([^\/]+)?/gi).exec(url); + if (matches) { + html += ''; + } + return html; } }); \ No newline at end of file -- 2.25.1