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 %} {% endblock %}
</div> </div>
{% block scripts %} {% 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(",") %} {% set languages = lang.t("search.languages").split(",") %}
{% if languages | length and languages[0] != "" %} {% if languages | length and languages[0] != "" %}
{% set path = base_url + "/assets/javascripts/lunr" %} {% set path = base_url + "/assets/javascripts/lunr" %}

View File

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