48 lines
1.4 KiB
JavaScript
Executable File
48 lines
1.4 KiB
JavaScript
Executable File
(function () {
|
|
var html = document.querySelector('html');
|
|
|
|
// Defer image loading till last.
|
|
function init() {
|
|
var imgDefer = document.getElementsByTagName('img');
|
|
for (var i = 0; i < imgDefer.length; i++) {
|
|
if (imgDefer[i].getAttribute('data-src')) {
|
|
imgDefer[i].setAttribute('src', imgDefer[i].getAttribute('data-src'));
|
|
}
|
|
}
|
|
}
|
|
|
|
// When the DOM is ready it'll execute fn().
|
|
function ready(fn) {
|
|
if (document.readyState != 'loading'){
|
|
fn();
|
|
} else {
|
|
document.addEventListener('DOMContentLoaded', fn);
|
|
}
|
|
}
|
|
|
|
window.onload = init;
|
|
|
|
ready(function () {
|
|
var showNavButton = document.getElementById('show-nav');
|
|
var nav = document.querySelector('aside');
|
|
var className = 'is-shown';
|
|
|
|
showNavButton.addEventListener('click', function (e) {
|
|
|
|
// Toggle class: "is-shown".
|
|
if (nav.classList) {
|
|
nav.classList.toggle(className);
|
|
} else {
|
|
var classes = nav.className.split(' ');
|
|
var existingIndex = classes.indexOf(className);
|
|
|
|
if (existingIndex >= 0)
|
|
classes.splice(existingIndex, 1);
|
|
else
|
|
classes.push(className);
|
|
|
|
nav.className = classes.join(' ');
|
|
}
|
|
});
|
|
});
|
|
})(); |