Skip to content

Instantly share code, notes, and snippets.

@mariemosley
Created December 16, 2013 15:10
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mariemosley/114c2f7589feb9227cc7 to your computer and use it in GitHub Desktop.
jQuery Click to Tweet - written for Blogger but can be modified for other platforms. In use: add the class "tweetable" to the element you'd like to make into a tweetable sentence.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type='text/javascript'>
$(document).ready(function() {
$('.tweetable').each(function() {
var sentence = $(this);
var permalink = sentence.parents('.post-outer').find('.timestamp-link').attr('href') || $(location).attr('href');
var tweetable = sentence.text();
var result = encodeURIComponent(tweetable);
var link = encodeURIComponent(permalink);
sentence.wrap('<a class="tweet-link" href="https://twitter.com/intent/tweet?text=' + result + " " + link +'"></a>');
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment