mirror of
https://github.com/stedolan/jq.git
synced 2024-05-11 05:55:39 +00:00
* Bump up Bootstrap to v5.3.1, Bootstrap Icon to v1.10.5. * Use autoComplete.js to drop dependency on jQuery and typeahead.js. * Support dark mode. * New svg logo and icon with responsive color mode support. * Normalize section ids to lower kebab-case for easiness of linking. * Use relative paths for links for local development (--root /output). * Various markup cleanups and accessibility improvements.
35 lines
1.3 KiB
JavaScript
35 lines
1.3 KiB
JavaScript
(() => {
|
|
const searchInput = document.querySelector('input#searchbox');
|
|
const sectionIDs = JSON.parse(document.querySelector('#section-ids').innerText);
|
|
const sanitize = (string) => string.replaceAll('<', '<').replaceAll('>', '>');
|
|
new autoComplete({
|
|
selector: `#${searchInput.id}`,
|
|
wrapper: false,
|
|
data: {
|
|
src: Object.keys(sectionIDs),
|
|
filter: (list) => list.sort((x, y) =>
|
|
x.match.indexOf('<') - y.match.indexOf('<') || x.value.length - y.value.length),
|
|
},
|
|
searchEngine: (query, value) => {
|
|
const index = value.toLowerCase().indexOf(query.toLowerCase());
|
|
if (index >= 0) {
|
|
return sanitize(value.substring(0, index)) +
|
|
`<mark>${sanitize(value.substring(index, index + query.length))}</mark>` +
|
|
sanitize(value.substring(index + query.length));
|
|
}
|
|
},
|
|
});
|
|
searchInput.addEventListener('selection', (event) => {
|
|
event.target.value = event.detail.selection.value;
|
|
location.hash = `#${sectionIDs[event.detail.selection.value]}`;
|
|
});
|
|
document.addEventListener('keydown', (event) => {
|
|
if (event.code === 'Slash' && !event.altKey && !event.ctrlKey && !event.metaKey
|
|
&& !event.shiftKey && !/^(INPUT|TEXTAREA)$/.test(event.target.nodeName)) {
|
|
searchInput.focus();
|
|
searchInput.select();
|
|
event.preventDefault();
|
|
}
|
|
});
|
|
})();
|