Add search and navbar javascript

pull/2/head
Alexandre Iooss 3 years ago
parent feafea049b
commit 6f3d809d02

File diff suppressed because one or more lines are too long

@ -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');
});
});
}
});

@ -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;
}
});
Loading…
Cancel
Save