Skip to content

Commit

Permalink
Made twitter share url even COOLER
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacques Crocker committed Aug 14, 2010
1 parent 6daf723 commit 609ef15
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 17 deletions.
15 changes: 6 additions & 9 deletions dynamic/misc/_navbar.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@
<a href="#home" class="title home">If I would have known just one thing...</a>
<a href="#" class="prev">Previous Slide</a>
<a href="#" class="next">Next Slide</a>
<a href="#" class="tweet">Tweet this Slide</a>

<a href="http://twitter.com/share" class="twitter-share-button"
data-url="http://ifiwouldhaveknownjustonething.com#<%= slide %>"
data-text="If I would have known just one thing... (by <%= author_name %>)"
data-count="horizontal"
<% if defined?(author_twitter) %>
data-via="<%= author_twitter %>"
<% end %>
data-related="sayhellothere">Tweet</a>
<%= twitter_share :label => "Tweet this Slide",
:url => "http://ifiwouldhaveknownjustonething.com##{slide}",
:text => "If I would have known just one thing... (by #{author_name})",
:via => defined?(author_twitter) ? author_twitter : nil,
:related => "sayhellothere" %>

</nav>

18 changes: 18 additions & 0 deletions helpers.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
require 'uri'

module FrankHelpers

def partial(*args)
render_partial(*args)
end

def twitter_share(options = {})
%{
<a href="#{twitter_share_url(options)}" class="tweet">#{options[:label] || 'Tweet this'}</a>
}
end

def twitter_share_url(options = {})
base = "http://twitter.com/share?"
params = []
params << "url=#{URI.encode(options[:url])}"
params << "text=#{URI.encode(options[:text])}"
params << "via=#{URI.encode(options[:via])}" if options[:via]
params << "related=#{URI.encode(options[:related])}"
base+params.join("&")
end

def slidedeck
result = []
Pathname.new(File.dirname(__FILE__)).join("dynamic", "slidedeck").children.each do |child|
Expand Down
24 changes: 23 additions & 1 deletion layouts/default.erb
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,29 @@
});
})

$(".tweet").click(function(e) {
e.preventDefault();

var url = $(this).attr("href");

var Z = 550,
h = 450;
var c = screen.height;
var b = screen.width;
var a = Math.round((b / 2) - (Z / 2));
var g = 0;
if (c > h) {
g = Math.round((c / 2) - (h / 2))
}

var tweetWindow = window.open(url, "twitter_tweet", "left=" + a + ",top=" + g + ",width=" + Z + ",height=" + h + ",personalbar=no,toolbar=no,scrollbars=yes,location=yes,resizable=yes");
if (tweetWindow) {
tweetWindow.focus()
} else {
window.location.href = Y
}
})

})();
</script>

Expand All @@ -484,6 +507,5 @@
})();

</script>
<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
</body>
</html>
7 changes: 0 additions & 7 deletions static/css/slides.css
Original file line number Diff line number Diff line change
Expand Up @@ -532,14 +532,7 @@ info {
background-position: 0 -36px;
}

.slide.know nav .twitter-share-button {
right: 180px;
top: 20px;
position: absolute;
}

.slide.know nav a.tweet {
display: none;
top: 22px;
right: 185px;
width: 136px;
Expand Down

0 comments on commit 609ef15

Please sign in to comment.