window.loremIpsum = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum';
langCodes = {
'en': 'engelska',
'la': 'latin',
'da': 'danska',
'no': 'norska'
}
fadeIntoDark = function(img) {
img.src='/img/' + (window.matchMedia?.('(prefers-color-scheme: dark)').matches ? 'dark' : 'default') + '.png';
}
function research(text) {
if (document.getElementById('search-text').value == text) {
document.getElementById('search-text').focus();
alert('Det står redan "' + text + '" i sökfältet 😅');
} else {
document.getElementById('search-text').value = text;
window.instantsearch(document.getElementById('search-text'));
document.getElementById('search-text').focus()
}
}
// https://stackoverflow.com/questions/1345722/calling-jquery-function-from-javascript
function toggle(button) {
if (button.target) {
button = button.target;
}
if (button.classList.contains('untoggle')) {
button.classList.remove('untoggle');
button.innerText = button.innerText.replace(/Implodera/i, 'Expandera');
button.setAttribute('aria-expanded', 'false');
button.nextElementSibling.classList.add('hide');
button.nextElementSibling.classList.remove('show');
} else {
button.classList.add('untoggle');
button.innerText = button.innerText.replace(/Expandera/i, 'Implodera');
button.setAttribute('aria-expanded', 'true');
button.nextElementSibling.classList.add('show');
button.nextElementSibling.classList.remove('hide');
}
}
window.onfocus = function() {
document.body.classList.add('activated');
document.body.classList.remove('deactivated');
}
window.onblur = function() {
document.body.classList.remove('activated');
document.body.classList.add('deactivated');
}
window.ononline = function() {
if (window.onlinelink) {
if (confirm('Den senaste länken som du tryckte på när du var offline var ' + (window.onlinelink['text'] ? '"' + window.onlinelink['text'] + '" (' + window.onlinelink['href'] + ')' : '"' + window.onlinelink['href'] + '"') + '. Vill du gå till den nu?')) {
window.location = window.onlinelink;
}
}
}
window.onhashchange = function(event) {
// event.preventDefault();
alert(JSON.stringify(new URL(event.newURL).pathname));
return false;
if (document.activeElement && document.activeElement.tagName == 'A') {
window.location = document.activeElement.getAttribute('href');
} else {
window.scrollTo(0, window.pageYOffset - 75 - 14);
event.preventDefault();
}
}
window.addEventListener('load', function() {
if (document.querySelector('table.colors')) {
document.querySelector('table.colors').onclick = function(event) {
document.body.style.background = event.target.style.background;
document.querySelector('#content').style.background = 'transparent';
}
}
});
// document.onclick = function(event) {
window.onclick = function(event) {
/*
if () {
alert(event.target.tagName + ':' + event.currentTarget.tagName); // + ':' + event.tElement.tagName);
}
*/
if (event.target.tagName == 'A') {
if (event.target.hash) {
window.location = window.location.pathname + event.target.hash;
//event.preventDefault();
// alert('Detta är en hashtag');
} else if (event.target.classList.contains('toggle')) {
// alert('Expandera');
toggle(event.target);
} else if (event.target.hasAttribute('href') && event.target.getAttribute('href').length == 0) {
event.preventDefault();
if (confirm('"' + event.target.innerText + '" verkar sakna webbadress 😟 Vill du söka på det istället?')) {
if (document.body.classList.contains('admin')) {
window.location = '//google.com/search?q=' + encodeURIComponent(event.target.innerText);
} else {
window.location = '/search/?q=' + encodeURIComponent(event.target.innerText);
}
}
} else {
if (!navigator.onLine) {
event.preventDefault();
// Du har förlorat internet ✈️ // Du har tappat din internet-anslutning
if (confirm('Det går inte att gå till sidor utan att vara ansluten till internet 🌐 Vill du att jag ska fråga om du vill gå till sidan "' + event.target.innerText + '" när du är ansluten till internet igen?')) {
alert('OK');
window.onlinelink = {
'href': event.target.innerText,
'text': event.target.getAttribute('href')
}
}
} else if (event.target.href.indexOf('.wikipedia.') != -1) {
// alert('Redirecting to Wikipedia: ' + event.target.href.indexOf('wikipedia'));
event.preventDefault();
answer = confirm('Gå till mobil webbplats av Wikipedia för sidan "' + decodeURI(event.target.href).replace(/.*wikipedia\.org\/wiki\//i, '').replace(/_/g, ' ') + '"? 📱');
if (answer) { // https://en.m.wikipedia.org/wiki/Semigraphics
//alert('Går till mobil webbplats: ' + event.target.href.replace(/(\w{2})\.wikipedia\.org/i, '$1.m.wikipedia.org'));
window.location = event.target.href.replace(/(\w{2})\.wikipedia\.org/i, '$1.m.wikipedia.org');
} else {
//alert('Går till vanlig webbplats: ' + event.target.href.replace(/m\.wikipedia\.org/i, 'wikipedia.org'));
window.location = event.target.href.replace(/m\.wikipedia\.org/i, 'wikipedia.org');
}
} else if (event.target.closest('a').classList.contains('clipboard')) {
closeA = event.target.closest('a');
// alert(event.target.parentNode.innerHTML.replace(/(<.+?>)/gi, '')); //
// alert(event.target.tagName + ':' + event.target.closest('a').tagName);
copyText = closeA.previousElementSibling.hasAttribute('data-copy') ? closeA.previousElementSibling.dataset.copy : (closeA.previousElementSibling.previousElementSibling && closeA.previousElementSibling.previousElementSibling.tagName == 'H2' ? closeA.previousElementSibling.previousElementSibling.innerText : (closeA.previousElementSibling.previousSibling && closeA.parentElement.firstChild.nodeType != Node.TEXT_NODE ? 'Kod för ikonen "' + closeA.previousElementSibling.previousSibling.textContent + '"' : null));
copy(closeA.previousElementSibling.innerText, (copyText ? copyText : '')); //
} else {
// alert(event.target.tagName);
// alert(event.target.classList.contains('toggle') ? 'Toggla' : 'Inte toggle: ' + event.target.classList);
}
}
// event.target.parentNode.previousElementSibling.tagName == 'H2' &&
} else if (0) { //event.target?.parentNode?.previousElementSibling.tagName == 'H2' && event.target?.parentNode.tagName == 'UL' && event.target?.parentNode.contains(event.target?.parentNode.querySelector('time'))) {
alert('Snart kommer du få mer information om filmer som du trycker på 🎬\n\n' + event.target.innerText.split('(')[0] + '\n\n' + (event.target.parentNode.querySelector('time').innerText ? 'Filmen kom år ' + event.target.parentNode.querySelector('time').innerText : 'Vet inte vilket år filmen kom') + '\n\nDen verkar vara på ' + (event.target.parentNode.contains(event.target.querySelector('dfn')) ? langCodes[event.target.parentNode.querySelector('dfn').getAttribute('lang')] : 'svenska'));
} else if (event.target.tagName == 'ABBR') {
event.stopImmediatePropagation();
event.preventDefault();
if (event.target.getAttribute('title')) {
//alert(event.target.getAttribute('title'));
// https://stackoverflow.com/questions/29223502/how-to-get-href-of-anchor-when-the-event-target-is-htmlimageelement
/*
event = event || window.event;
var target = event.target || event.srcElement;
while (target) {
if (target instanceof HTMLAnchorElement) {
console.log(target.getAttribute('href'));
break;
}
target = target.parentNode;
*/
if (confirm('Vill du gå till "' + event.target.innerHTML + '"? Det betyder "' + event.target.getAttribute('title') + '"?')) {
link = event.target.closest('a');
if (link) {
window.location = link.getAttribute('href');
} else {
alert('Det finns ingen länk att gå till');
}
}
/*}*/
} else {
xhr = new XMLHttpRequest();
xhr.onloadend = function() {
if (xhr.status == 200) {
alert((event.target.getAttribute('title') == '' ? 'Jag är inte helt säker på vad "' + event.target.innerText + '" betyder, men jag tror att det står för ' : (event.target.innerText + (JSON.parse(xhr.response).total.hits > 1 ? ' kan betyda lite olika saker' : ' betyder'))) + '\n\n• ' + JSON.parse(xhr.response).hits.join('\n• ') + '\n\nJag kan ' + (JSON.parse(xhr.response).total.number-1) + ' fler förkortningar');
} else {
alert('Jag vet inte vad ' + event.target.innerText + ' är förkortning för 😳' + '\n\nVi har ' + (JSON.parse(xhr.response).total.number-1) + ' andra förkortningar');
}
}
xhr.open('GET', 'https://api.omnum.se/abbr/?q=' + event.target.innerText);
xhr.send();
}
}
if (event.target.classList.contains('blur') || event.target.classList.contains('unblur')) {
event.target.classList.toggle('blur');
event.target.classList.toggle('unblur');
if (event.target.tagName == 'A') {
event.stopPropagation();
if (confirm('Vill du följa länken?')) {
window.location = event.target.getAttribute('href');
}
// // return false;
}
}
if (event.target?.parentNode?.parentNode.classList.contains('current')) {
event.target.parentNode.parentNode.querySelectorAll('a').forEach(function(el) {
el.classList.remove('current');
});
event.target.classList.add('current');
}
if (document.getElementById('instant-search')) {
if (!document.getElementById('topmenu').contains(document.activeElement)) {
document.getElementById('instant-search').style.display = 'none';
}
}
}
/*
function printa() {
if (window.print) {
window.print();
} else {
alert('Stöd för att skriva ut saknas i din webbläsare');
}
}
*/
function notify() { // notifyMe()
// Let's check if the browser supports notifications
if (!('Notification' in window)) {
alert('Stöd för notifikationer saknas i din webbläsare'); // This browser does not support desktop notification
}
// Let's check whether notification permissions have already been granted
else if (Notification.permission === 'granted') {
// If it's okay let's create a notification
var notification = new Notification('Omnification', {
body: 'This is a link to the latest page',
icon: '/img/avatar/admin.jpg'
});
notification.onclick = function() {
window.open('/latest/', '_blank');
}
}
// Otherwise, we need to ask the user for permission
else if (Notification.permission !== 'denied') {
Notification.requestPermission(function (permission) {
// If the user accepts, let's create a notification
if (permission === 'granted') {
var notification = new Notification('Omnification', {
body: 'This is a link to the latest page',
icon: 'http:///omnum.se/img/avatar/admin.jpg'
});
notification.onclick = function() {
window.open('/latest/', '_blank');
}
} else {
alert(permission);
}
});
}
// At last, if the user has denied notifications, and you
// want to be respectful there is no need to bother them any more.
}
// http://stackoverflow.com/questions/5045053/set-cookie-wih-js-read-with-php-problem
// document.cookie = 'ppkcookie1=testcookie; expires=Thu, 2 Aug 2001 20:47:11 UTC; path=/; ;domain=.example.com'
function createCookie(name, value, minutes) {
if (minutes) {
var date = new Date();
date.setTime(date.getTime()+(minutes*60*1000));
var expires = '; expires=' + date.toGMTString();
} else {
var expires = '';
}
document.cookie = name + '=' + value + expires + '; path=/;';
}
/*
options = {
enableHighAccuracy: true,
timeout: 10000,
maximumAge: 0
};
// Register for location changes
var watchId = navigator.geolocation.watchPosition(scrollMap, handleError, options);
// The error callback should take a PositionError object as the parameter as in:
function handleError(error) {
// Update a div element with the error message
document.getElementById('errorlatlng').innerHTML = (error.code + ":" + error.message + "(" + JSON.stringify(error) + ")") + '
';
}
function scrollMap(position) {
// Scroll the map to center position
//alert(JSON.stringify(position));
latitude = position.coords.latitude;
longitude = position.coords.longitude;
if (document.getElementById('latlng')) {
document.getElementById('errorlatlng').innerHTML = "";
document.getElementById('latlng').innerHTML = ("latitude: " + latitude + "
longitude: " + longitude);
}
}
*/
// Renamed "functionalService" 2024-01-24
function locator() {
if (navigator.cookieEnabled) {
getLocation();
} else {
document.getElementById('location-status').innerHTML = 'Du har valt att inte använda kakor 🍪 Vi använder det för att kunna hämta din nuvarande plats';
//console.log(error);
locationButtonIcon = document.querySelector('#location-wrapper .button i');
document.querySelector('#location-wrapper .button').text = 'Försök igen';
document.querySelector('#location-wrapper .button').prepend(locationButtonIcon);
locationButtonIcon.classList.remove('fa-map-marker');
locationButtonIcon.classList.add('fa-refresh');
locationButtonIcon.classList.remove('fa-spin');
document.querySelector('#location-wrapper .button').addEventListener('click', function() {locationButtonIcon.classList.add('fa-spin')});
}
}
function getLocation() {
options = {
enableHighAccuracy: true,
maximumAge: 30000
}
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition, notShowPosition, options);
} else {
alert('Stöd för geolocation saknas i din webbläsare'); // Geolocation is not supported by this browser
}
}
function notShowPosition(error) {
if (document.getElementById('location-header')) {
document.getElementById('location-header').innerHTML = 'Du har valt att inte dela din plats 🫢';
document.getElementById('location-p').innerHTML = '
Vi använder plats-information för att visa platser i närheten som kan vara intressanta för dig. Vänta en liten stund och försök igen, du kan även prova att ladda om sidan.
' + '' + `${error.code}: ${error.message}` + '.
';
//console.log(error);
locationButtonIcon = document.querySelector('#location-wrapper .button i');
document.querySelector('#location-wrapper .button').text = 'Försök igen';
document.querySelector('#location-wrapper .button').prepend(locationButtonIcon);
locationButtonIcon.classList.remove('fa-map-marker');
locationButtonIcon.classList.add('fa-refresh');
locationButtonIcon.classList.remove('fa-spin');
document.querySelector('#location-wrapper .button').addEventListener('click', function() {locationButtonIcon.classList.add('fa-spin')});
hungryPeopleWaited = 0;
hungryAndStillWaiting = setInterval(function() {
hungryPeopleWaited++;
if (hungryPeopleWaited == 30) {
document.getElementById('location-header').innerHTML = 'Visste du att du även kan söka på den typ av mat eller en restaurang som du letar efter? 😉';
//console.log('hungryPeopleWaited',hungryPeopleWaited);
clearTimeout(hungryAndStillWaiting);
}
}, 1000);
}
}
function showPosition(positions) {
hungryPeopleWaited = 0;
hungryAndStillWaiting = setInterval(function() {
hungryPeopleWaited++;
if (hungryPeopleWaited == 5) {
document.getElementById('location-header').innerHTML = 'Visste du att du även kan söka på den typ av mat eller en restaurang som du letar efter? 😉';
console.log('hungryPeopleWaited',hungryPeopleWaited);
clearTimeout(hungryAndStillWaiting);
}
}, 1000);
//x.innerHTML="Latitude: " + position.coords.latitude + "