-
Notifications
You must be signed in to change notification settings - Fork 31
/
share.js
45 lines (37 loc) · 1.1 KB
/
share.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const domReady = () => {
const wrap = document.getElementById("share");
const width = 600;
const height = 600;
const share = ({ url, title }) => {
const top =
window.screenTop + document.documentElement.clientHeight / 2 - height / 2;
const left =
window.screenLeft + document.documentElement.clientWidth / 2 - width / 2;
const popup = window.open(
url,
title,
`width=${width},height=${height},top=${top},left=${left},
directories=no,titlebar=no,toolbar=no,location=no,status=no,menubar=no,
copyhistory=no,dependent=yes`
);
// Unset `window.opener` to remove popup page's access
popup.opener = null;
};
wrap.addEventListener("click", (ev) => {
const link = ev.target.closest("a");
if (link) {
const url = link.href;
const title = link.getAttribute("aria-label");
console.log(title);
share({ url, title });
}
});
};
if (
document.readyState === "interactive" ||
document.readyState === "complete"
) {
setTimeout(domReady, 0);
} else {
document.addEventListener("DOMContentLoaded", domReady);
}