88 lines
2.8 KiB
JavaScript
88 lines
2.8 KiB
JavaScript
(function (){
|
|
var comfiture = {};
|
|
var activeLink;
|
|
var activeContent;
|
|
var motds = [
|
|
"Made by Fristi",
|
|
"Made by a crocodile",
|
|
"Made by a Dutch potato",
|
|
"Fristi? Fristi habe ich nicht.",
|
|
"[Subject quote here]",
|
|
"Press R or Z twice to do a barrel roll",
|
|
"You wouldn't download a car.",
|
|
"The last metroid is in captivity.",
|
|
"Suavemente, bésame",
|
|
"What is love?",
|
|
"Justice in Spades",
|
|
"Let's get Volatile",
|
|
];
|
|
var wallpapers = [
|
|
'1.gif', '3.gif', '4.gif',
|
|
'6.gif', '7.gif', '8.gif',
|
|
'9.gif', '10.gif', '12.gif',
|
|
'13.gif', '14.gif', '16.gif',
|
|
'17.gif', '18.gif', '19.gif', '20.gif',
|
|
'22.gif', '23.gif',
|
|
'1.png', '2.png', '3.png',
|
|
'5.png', '6.png'
|
|
];
|
|
|
|
//Function to set the wallpaper
|
|
comfiture.setupWallpaper = function () {
|
|
let wallpaper = wallpapers[Math.floor(Math.random() * wallpapers.length)];
|
|
document.querySelector('.background').style.backgroundImage = 'url("backgrounds/'+wallpaper+'")';
|
|
};
|
|
|
|
comfiture.printMotd = function () {
|
|
let motd = motds[Math.floor(Math.random() * motds.length)];
|
|
document.write(motd);
|
|
}
|
|
|
|
//Onload
|
|
window.addEventListener('load', function(){
|
|
//Hide all content
|
|
let contents = document.querySelectorAll('.content');
|
|
contents.forEach(function (element) {
|
|
element.classList.add('hide');
|
|
});
|
|
|
|
//Activate content matching hash in url (or home instead)
|
|
let hash = window.location.hash;
|
|
if(!hash) hash = '#home';
|
|
switchActiveContent(hash);
|
|
|
|
//Add click event handlers for header/footer links
|
|
window.addEventListener("click", event => {
|
|
var elements = document.querySelectorAll('header a, footer a');
|
|
elements.forEach(element => {
|
|
if (element && element.contains(event.target)) {
|
|
let hash = element.getAttribute('href');
|
|
switchActiveContent(hash);
|
|
}
|
|
});
|
|
});
|
|
});
|
|
|
|
function switchActiveContent(id)
|
|
{
|
|
let link = document.querySelector('a[href="'+id+'"]');
|
|
let content = document.querySelector(id);
|
|
|
|
if(link && content) {
|
|
if(activeLink) activeLink.classList.remove('active');
|
|
if(activeContent) activeContent.classList.add('hide');
|
|
|
|
link.classList.add('active');
|
|
content.classList.remove('hide');
|
|
|
|
activeLink = link;
|
|
activeContent = content;
|
|
} else {
|
|
console.error('Error: not switching content; link or content element for id ' + id + ' does not exist.');
|
|
}
|
|
}
|
|
|
|
//Expose comfiture object to document
|
|
window.comfiture = comfiture;
|
|
|
|
})(); |