Last active
January 2, 2016 22:29
-
-
Save psteinweber/8369833 to your computer and use it in GitHub Desktop.
#twitter #jquery This jquery snipped appends a "Click to tweet" button (font-awesome icon in this case) into every blockquote on the page. Created as a replacement for bulky "Click to tweet" wordpress plugins.
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
blockquote a:before { | |
content:"\f099"; | |
font-family: FontAwesome; | |
margin-left: 10px; | |
} |
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
var completeurl = window.location.protocol + "//" + window.location.host + window.location.pathname + window.location.search; | |
completeurl = encodeURIComponent(completeurl); | |
var twshare = "https://twitter.com/share?url=" + completeurl; | |
$("blockquote").each(function () { | |
var $link = $("<a />"), | |
linkText = "", | |
url = twshare + "&text=" + $(this).text() + " @metamonks"; | |
$link.attr("href", url); | |
$link.attr("title", "Tweet this"); | |
$link.attr("target", "_blank"); | |
$link.text(linkText); | |
$link.addClass('tweet-this'); | |
$(this).append($link); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, this was very helpful in creating a simple 'click to tweet' feature for Ghost.