JSFiddle - React, Tailwind, and code Playground
by DanBrown180
HTML
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<p>Chia VHS fashion axe fanny pack banh mi. Aliqua fap kitsch quis readymade swag fingerstache, tofu gluten-free gastropub sed messenger bag. Velit chambray Bushwick craft beer retro aliqua viral. Accusamus eu bitters, gentrify American Apparel artisan pop-up qui pour-over drinking vinegar consequat VHS. Umami organic +1 tote bag brunch. DIY narwhal locavore next level quinoa, butcher messenger bag meh Carles Tumblr. Deep v +1 pug letterpress et, labore gentrify squid drinking vinegar Tonx velit dolor.</p>
<p>Fugiat quinoa nostrud YOLO ullamco, duis est literally Etsy flexitarian velit shabby chic. Wolf skateboard Odd Future cliche, Pinterest trust fund actually blog cupidatat Intelligentsia paleo jean shorts Vice photo booth hoodie. Food truck vero Schlitz cliche squid est Wes Anderson, pariatur freegan Shoreditch fixie Pinterest American Apparel selfies disrupt. Pop-up locavore mustache, laborum American Apparel kogi fanny pack Vice vero. Disrupt Tonx cliche pour-over, Schlitz Thundercats Austin. Freegan vegan photo booth accusamus nostrud, ennui Tonx narwhal cray. Messenger bag High Life flannel Cosby sweater gluten-free nostrud.</p>
<p>You probably haven't heard of them butcher freegan sed Pinterest Thundercats. Narwhal tousled nostrud, direct trade aliquip dolore eu nesciunt authentic 8-bit irony fixie officia. Kitsch church-key id, swag organic gastropub cliche. Tofu consequat fap, sriracha chillwave viral nostrud placeat exercitation culpa Williamsburg master cleanse. Authentic 8-bit irony nihil synth ad roof party DIY blog. Tumblr keytar pop-up twee, irure Blue Bottle fap incididunt sint asymmetrical VHS before they sold out narwhal id. Messenger bag farm-to-table 90's brunch, hashtag fashion axe next level aliqua Cosby sweater ethical +1 labore pariatur single-origin coffee iPhone.</p>
<p>Disrupt Odd Future non flannel. Farm-to-table non exercitation, Vice keytar...
CSS
#tweetbutton {
display:none;
position:absolute;
z-index:1010;
padding-left:10px;
}
JavaScript
function getSelectionText() {
var text = "";
if (window.getSelection) {
text = window.getSelection().toString();
} else if (document.selection && document.selection.type != "Control") {
text = document.selection.createRange().text;
}
return text;
}
var mouseX;
var mouseY;
$(document).mousemove(function (e) {
mouseX = e.pageX;
mouseY = e.pageY;
});
$(document).ready(function () {
$('#tweetbutton').mouseup(function (e) {
$('#tweetbutton').hide();
});
$('div,p').mouseup(function (e) {
if (getSelectionText() != "") {
$("#tweetbutton").attr("href", 'https://twitter.com/intent/tweet?text=' + encodeURI(getSelectionText()) + '&url=' + encodeURI(document.URL));
$("#tweetbutton").attr("target", '_blank');
$('#tweetbutton').css({
'top': mouseY - 10,
'left': mouseX
}).fadeIn('slow');
}
})
});