Skip to content

Instantly share code, notes, and snippets.

@csessig86
Created June 8, 2016 14:24
Show Gist options
  • Save csessig86/3c89d0483b05b065041363805bfcb68e to your computer and use it in GitHub Desktop.
Save csessig86/3c89d0483b05b065041363805bfcb68e to your computer and use it in GitHub Desktop.
Social sharing on The Gazette
// Set social buttons
function socialShare(network) {
var winWidth = 520;
var winHeight = 350;
var winTop = (screen.height / 2) - (winHeight / 2);
var winLeft = (screen.width / 2) - (winWidth / 2);
var url = encodeURIComponent(window.location.href);
var title = $('#body-content h1').text();
if (title === "") {
title = $('#wrapper h1').text();
}
var descr = " Share popup";
var image = "https://gadatabases.herokuapp.com/assets/datacenter-icon-0d0490109aa013b7d4c0304135eaccd4cf87b950664bc98b0a83dc26e83a9a3f.png";
if (network === 'Facebook') {
var url_start = 'http://www.facebook.com/sharer.php?s=100';
} else if (network === 'Twitter') {
var url_start = 'https://twitter.com/share?url=' + url + '&text=Check this out: ' + title + ' - &via=gazettedotcom';
}
window.open(url_start + '&p[title]=' + title + '&p[summary]=' + descr + '&p[url]=' + url + '&p[images][0]=' + image, 'sharer', 'top=' + winTop + ',left=' + winLeft + ',toolbar=0,status=0,width=' + winWidth + ',height=' + winHeight);
}
// Fire it up
$(document).ready(function() {
// Social buttons
var twitter = '<a title="Tweet" class="share-action twitter" href="javascript:socialShare(' + "'Twitter'" + ')"><div class="fa fa-twitter fa-2x icons-share"></div></a>';
var facebook = '<a title="Share on Facebook" class="share-action facebook" href="javascript:socialShare(' + "'Facebook'" + ')"><div class="fa fa-facebook fa-2x icons-share"></div></a>';
$('#share-first-li').html(twitter);
$('#share-next-li').html(facebook);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment