Add search and navbar javascript

This commit is contained in:
Alexandre Iooss 2021-11-01 12:06:58 +01:00
parent feafea049b
commit 6f3d809d02
3 changed files with 52 additions and 0 deletions

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,17 @@
// From https://bulma.io/documentation/components/navbar/
document.addEventListener('DOMContentLoaded', () => {
const $navbarBurgers = Array.prototype.slice.call(document.querySelectorAll('.navbar-burger'), 0);
if ($navbarBurgers.length > 0) {
$navbarBurgers.forEach(el => {
el.addEventListener('click', () => {
// Get the target from the "data-target" attribute
const target = el.dataset.target;
const $target = document.getElementById(target);
// Toggle the "is-active" class on both the "navbar-burger" and the "navbar-menu"
el.classList.toggle('is-active');
$target.classList.toggle('is-active');
});
});
}
});

View file

@ -0,0 +1,34 @@
/*
Some JavaScript for search, Aurore 2021
*/
new autoComplete({
data: {
src: async () => {
const source = await fetch(indexUrl);
const data = await source.json();
return data;
},
key: ["title", "content"],
cache: true
},
highlight: true,
resultsList: {
render: true
},
resultItem: {
content: (data, source) => {
found = data.match.match(/([^\s]*.{0,32}<span.*>.{0,32}[^\s]*)/);
if (found) {
source.innerHTML = "<b>" + data.value.title + "</b> : " + found[1];
} else {
// erdnaxe missed his regex...
console.log(data.match);
}
}
},
onSelection: feedback => {
// Go to page
window.location.href = feedback.selection.value.uri;
}
});