1
0
mirror of https://github.com/squidfunk/mkdocs-material.git synced 2024-11-12 01:50:52 +01:00

Improved search user experience

This commit is contained in:
squidfunk 2017-07-25 17:02:42 +02:00 committed by Martin Donath
parent 357c6f4122
commit bda96f88df
3 changed files with 7 additions and 9 deletions

File diff suppressed because one or more lines are too long

View File

@ -150,7 +150,7 @@
{% endblock %}
</div>
{% block scripts %}
<script src="{{ base_url }}/assets/javascripts/application-8ec1c9e2d8.js"></script>
<script src="{{ base_url }}/assets/javascripts/application-07b0fbb49b.js"></script>
{% set languages = lang.t("search.languages").split(",") %}
{% if languages | length and languages[0] != "" %}
{% set path = base_url + "/assets/javascripts/lunr" %}

View File

@ -302,9 +302,8 @@ function initialize(config) { // eslint-disable-line func-style
/* Retrieve all results */
const links = Array.prototype.slice.call(
document.querySelectorAll("[data-md-component=search] [href]"))
if (!links.length)
return
document.querySelectorAll(
"[data-md-component=query], [data-md-component=search] [href]"))
/* Retrieve current active/focused result */
const focus = links.find(link => {
@ -321,10 +320,10 @@ function initialize(config) { // eslint-disable-line func-style
) % links.length)
/* Set active state and focus */
if (!(links[index] instanceof HTMLElement))
throw new ReferenceError
links[index].dataset.mdState = "active"
links[index].focus()
if (links[index]) {
links[index].dataset.mdState = "active"
links[index].focus()
}
/* Prevent scrolling of page */
ev.preventDefault()