2
0
mirror of https://github.com/tenrok/bootstrap.git synced 2026-06-05 16:42:29 +03:00

Backport search from v4 and adapt it for v3.4.0.

This commit is contained in:
XhmikosR
2018-09-20 12:07:38 +03:00
parent ebe7459665
commit d24d47c27a
4 changed files with 58 additions and 20 deletions
+51
View File
@@ -0,0 +1,51 @@
// NOTICE!! DO NOT USE ANY OF THIS JAVASCRIPT
// IT'S ALL JUST JUNK FOR OUR DOCS!
// ++++++++++++++++++++++++++++++++++++++++++
(function () {
'use strict'
var inputElement = document.getElementById('search-input')
if (!window.docsearch || !inputElement) {
return
}
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: 'c8948afa20e6437a6e829f7e87b9ac11',
indexName: 'bootstrap-v3',
inputSelector: '#search-input',
handleSelected: function (input, event, suggestion) {
var url = suggestion.url
url = suggestion.isLvl1 ? url.split('#')[0] : url
// If it's a title we remove the anchor so it does not jump.
window.location.href = url
},
transformData: function (hits) {
return hits.map(function (hit) {
var siteurl = getOrigin()
var urlRE = /^https?:\/\/getbootstrap\.com/
// When in production, return the result as is,
// otherwise remove our url from it.
hit.url = siteurl.match(urlRE) ? hit.url : hit.url.replace(urlRE, '')
return hit
})
},
debug: false // Set debug to true if you want to inspect the dropdown
})
}())