Basic cours support #44

Merged
Anri merged 67 commits from cours into main 2024-04-01 18:11:49 +02:00
2 changed files with 33 additions and 2 deletions
Showing only changes of commit f2a6fe6ddd - Show all commits

View file

@ -1,5 +1,5 @@
{{#metadata}} {{#info}} {{#portfolio}} {{#link}}
<li role="button" onclick="window.open('{{link}}', '_blank', 'noreferrer');">
<li role="button" onmousedown="openLink('{{link}}');">
{{>portfolio/project.html}}
</li>
{{/link}} {{^link}}

View file

@ -40,11 +40,42 @@
document.querySelectorAll("main a").forEach(function (link) {
link.setAttribute("target", "_blank");
link.setAttribute("rel", "noreferrer");
link.addEventListener("click", function (event) {
link.addEventListener("mousedown", function (event) {
event.stopPropagation();
});
})
);
/* Open cards link */
const openLink = (url) => {
const backgroundtab = () =>
Object.assign(document.createElement("a"), {
href: url,
target: "_blank",
rel: "noreferrer",
}).dispatchEvent(
new MouseEvent("click", { ctrlKey: true, metaKey: true })
);
switch (event.button) {
case 0:
/* Left click */
if (event.ctrlKey || event.metaKey) {
backgroundtab();
} else {
window.open(url, "_blank", "noreferrer");
}
break;
case 1:
/* Middle click */
event.preventDefault();
backgroundtab();
break;
default:
break;
}
};
</script>
</body>
</html>