0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-12-14 02:24:00 +01:00
Bootstrap/site/assets/js/search.js
Tiger Oakes fe257823ec
Use Babel and ES6 in docs JS files (#31607)
* Pass docs js through Babel

* Use ES6 in docs js

* Only run babel on src files

* Allow babel in Hugo

* Update scripts.html

* Inherit from the root .eslintrc.json

* Use `Array.from`

* Drop Babel from docs

* Prefer template

* replace IIFE with arrow functions

Co-authored-by: XhmikosR <xhmikosr@gmail.com>
Co-authored-by: GeoSot <geo.sotis@gmail.com>
2022-04-12 18:07:25 +03:00

54 lines
1.4 KiB
JavaScript

// NOTICE!! DO NOT USE ANY OF THIS JAVASCRIPT
// IT'S ALL JUST JUNK FOR OUR DOCS!
// ++++++++++++++++++++++++++++++++++++++++++
(() => {
'use strict'
const inputElement = document.getElementById('search-input')
if (!window.docsearch || !inputElement) {
return
}
const siteDocsVersion = inputElement.getAttribute('data-bd-docs-version')
document.addEventListener('keydown', event => {
if (event.ctrlKey && event.key === '/') {
event.preventDefault()
inputElement.focus()
}
})
window.docsearch({
apiKey: '5990ad008512000bba2cf951ccf0332f',
indexName: 'bootstrap',
inputSelector: '#search-input',
algoliaOptions: {
facetFilters: [`version:${siteDocsVersion}`]
},
transformData(hits) {
return hits.map(hit => {
const liveUrl = 'https://getbootstrap.com/'
hit.url = window.location.origin.startsWith(liveUrl) ?
// On production, return the result as is
hit.url :
// On development or Netlify, replace `hit.url` with a trailing slash,
// so that the result link is relative to the server root
hit.url.replace(liveUrl, '/')
// Prevent jumping to first header
if (hit.anchor === 'content') {
hit.url = hit.url.replace(/#content$/, '')
hit.anchor = null
}
return hit
})
},
// Set debug to `true` if you want to inspect the dropdown
debug: false
})
})()