From 3e25bf403a9d07dbeef701c340c1de47bb4e58ca Mon Sep 17 00:00:00 2001 From: Pixelastic Date: Thu, 22 Nov 2018 15:34:34 +0100 Subject: [PATCH] Update DocSearch.js to latest version The latest (2.6.2) docsearch.js version now displays results as standard `` links, allowing users to `ctrl`-click on them to trigger default browser behavior of opening in a new tab. To maintain backward compatibility, this behavior has only been enabled to users that didn't define their own `handleSelected` method. This PR updates your `docsearch()` code to take advantage of the new `` template, by removing your custom `handleSelected` and moving its behavior to the `transformData` call. Namely, what you wanted to avoid was jumping to the first `

` of the pages, which would prevent users from seeing the header. This PR checks if the suggestion targets the `#content` anchor (meaning it goes to this first `

`) and remove it. Behavior should be the same, but at least now you can enjoy the `ctrl`-click :) --- site/docs/4.1/assets/js/src/search.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/site/docs/4.1/assets/js/src/search.js b/site/docs/4.1/assets/js/src/search.js index 546cca5c7e..459d412df9 100644 --- a/site/docs/4.1/assets/js/src/search.js +++ b/site/docs/4.1/assets/js/src/search.js @@ -32,12 +32,6 @@ 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) { var siteurl = getOrigin() @@ -47,6 +41,12 @@ // otherwise remove our url from it. hit.url = siteurl.match(urlRE) ? hit.url : hit.url.replace(urlRE, '') + // Prevent jumping to first header + if (hit.anchor === 'content') { + hit.url = hit.url.replace(/#content$/, '') + hit.anchor = null + } + return hit }) }, -- 2.47.2