diff --git a/themes/custom/static/js/autoComplete.min.js b/themes/custom/static/js/autoComplete.min.js new file mode 100644 index 0000000..7982fc6 --- /dev/null +++ b/themes/custom/static/js/autoComplete.min.js @@ -0,0 +1 @@ +var a,b;a=this,b=function(){"use strict";function i(e,t){for(var n=0;n").concat(e,"")},c=function(e,o,r){var s=document.createDocumentFragment();o.forEach(function(e,t){var n=document.createElement(r.element),i=o[t].index;n.setAttribute(a,i),n.setAttribute("class",l),r.content?r.content(e,n):n.innerHTML=e.match||e,s.appendChild(n)}),e.appendChild(s)},p=function(t,n,i,o){function r(e){c.classList.remove(h),a=1===e?c.nextSibling:c.previousSibling}function s(e){(c=e).classList.add(h)}var a,l=n.childNodes,u=l.length-1,c=void 0;t.onkeydown=function(e){if(0a.threshold&&o.replace(/ /g,"").length;if(e){var s=a.resultsList.view;g(s);r?a.listMatchedResults(a.dataStream,t).then(function(e){n(t,e),a.resultsList.render&&(0===e.list.length&&a.noResults?a.noResults():(c(s,e.list,a.resultItem),a.onSelection&&(a.resultsList.navigation?a.resultsList.navigation(t,l,s,a.onSelection,e):p(l,s,a.onSelection,e))))}):n(t)}else!e&&r&&a.listMatchedResults(a.dataStream,t).then(function(e){n(t,e)})}(t)})}this.trigger.event.forEach(function(e){l.addEventListener(e,function(n,i){var o;return function(){var e=this,t=arguments;clearTimeout(o),o=setTimeout(function(){return n.apply(e,t)},i)}}(function(e){return t(e)},a.debounce))})}},{key:"init",value:function(){var t=this;this.data.cache?Promise.resolve(this.data.src()).then(function(e){t.dataStream=e,t.ignite()}):this.ignite(),y.initElementClosestPolyfill()}}]),K}()},"object"==typeof exports&&"undefined"!=typeof module?module.exports=b():"function"==typeof define&&define.amd?define(b):a.autoComplete=b(); diff --git a/themes/custom/static/js/navbar.js b/themes/custom/static/js/navbar.js new file mode 100644 index 0000000..81f887b --- /dev/null +++ b/themes/custom/static/js/navbar.js @@ -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'); + }); + }); + } +}); diff --git a/themes/custom/static/js/search.js b/themes/custom/static/js/search.js new file mode 100644 index 0000000..61dbe21 --- /dev/null +++ b/themes/custom/static/js/search.js @@ -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}.{0,32}[^\s]*)/); + if (found) { + source.innerHTML = "" + data.value.title + " : " + found[1]; + } else { + // erdnaxe missed his regex... + console.log(data.match); + } + } + }, + onSelection: feedback => { + // Go to page + window.location.href = feedback.selection.value.uri; + } +});