From d24d47c27add7878c20e2a4b5502c03214120adb Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Thu, 20 Sep 2018 12:07:38 +0300 Subject: [PATCH] Backport search from v4 and adapt it for v3.4.0. --- docs/_includes/footer.html | 22 +++------------- docs/_includes/header.html | 2 +- docs/assets/js/src/search.js | 51 ++++++++++++++++++++++++++++++++++++ grunt/configBridge.json | 3 ++- 4 files changed, 58 insertions(+), 20 deletions(-) create mode 100644 docs/assets/js/src/search.js diff --git a/docs/_includes/footer.html b/docs/_includes/footer.html index c31f1f4645..e7a5bf955e 100644 --- a/docs/_includes/footer.html +++ b/docs/_includes/footer.html @@ -29,6 +29,10 @@ {% endif %} +{% if page.layout == "default" %} + +{% endif %} + {% if site.github %} {% else %} @@ -37,24 +41,6 @@ {% endfor %} {% endif %} -{% if page.slug == "getting-started" or page.slug == "css" or page.slug == "components" or page.slug == "js" %} - - -{% endif %} - {% if page.slug == "customize" %} {% if site.github %} diff --git a/docs/_includes/header.html b/docs/_includes/header.html index f63e9e3f3c..7446ba8867 100644 --- a/docs/_includes/header.html +++ b/docs/_includes/header.html @@ -28,7 +28,7 @@ {% endif %} {% endif %} -{% if page.slug == "getting-started" or page.slug == "css" or page.slug == "components" or page.slug == "js" %} +{% if page.layout == "default" %} {% endif %} diff --git a/docs/assets/js/src/search.js b/docs/assets/js/src/search.js new file mode 100644 index 0000000000..53fec2a702 --- /dev/null +++ b/docs/assets/js/src/search.js @@ -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 + }) +}()) diff --git a/grunt/configBridge.json b/grunt/configBridge.json index f7f991c6b2..956311fed0 100644 --- a/grunt/configBridge.json +++ b/grunt/configBridge.json @@ -14,7 +14,8 @@ "/docs/3.4/assets/js/vendor/holder.min.js", "/docs/3.4/assets/js/vendor/clipboard.min.js", "/docs/3.4/assets/js/vendor/anchor.min.js", - "/docs/3.4/assets/js/src/application.js" + "/docs/3.4/assets/js/src/application.js", + "/docs/3.4/assets/js/src/search.js" ] }, "config": {