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

60 lines
1.6 KiB
JavaScript
Raw Normal View History

2018-04-27 09:11:17 +02:00
// NOTICE!! DO NOT USE ANY OF THIS JAVASCRIPT
// IT'S ALL JUST JUNK FOR OUR DOCS!
// ++++++++++++++++++++++++++++++++++++++++++
(function () {
'use strict'
if (!window.docsearch) {
return
}
var inputElement = document.getElementById('search-input')
var siteDocsVersion = inputElement.getAttribute('data-docs-version')
function getOrigin() {
var location = window.location
var origin = location.origin
if (!origin) {
var port = location.port ? ':' + location.port : ''
origin = location.protocol + '//' + location.hostname + port
}
return origin
}
window.docsearch({
apiKey: '5990ad008512000bba2cf951ccf0332f',
indexName: 'bootstrap',
inputSelector: '#search-input',
algoliaOptions: {
facetFilters: ['version:' + siteDocsVersion]
},
transformData: function (hits) {
return hits.map(function (hit) {
var currentUrl = getOrigin()
var liveUrl = 'https://getbootstrap.com'
// When in production, return the result as is,
// otherwise remove our url from it.
// eslint-disable-next-line no-negated-condition
hit.url = currentUrl.indexOf(liveUrl) !== -1 ? // lgtm [js/incomplete-url-substring-sanitization]
hit.url :
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
})
2019-02-26 12:20:34 +01:00
})()