Navigation Menu

Skip to content

Commit

Permalink
Add Twitter Web Intents
Browse files Browse the repository at this point in the history
  • Loading branch information
re4k committed Mar 28, 2013
1 parent 295db76 commit 61087e2
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 7 deletions.
Binary file added app/assets/images/favorite.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/reply.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/retweet.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions app/assets/javascripts/twitter.js
@@ -0,0 +1,43 @@
(function() {
if (window.__twitterIntentHandler) return;
var intentRegex = /twitter\.com(\:\d{2,4})?\/intent\/(\w+)/,
windowOptions = 'scrollbars=yes,resizable=yes,toolbar=no,location=yes',
width = 550,
height = 420,
winHeight = screen.height,
winWidth = screen.width;

function handleIntent(e) {
e = e || window.event;
var target = e.target || e.srcElement,
m, left, top;

while (target && target.nodeName.toLowerCase() !== 'a') {
target = target.parentNode;
}

if (target && target.nodeName.toLowerCase() === 'a' && target.href) {
m = target.href.match(intentRegex);
if (m) {
left = Math.round((winWidth / 2) - (width / 2));
top = 0;

if (winHeight > height) {
top = Math.round((winHeight / 2) - (height / 2));
}

window.open(target.href, 'intent', windowOptions + ',width=' + width +
',height=' + height + ',left=' + left + ',top=' + top);
e.returnValue = false;
e.preventDefault && e.preventDefault();
}
}
}

if (document.addEventListener) {
document.addEventListener('click', handleIntent, false);
} else if (document.attachEvent) {
document.attachEvent('onclick', handleIntent);
}
window.__twitterIntentHandler = true;
}());
20 changes: 15 additions & 5 deletions app/assets/stylesheets/_tweets.css.sass
Expand Up @@ -8,12 +8,22 @@
:border 1px solid #c1c5cb
:border-width 1px 0
:padding 15px
.avatar
:width 60px
.left
:float left
img
:width 48px
:height 48px
:width 60px
.avatar
img
:width 48px
:height 48px
ul.actions
li
:padding 0
a
:float left
img
:width 16px
:height 16px
:vertical-align bottom
.tweet_content_fix
:float left
:width 0
Expand Down
1 change: 1 addition & 0 deletions app/views/layouts/_base.html.haml
Expand Up @@ -3,6 +3,7 @@
%head
%title= @title
= stylesheet_link_tag "application"
= javascript_include_tag "twitter"
%body
.navbar.navbar-static-top
.navbar-inner
Expand Down
10 changes: 8 additions & 2 deletions app/views/shared/_tweet.html.haml
@@ -1,7 +1,13 @@
.item
.tweet
.avatar
= link_to image_tag(item.user.profile_image_url, :alt => item.user.screen_name, :title => item.user.name), :controller => "users", :action => "best", :screen_name => item.user.screen_name
.left
.avatar
= link_to image_tag(item.user.profile_image_url, :alt => item.user.screen_name, :title => item.user.name), :controller => "users", :action => "best", :screen_name => item.user.screen_name
%ul.inline.actions
%li
= link_to image_tag("reply.png", :alt => "reply"), "https://twitter.com/intent/tweet?in_reply_to=#{item.id}"
= link_to image_tag("retweet.png", :alt => "retweet"), "https://twitter.com/intent/retweet?tweet_id=#{item.id}"
= link_to image_tag("favorite.png", :alt => "favorite"), "https://twitter.com/intent/favorite?tweet_id=#{item.id}"
.tweet_content_fix
.tweet_content
.user
Expand Down

0 comments on commit 61087e2

Please sign in to comment.