diff options
author | XhmikosR <xhmikosr@gmail.com> | 2018-04-09 23:53:45 +0300 |
---|---|---|
committer | XhmikosR <xhmikosr@gmail.com> | 2018-04-27 10:22:58 +0300 |
commit | 30cb1a2715fc1f920fd225ce5f7452e77fc819f8 (patch) | |
tree | ffe982ec63f429cc8a98dfba8ef08527c19aafbd /assets | |
parent | b5988a4430138455d2e972fe6302ec089338a6e5 (diff) |
Pass docs version to search form and switch to the new index.
Also, move the search code to a separate file.
Diffstat (limited to 'assets')
-rw-r--r-- | assets/js/src/application.js | 28 | ||||
-rw-r--r-- | assets/js/src/search.js | 38 |
2 files changed, 38 insertions, 28 deletions
diff --git a/assets/js/src/application.js b/assets/js/src/application.js index 1f1af444c9..7666da065d 100644 --- a/assets/js/src/application.js +++ b/assets/js/src/application.js @@ -101,34 +101,6 @@ anchors.add('.bd-content > h2, .bd-content > h3, .bd-content > h4, .bd-content > h5') $('.bd-content > h2, .bd-content > h3, .bd-content > h4, .bd-content > h5').wrapInner('<div></div>') - // Search - if (window.docsearch) { - window.docsearch({ - apiKey: '48cb48b22351bc71ea5f12f4d1ede198', - indexName: 'bootstrap-v4', - 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) { - // When in production, return the result as is, - // otherwise remove our url from it. - var siteurl = document.getElementById('search-input').getAttribute('data-siteurl') - var urlRE = /^https?:\/\/getbootstrap\.com/ - - 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 - }) - } - // Holder Holder.addTheme('gray', { bg: '#777', diff --git a/assets/js/src/search.js b/assets/js/src/search.js new file mode 100644 index 0000000000..3acd71c6f7 --- /dev/null +++ b/assets/js/src/search.js @@ -0,0 +1,38 @@ +(function () { + 'use strict' + + if (!window.docsearch) { + return + } + + var inputElement = document.getElementById('search-input') + var siteDocsVersion = inputElement.getAttribute('data-docs-version') + + window.docsearch({ + apiKey: '5990ad008512000bba2cf951ccf0332f', + indexName: 'bootstrap', + inputSelector: '#search-input', + algoliaOptions: { + facetFilters: ['version:' + siteDocsVersion] + }, + 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) { + // When in production, return the result as is, + // otherwise remove our url from it. + var siteurl = inputElement.getAttribute('data-siteurl') + var urlRE = /^https?:\/\/getbootstrap\.com/ + + 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 + }) +}()) |