search.js 1.46 KB
Newer Older
XhmikosR's avatar
XhmikosR committed
1
2
3
4
// NOTICE!! DO NOT USE ANY OF THIS JAVASCRIPT
// IT'S ALL JUST JUNK FOR OUR DOCS!
// ++++++++++++++++++++++++++++++++++++++++++

5
6
7
(function () {
  'use strict'

8
9
10
  var inputElement = document.getElementById('search-input')

  if (!window.docsearch || !inputElement) {
11
12
13
    return
  }

14
  var siteDocsVersion = inputElement.getAttribute('data-bd-docs-version')
15

16
17
18
19
20
21
22
  document.addEventListener('keydown', function (event) {
    if (event.ctrlKey && event.key === '/') {
      event.preventDefault()
      inputElement.focus()
    }
  })

23
24
25
26
27
28
29
30
31
  window.docsearch({
    apiKey: '5990ad008512000bba2cf951ccf0332f',
    indexName: 'bootstrap',
    inputSelector: '#search-input',
    algoliaOptions: {
      facetFilters: ['version:' + siteDocsVersion]
    },
    transformData: function (hits) {
      return hits.map(function (hit) {
32
        var liveUrl = 'https://v5.getbootstrap.com/'
33

34
        hit.url = window.location.origin.startsWith(liveUrl) ?
35
          // On production, return the result as is
36
          hit.url :
37
38
39
          // 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, '/')
40

41
42
43
44
45
46
        // Prevent jumping to first header
        if (hit.anchor === 'content') {
          hit.url = hit.url.replace(/#content$/, '')
          hit.anchor = null
        }

47
48
49
        return hit
      })
    },
50
51
    // Set debug to `true` if you want to inspect the dropdown
    debug: false
52
  })
XhmikosR's avatar
XhmikosR committed
53
})()