Created
December 16, 2013 15:10
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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