Skip to content

Update DocSearch.js to latest version#27710

Merged
XhmikosR merged 1 commit intotwbs:v4-devfrom
algolia:docs/docsearch-update
Nov 22, 2018
Merged

Update DocSearch.js to latest version#27710
XhmikosR merged 1 commit intotwbs:v4-devfrom
algolia:docs/docsearch-update

Conversation

@pixelastic
Copy link
Copy Markdown
Contributor

The latest (2.6.2) docsearch.js version now displays results as standard <a href> links, allowing users to ctrl-click on them to trigger default browser behavior of opening in a new tab. This has been a been a long awaited feature and is now live.

To maintain backward compatibility, this behavior has only been enabled to users that didn't define their own handleSelected method. Because the Bootstrap documentation uses its own handleSelected, you won't be able to ctrl-clicks results as of today :/

This PR updates your docsearch() code to take advantage of the new <a href> 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 <h1> of the pages (source), which would prevent users from seeing the header. This PR checks if the suggestion targets the #content anchor (meaning it goes to this first <h1>) and if so, removes it.

Behavior should be the same, but at least now you can enjoy the ctrl-click :)

The latest (2.6.2) docsearch.js version now displays results as standard `<a href>` 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 `<a href>` 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 `<h1>` 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 `<h1>`) and remove it.

Behavior should be the same, but at least now you can enjoy the `ctrl`-click :)
@pixelastic pixelastic requested a review from a team as a code owner November 22, 2018 14:45
Copy link
Copy Markdown
Member

@Johann-S Johann-S left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@XhmikosR XhmikosR merged commit 3e25bf4 into twbs:v4-dev Nov 22, 2018
@mdo mdo mentioned this pull request Nov 22, 2018
@XhmikosR
Copy link
Copy Markdown
Member

Thanks @pixelastic.

Note to self, backport this to master-xmr-v3-fixes branch.

@pixelastic pixelastic deleted the docs/docsearch-update branch November 25, 2018 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants