Skip to content

Instantly share code, notes, and snippets.

@adamloving
Created November 25, 2012 00:48
Show Gist options
  • Save adamloving/4141957 to your computer and use it in GitHub Desktop.
Save adamloving/4141957 to your computer and use it in GitHub Desktop.
Add "tweet this" links to text in a blog post
function onMouseenter(e) {
el = $(e.target);
url = 'https://twitter.com/intent/tweet?text='
url += encodeURIComponent(el.text());
url += ' ' + window.location.href;
// el.css('position', 'relative');
el.append('<a href="' + url + '" target="_blank" class="tweet-this" style="position: relative; left: 5px;">Tweet this</a>');
};
function onMouseleave(e) {
el = $(e.target);
$('.tweet-this').remove();
};
$(document).ready(function () {
$('.tweetable').mouseenter(onMouseenter);
$('.tweetable').mouseleave(onMouseleave);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment