jQuery social share links
A code snippet for share links for Facebook, Twitter and Google+
First, you have to create a Facebook App in order to make Facebook share link work here:
https://developers.facebook.com/
Add this code provided by Facebook to the page:
window.fbAsyncInit = function() { FB.init({ appId : 'YOUR APP ID', xfbml : true, version : 'v2.5' }); }; (function(d, s, id){ var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) {return;} js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_US/sdk.js"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk'));
After that here’s the code to be included as a script:
jQuery(document).ready(function(){ var shimg = jQuery('#top .loglink img').attr('src');//Fb image src URL var shlink = window.location.href; jQuery('#share .l-fb').on('click', function () { FB.ui({ method: 'feed', link: shlink, caption: "Some Title", description: "Some Description", picture: shimg, }, function(response){}); }); var selId = jQuery(this).attr('id'); jQuery('#share .l-tw').on('click', function () { window.open('http://twitter.com/share?url=' + shlink + '&text=SOME TEXT, Fast', 'twitterwindow', 'height=450, width=550, top='+(jQuery(window).height()/2 - 225) +', left='+jQuery(window).width()/2 +', toolbar=0, location=0, menubar=0, directories=0, scrollbars=0'); }); jQuery('#share .l-gp').on('click', function () { window.open('https://plusone.google.com/_/+1/confirm?hl=en&url=' + shlink, 'googlewindow', 'height=450, width=550, top='+(jQuery(window).height()/2 - 225) +', left='+jQuery(window).width()/2 +', toolbar=0, location=0, menubar=0, directories=0, scrollbars=0'); }); });
No comments