Skip to content

Instantly share code, notes, and snippets.

@cladley
Created May 20, 2016 09:33
Show Gist options
  • Save cladley/cc0b7d92b5b8f9844cb4e68055806b1b to your computer and use it in GitHub Desktop.
Save cladley/cc0b7d92b5b8f9844cb4e68055806b1b to your computer and use it in GitHub Desktop.
function SocialShare(el) {
this.POPUP_WIDTH = 550;
this.POPUP_HEIGHT = 420;
this.$element = $(el);
this.$element.on('click', this.onClick.bind(this));
}
SocialShare.prototype = {
constructor: SocialShare,
onClick: function(e) {
var anchor = $(event.currentTarget);
var href = anchor.attr('href');
var offsetX = Math.floor(((screen.availWidth || 1024) - this.POPUP_WIDTH) / 2);
var offsetY = Math.floor(((screen.availHeight || 768) - this.POPUP_HEIGHT) / 2);
var popup = window.open(
href,
"Social share",
"width=" +
this.POPUP_WIDTH +
",height=" +
this.POPUP_HEIGHT +
",left=" +
offsetX +
",top=" +
offsetY +
",location=0,toolbar=0,menubar=0,status=0,scrollbars=1,resizable=1"
);
event.preventDefault();
return popup || false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment