search.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // NOTICE!! DO NOT USE ANY OF THIS JAVASCRIPT
  2. // IT'S ALL JUST JUNK FOR OUR DOCS!
  3. // ++++++++++++++++++++++++++++++++++++++++++
  4. (function () {
  5. 'use strict'
  6. var inputElement = document.getElementById('search-input')
  7. if (!window.docsearch || !inputElement) {
  8. return
  9. }
  10. var siteDocsVersion = inputElement.getAttribute('data-bd-docs-version')
  11. document.addEventListener('keydown', function (event) {
  12. if (event.ctrlKey && event.key === '/') {
  13. event.preventDefault()
  14. inputElement.focus()
  15. }
  16. })
  17. window.docsearch({
  18. apiKey: '5990ad008512000bba2cf951ccf0332f',
  19. indexName: 'bootstrap',
  20. inputSelector: '#search-input',
  21. algoliaOptions: {
  22. facetFilters: ['version:' + siteDocsVersion]
  23. },
  24. transformData: function (hits) {
  25. return hits.map(function (hit) {
  26. var liveUrl = 'https://getbootstrap.com/'
  27. hit.url = window.location.origin.startsWith(liveUrl) ?
  28. // On production, return the result as is
  29. hit.url :
  30. // On development or Netlify, replace `hit.url` with a trailing slash,
  31. // so that the result link is relative to the server root
  32. hit.url.replace(liveUrl, '/')
  33. // Prevent jumping to first header
  34. if (hit.anchor === 'content') {
  35. hit.url = hit.url.replace(/#content$/, '')
  36. hit.anchor = null
  37. }
  38. return hit
  39. })
  40. },
  41. // Set debug to `true` if you want to inspect the dropdown
  42. debug: false
  43. })
  44. })()