Web/main/scripts/util.js
Ell cfe0ae6e88
All checks were successful
Web/pipeline/head This commit looks good
redirect legacy anchors in js
2021-10-11 14:07:57 +02:00

30 lines
No EOL
825 B
JavaScript

function getCookie(key) {
let match = new RegExp(`${key}=([^;]+);?`, "g").exec(document.cookie);
return match ? match[1] : undefined;
}
function setCookie(key, value, days) {
let date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
document.cookie = `${key}=${value}; expires=${date.toUTCString()}; path=/`;
}
function forceToAnchor(customAnchor) {
let anchor = customAnchor || location.hash;
// this is probably a terrible hack
if (anchor.startsWith("#")) {
let element = $(anchor);
if (element.length) {
$('html, body').animate({
scrollTop: element.offset().top
}, 0);
}
}
}
function addStyle(path) {
$('head').append($("<link/>", {
rel: "stylesheet",
href: path
}));
}