From 282b77ee9c9fd382d5ed576ad5bf7a41d97ca2a5 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Fri, 19 Oct 2018 19:43:12 +0300 Subject: docs search: take into account the current URL. --- site/docs/4.1/assets/js/src/search.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'site/docs') diff --git a/site/docs/4.1/assets/js/src/search.js b/site/docs/4.1/assets/js/src/search.js index 2e91fcf21..546cca5c7 100644 --- a/site/docs/4.1/assets/js/src/search.js +++ b/site/docs/4.1/assets/js/src/search.js @@ -12,6 +12,19 @@ var inputElement = document.getElementById('search-input') var siteDocsVersion = inputElement.getAttribute('data-docs-version') + 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: '5990ad008512000bba2cf951ccf0332f', indexName: 'bootstrap', @@ -27,11 +40,11 @@ }, 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 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 -- cgit v1.2.3