Skip to content

Instantly share code, notes, and snippets.

@kjbrum
Last active July 13, 2024 22:33
Show Gist options
  • Save kjbrum/9fa7948aceb969434445 to your computer and use it in GitHub Desktop.
Save kjbrum/9fa7948aceb969434445 to your computer and use it in GitHub Desktop.
Create a popup for sharing something on social media.
/**
* Social sharing popup window
*/
var jsSocialShares = document.querySelectorAll('.social-share a');
if(jsSocialShares) {
[].forEach.call(jsSocialShares, function(anchor) {
anchor.addEventListener('click', function(e) {
var url = this.href,
width = 500,
height = 300,
left = (screen.width / 2) - (width / 2),
top = (screen.height / 2) - (height / 2);
if(/^(f|ht)tps?:\/\//i.test(url) || /^mailto/i.test(url)) {
e.preventDefault();
window.open(
url,
'',
'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,width=' + width + ',height=' + height + ',top=' + top + ',left=' + left
);
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment