Add search and navbar javascript
This commit is contained in:
parent
feafea049b
commit
6f3d809d02
3 changed files with 52 additions and 0 deletions
1
themes/custom/static/js/autoComplete.min.js
vendored
Normal file
1
themes/custom/static/js/autoComplete.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
17
themes/custom/static/js/navbar.js
Normal file
17
themes/custom/static/js/navbar.js
Normal 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');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
34
themes/custom/static/js/search.js
Normal file
34
themes/custom/static/js/search.js
Normal 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;
|
||||||
|
}
|
||||||
|
});
|
Loading…
Reference in a new issue