Skip to content

Instantly share code, notes, and snippets.

@jonathanpath
Last active June 8, 2016 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathanpath/2db05b120ecdd94bd72c to your computer and use it in GitHub Desktop.
Save jonathanpath/2db05b120ecdd94bd72c to your computer and use it in GitHub Desktop.
Share Twitter/Facebook/Googleplus Custom
$('a.js-share-facebook').click(function(e){
e.preventDefault();
var loc = encodeURIComponent($(this).attr('href'));
window.open('https://www.facebook.com/sharer/sharer.php?&u=' + loc, 'twitterwindow', 'height=450, width=550, top='+($(window).height() - 450)/2 +', left='+($(window).width() - 550)/2 +', toolbar=0, location=0, menubar=0, directories=0, scrollbars=0');
});
$('a.js-share-tweet').click(function(e){
e.preventDefault();
var loc = $(this).attr('href');
var text = $(this).data('text'); // Need title encoding http://stackoverflow.com/questions/10771728/encoding-get-the-title-for-twitter-share-url
var via = escape($(this).data('via'));
window.open('http://twitter.com/share?url=' + loc + '&text=' + text + '&via=' + via + '&', 'twitterwindow', 'height=450, width=550, top='+($(window).height() - 450)/2 +', left='+($(window).width() - 550)/2 +', toolbar=0, location=0, menubar=0, directories=0, scrollbars=0');
});
$('a.js-share-googleplus').click(function(e){
e.preventDefault();
var loc = $(this).attr('href');
window.open('https://plus.google.com/share?url=' + loc, 'twitterwindow', 'height=450, width=550, top='+($(window).height() - 450)/2 +', left='+($(window).width() - 550)/2 +', toolbar=0, location=0, menubar=0, directories=0, scrollbars=0');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment