2020-06-14 10:24:26 +03:00
|
|
|
function getLocalStorage(key) {
|
|
|
|
try {
|
|
|
|
return localStorage.getItem(key);
|
|
|
|
} catch (e) {
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
function setLocalStorage(key, value) {
|
|
|
|
try {
|
2020-06-14 11:10:26 +03:00
|
|
|
if (value !== "" && value !== null) {
|
|
|
|
localStorage.setItem(key, value);
|
|
|
|
} else {
|
|
|
|
localStorage.removeItem(key);
|
|
|
|
}
|
2020-06-14 10:24:26 +03:00
|
|
|
return true;
|
|
|
|
} catch (e) {}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-06-14 11:10:26 +03:00
|
|
|
function clearLocalStorage(key) {
|
|
|
|
localStorage.removeItem(key);
|
|
|
|
}
|
|
|
|
|
2020-06-14 10:24:26 +03:00
|
|
|
function jumpToBottom(id) {
|
2020-06-16 09:32:26 +03:00
|
|
|
const div = id ? document.querySelector(id) : document.body;
|
2020-06-14 10:24:26 +03:00
|
|
|
div.scrollTo({
|
2020-06-16 09:32:26 +03:00
|
|
|
top: div.scrollHeight,
|
2020-06-14 10:24:26 +03:00
|
|
|
left: 0,
|
|
|
|
behavior: 'smooth'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function uuidv4() {
|
|
|
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
|
|
const r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
|
|
|
|
return v.toString(16);
|
|
|
|
});
|
2020-06-15 07:14:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function setVHvar() {
|
2020-06-15 23:43:41 +03:00
|
|
|
var vh = window.innerHeight * 0.01;
|
2020-06-15 07:14:42 +03:00
|
|
|
// Then we set the value in the --vh custom property to the root of the document
|
|
|
|
document.documentElement.style.setProperty('--vh', `${vh}px`);
|
2020-06-15 23:43:41 +03:00
|
|
|
console.log("== new vh", vh)
|
2020-06-15 07:14:42 +03:00
|
|
|
}
|
2020-06-16 01:55:57 +03:00
|
|
|
// delayed
|
2020-06-15 07:14:42 +03:00
|
|
|
function mobileVHhack() {
|
2020-06-16 01:55:57 +03:00
|
|
|
setTimeout(setVHvar, 100);
|
2020-06-15 10:15:23 +03:00
|
|
|
}
|
|
|
|
|
2020-06-15 23:43:41 +03:00
|
|
|
|
2020-06-16 01:45:55 +03:00
|
|
|
// Trying to determine if browser is mobile/tablet.
|
|
|
|
// Source: https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent
|
|
|
|
function hasTouchScreen() {
|
|
|
|
var hasTouchScreen = false;
|
|
|
|
if ("maxTouchPoints" in navigator) {
|
|
|
|
hasTouchScreen = navigator.maxTouchPoints > 0;
|
|
|
|
} else if ("msMaxTouchPoints" in navigator) {
|
|
|
|
hasTouchScreen = navigator.msMaxTouchPoints > 0;
|
|
|
|
} else {
|
|
|
|
var mQ = window.matchMedia && matchMedia("(pointer:coarse)");
|
|
|
|
if (mQ && mQ.media === "(pointer:coarse)") {
|
|
|
|
hasTouchScreen = !!mQ.matches;
|
|
|
|
} else if ('orientation' in window) {
|
|
|
|
hasTouchScreen = true; // deprecated, but good fallback
|
|
|
|
} else {
|
|
|
|
// Only as a last resort, fall back to user agent sniffing
|
|
|
|
var UA = navigator.userAgent;
|
|
|
|
hasTouchScreen = (
|
|
|
|
/\b(BlackBerry|webOS|iPhone|IEMobile)\b/i.test(UA) ||
|
|
|
|
/\b(Android|Windows Phone|iPad|iPod)\b/i.test(UA)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return hasTouchScreen;
|
|
|
|
}
|
2020-06-15 23:43:41 +03:00
|
|
|
|