search.js 1.52 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
8
9
10
11
12
13
14
(function () {
  'use strict'

  if (!window.docsearch) {
    return
  }

  var inputElement = document.getElementById('search-input')
  var siteDocsVersion = inputElement.getAttribute('data-docs-version')

15
16
17
18
19
20
21
22
23
24
25
26
27
  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
  }

28
29
30
31
32
33
34
35
36
  window.docsearch({
    apiKey: '5990ad008512000bba2cf951ccf0332f',
    indexName: 'bootstrap',
    inputSelector: '#search-input',
    algoliaOptions: {
      facetFilters: ['version:' + siteDocsVersion]
    },
    transformData: function (hits) {
      return hits.map(function (hit) {
37
38
        var currentUrl = getOrigin()
        var liveUrl = 'https://getbootstrap.com'
39

40
41
        // When in production, return the result as is,
        // otherwise remove our url from it.
42
43
44
45
        // eslint-disable-next-line no-negated-condition
        hit.url = currentUrl.indexOf(liveUrl) !== -1 ?
          hit.url :
          hit.url.replace(liveUrl, '')
46

47
48
49
50
51
52
        // Prevent jumping to first header
        if (hit.anchor === 'content') {
          hit.url = hit.url.replace(/#content$/, '')
          hit.anchor = null
        }

53
54
55
        return hit
      })
    },
56
57
    // Set debug to `true` if you want to inspect the dropdown
    debug: false
58
  })
XhmikosR's avatar
XhmikosR committed
59
})()