Skip to content

Instantly share code, notes, and snippets.

@frontycore
Last active May 27, 2023 21:20
Show Gist options
  • Save frontycore/c7a34878d99a5466db1e5dfce908c8b5 to your computer and use it in GitHub Desktop.
Save frontycore/c7a34878d99a5466db1e5dfce908c8b5 to your computer and use it in GitHub Desktop.
Socials share link
/**
* Centered window popups ie. for social sharers
*/
(function() {
const $popups = document.querySelectorAll('[data-popup]');
$popups.forEach($popup => {
$popup.addEventListener('click', (e) => {
e.preventDefault();
const w = Math.min(640, window.innerWidth);
const h = Math.min(400, window.innerHeight);
const x = (window.innerWidth - w) / 2;
const y = (window.innerHeight - h) / 2;
window.open($popup.href, 'popupModal', `left=${x},top=${y},width=${w},height=${h}`);
});
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment