Initial version
This commit is contained in:
commit
ed5653a7fc
211 changed files with 11043 additions and 0 deletions
49
themes/zen/assets/js/contact.js
Normal file
49
themes/zen/assets/js/contact.js
Normal file
|
@ -0,0 +1,49 @@
|
|||
/**
|
||||
* @file
|
||||
* A JavaScript file for the contact form.
|
||||
*/
|
||||
|
||||
(function () {
|
||||
|
||||
'use strict';
|
||||
|
||||
const form = document.querySelector('.contact-form');
|
||||
const button = form.querySelector('[type=submit]');
|
||||
const action = form.getAttribute('data-protect');
|
||||
|
||||
const activateForm = function () {
|
||||
form.setAttribute('action', action);
|
||||
button.removeAttribute('disabled');
|
||||
};
|
||||
|
||||
// Display the hidden form.
|
||||
form.classList.remove('hidden');
|
||||
|
||||
// Wait for a mouse to move, indicating they are human.
|
||||
document.body.addEventListener('mousemove', activateForm, {once: true});
|
||||
// Wait for a touch move event, indicating that they are human.
|
||||
document.body.addEventListener('touchmove', activateForm, {once: true});
|
||||
// A tab or enter key pressed can also indicate they are human.
|
||||
document.body.addEventListener('keydown', function (e) {
|
||||
if ((e.key === 'Tab') || (e.key === 'Enter')) {
|
||||
activateForm();
|
||||
}
|
||||
}, {once: true});
|
||||
|
||||
// Mark the form as submitted.
|
||||
button.addEventListener('click', () => form.classList.add('js-submitted'));
|
||||
|
||||
// Display messages.
|
||||
if (location.search.substring(1) !== '') {
|
||||
switch (location.search.substring(1)) {
|
||||
case 'submitted':
|
||||
document.querySelector('.contact-submitted').classList.remove('hidden');
|
||||
break;
|
||||
|
||||
case 'error':
|
||||
document.querySelector('.contact-error').classList.remove('hidden');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
})();
|
44
themes/zen/assets/js/cookieconsent.js
Normal file
44
themes/zen/assets/js/cookieconsent.js
Normal file
|
@ -0,0 +1,44 @@
|
|||
/**
|
||||
* @file
|
||||
* A JavaScript file for cookie consent.
|
||||
*/
|
||||
|
||||
(function () {
|
||||
|
||||
'use strict';
|
||||
|
||||
const cookiebanner = document.querySelector('.cookieconsent');
|
||||
const cookieconsent = localStorage.getItem('cookieconsent');
|
||||
|
||||
if (cookiebanner && !cookieconsent) {
|
||||
cookiebanner.classList.remove('hidden');
|
||||
cookiebanner.classList.add('js-cookieconsent-open');
|
||||
}
|
||||
|
||||
const cookie_buttons = document.querySelectorAll('button[data-consent]');
|
||||
cookie_buttons.forEach(function (button) {
|
||||
button.addEventListener('click', function () {
|
||||
if (button.getAttribute('data-consent') === 'true') {
|
||||
localStorage.setItem('cookieconsent', 'accept');
|
||||
}
|
||||
else {
|
||||
localStorage.setItem('cookieconsent', 'decline');
|
||||
}
|
||||
cookiebanner.classList.remove('js-cookieconsent-open');
|
||||
cookiebanner.classList.add('hidden');
|
||||
});
|
||||
});
|
||||
|
||||
const clear_buttons = document.querySelectorAll('.clearcookieconsent');
|
||||
clear_buttons.forEach(function (button) {
|
||||
button.addEventListener('click', function (e) {
|
||||
e.preventDefault();
|
||||
if (cookiebanner && cookieconsent) {
|
||||
localStorage.removeItem('cookieconsent');
|
||||
cookiebanner.classList.remove('hidden');
|
||||
cookiebanner.classList.add('js-cookieconsent-open');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
})();
|
21
themes/zen/assets/js/math.js
Normal file
21
themes/zen/assets/js/math.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
/**
|
||||
* @file
|
||||
* A JavaScript file for Katex auto renderer.
|
||||
*/
|
||||
|
||||
(function () {
|
||||
|
||||
'use strict';
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
// eslint-disable-next-line no-undef
|
||||
renderMathInElement(document.body, {
|
||||
delimiters: [
|
||||
{left: '$$', right: '$$', display: true},
|
||||
{left: '$', right: '$', display: false}
|
||||
],
|
||||
throwOnError: false
|
||||
});
|
||||
});
|
||||
|
||||
})();
|
52
themes/zen/assets/js/mobile.js
Normal file
52
themes/zen/assets/js/mobile.js
Normal file
|
@ -0,0 +1,52 @@
|
|||
/**
|
||||
* @file
|
||||
* A JavaScript file for the mobile menu.
|
||||
*/
|
||||
|
||||
(function () {
|
||||
|
||||
'use strict';
|
||||
|
||||
const nav = document.querySelector('.mobile-nav');
|
||||
const sheet = document.querySelector('.mobile-nav__sheet');
|
||||
const toggle = document.querySelector('.mobile-nav__toggle');
|
||||
|
||||
function navopen() {
|
||||
nav.classList.add('js-nav-open');
|
||||
sheet.setAttribute('aria-hidden', 'false');
|
||||
toggle.setAttribute('aria-expanded', 'true');
|
||||
}
|
||||
|
||||
function navclose() {
|
||||
nav.classList.remove('js-nav-open');
|
||||
sheet.setAttribute('aria-hidden', 'true');
|
||||
toggle.setAttribute('aria-expanded', 'false');
|
||||
}
|
||||
|
||||
// Toggle the mobile nav sheet.
|
||||
const toggles = document.querySelectorAll('.mobile-nav__cover, .mobile-nav__toggle');
|
||||
toggles.forEach(function (toggle) {
|
||||
toggle.addEventListener('click', function (e) {
|
||||
e.preventDefault();
|
||||
if (nav.classList.contains('js-nav-open')) {
|
||||
navclose();
|
||||
}
|
||||
else {
|
||||
navopen();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Close the nav sheet after click (needed for anchor links).
|
||||
const links = document.querySelectorAll('.mobile-nav__sheet a');
|
||||
links.forEach(function (link) {
|
||||
link.addEventListener('click', function (e) {
|
||||
navclose();
|
||||
});
|
||||
});
|
||||
|
||||
// Move focus back to button efter user tab out of last link.
|
||||
const lastlink = [].slice.call(links).pop();
|
||||
lastlink.addEventListener('blur', () => toggle.focus());
|
||||
|
||||
})();
|
13
themes/zen/assets/js/script-early.js
Normal file
13
themes/zen/assets/js/script-early.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
/**
|
||||
* @file
|
||||
* A JavaScript file for the theme. Runs first, before other things have loaded.
|
||||
*/
|
||||
|
||||
(function () {
|
||||
|
||||
'use strict';
|
||||
|
||||
// Add a js class to the html-tag when JavsScript is active.
|
||||
document.querySelector('html').classList.replace('nojs', 'js');
|
||||
|
||||
})();
|
12
themes/zen/assets/js/script.js
Normal file
12
themes/zen/assets/js/script.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
/**
|
||||
* @file
|
||||
* A JavaScript file for the theme.
|
||||
*/
|
||||
|
||||
(function () {
|
||||
|
||||
'use strict';
|
||||
|
||||
// Place your code here.
|
||||
|
||||
})();
|
92
themes/zen/assets/js/search.js
Normal file
92
themes/zen/assets/js/search.js
Normal file
|
@ -0,0 +1,92 @@
|
|||
/**
|
||||
* @file
|
||||
* A JavaScript file for flexsearch.
|
||||
*/
|
||||
|
||||
/* eslint-disable */
|
||||
import * as params from '@params';
|
||||
/* eslint-enable */
|
||||
|
||||
/* eslint-disable no-undef, guard-for-in */
|
||||
(function () {
|
||||
|
||||
'use strict';
|
||||
|
||||
const index = new FlexSearch.Document({
|
||||
document: {
|
||||
id: 'id',
|
||||
index: ['title', 'tags', 'content', 'date'],
|
||||
store: ['title', 'summary', 'date', 'permalink']
|
||||
},
|
||||
tokenize: 'forward'
|
||||
});
|
||||
|
||||
function showResults(items) {
|
||||
const template = document.querySelector('template').content;
|
||||
const fragment = document.createDocumentFragment();
|
||||
|
||||
const results = document.querySelector('.search-results');
|
||||
results.textContent = '';
|
||||
|
||||
for (const id in items) {
|
||||
const item = items[id];
|
||||
const result = template.cloneNode(true);
|
||||
const a = result.querySelector('a');
|
||||
const time = result.querySelector('time');
|
||||
const content = result.querySelector('.content');
|
||||
a.innerHTML = item.title;
|
||||
a.href = item.permalink;
|
||||
time.innerText = item.date;
|
||||
content.innerHTML = item.summary;
|
||||
fragment.appendChild(result);
|
||||
}
|
||||
results.appendChild(fragment);
|
||||
}
|
||||
|
||||
function doSearch() {
|
||||
const query = document.querySelector('.search-text').value.trim();
|
||||
const results = index.search({
|
||||
query: query,
|
||||
enrich: true,
|
||||
limit: params.searchLimit
|
||||
});
|
||||
const items = {};
|
||||
results.forEach(function (result) {
|
||||
result.result.forEach(function (r) {
|
||||
items[r.id] = r.doc;
|
||||
});
|
||||
});
|
||||
showResults(items);
|
||||
}
|
||||
|
||||
function enableUI() {
|
||||
const searchform = document.querySelector('.search-form');
|
||||
searchform.addEventListener('submit', function (e) {
|
||||
e.preventDefault();
|
||||
doSearch();
|
||||
});
|
||||
searchform.addEventListener('input', function () {
|
||||
doSearch();
|
||||
});
|
||||
document.querySelector('.search-loading').classList.add('hidden');
|
||||
document.querySelector('.search-input').classList.remove('hidden');
|
||||
document.querySelector('.search-text').focus();
|
||||
}
|
||||
|
||||
function buildIndex() {
|
||||
const searchindex = params.basePath + 'searchindex.json';
|
||||
document.querySelector('.search-loading').classList.remove('hidden');
|
||||
fetch(searchindex)
|
||||
.then(function (response) {
|
||||
return response.json();
|
||||
})
|
||||
.then(function (data) {
|
||||
data.forEach(function (item) {
|
||||
index.add(item);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
buildIndex();
|
||||
enableUI();
|
||||
})();
|
29
themes/zen/assets/js/tables.js
Normal file
29
themes/zen/assets/js/tables.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
/**
|
||||
* @file
|
||||
* A JavaScript file for responsive tables.
|
||||
*/
|
||||
|
||||
/* eslint-disable max-nested-callbacks */
|
||||
(function () {
|
||||
|
||||
'use strict';
|
||||
|
||||
const tables = document.querySelectorAll('.responsive-table');
|
||||
|
||||
tables.forEach(function (table) {
|
||||
const headers = table.querySelectorAll('th');
|
||||
const rows = table.querySelectorAll('tbody tr');
|
||||
|
||||
rows.forEach(function (row) {
|
||||
const cells = row.querySelectorAll('td');
|
||||
|
||||
cells.forEach(function (cell, i) {
|
||||
cell.setAttribute('role','cell');
|
||||
if (headers[i].innerText) {
|
||||
cell.setAttribute('aria-label', headers[i].innerText);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
})();
|
34
themes/zen/assets/js/tracking.js
Normal file
34
themes/zen/assets/js/tracking.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
/**
|
||||
* @file
|
||||
* A JavaScript file for analytic tracking.
|
||||
*/
|
||||
|
||||
/* eslint-disable */
|
||||
import * as params from '@params';
|
||||
/* eslint-enable */
|
||||
|
||||
/* eslint-disable no-undef */
|
||||
const cookiebanner = params.cookieConsent;
|
||||
const cookieconsent = localStorage.getItem('cookieconsent');
|
||||
const idSite = params.piwikSiteID;
|
||||
const matomoTrackingApiUrl = 'https://' + params.piwikTrackerUrl + '/matomo.php';
|
||||
const googleAnalytics = params.GoogleAnalytics;
|
||||
|
||||
if (idSite) {
|
||||
let _paq = window._paq = window._paq || [];
|
||||
|
||||
if (cookiebanner) {
|
||||
_paq.push(['requireConsent']);
|
||||
}
|
||||
_paq.push(['setTrackerUrl', matomoTrackingApiUrl]);
|
||||
_paq.push(['setSiteId', idSite]);
|
||||
_paq.push(['trackPageView']);
|
||||
_paq.push(['enableLinkTracking']);
|
||||
if (cookiebanner && cookieconsent === 'accept') {
|
||||
_paq.push(['setConsentGiven']);
|
||||
}
|
||||
}
|
||||
|
||||
if (googleAnalytics && cookiebanner && cookieconsent === 'decline') {
|
||||
window['ga-disable-' + googleAnalytics] = true;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue