Skip to content

Instantly share code, notes, and snippets.

@cameronbaney
Created October 15, 2014 14:18
Show Gist options
  • Save cameronbaney/5402629a914b0757cb35 to your computer and use it in GitHub Desktop.
Save cameronbaney/5402629a914b0757cb35 to your computer and use it in GitHub Desktop.
Custom social share
// Social media utilities from https://github.com/kni-labs/rrssb
var popupCenter = function(url, title, w, h) {
// Fixes dual-screen position Most browsers Firefox
var dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : screen.left;
var dualScreenTop = window.screenTop !== undefined ? window.screenTop : screen.top;
var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;
var left = ((width / 2) - (w / 2)) + dualScreenLeft;
var top = ((height / 3) - (h / 3)) + dualScreenTop;
var newWindow = window.open(url, title, 'scrollbars=yes, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
// Puts focus on the newWindow
if (window.focus) {
newWindow.focus();
}
};
// Share functionality
$('.social-share').on('click', function(e){
var $this = $(this);
popupCenter($this.attr('href'), $this.find('.text').html(), 580, 470);
e.preventDefault();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment