Add ESC handler to search modal

This commit is contained in:
squidfunk 2016-12-28 17:32:56 +01:00
parent 9d4a8409f9
commit 4ed0b1328f
3 changed files with 15 additions and 2 deletions

View File

@ -110,7 +110,7 @@
<script src="https://cdn.mathjax.org/{{ path }}"></script> <script src="https://cdn.mathjax.org/{{ path }}"></script>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
<script src="{{ base_url }}/assets/javascripts/application-7481d5412b.js"></script> <script src="{{ base_url }}/assets/javascripts/application-5c0b7e9d97.js"></script>
<script> <script>
/* Configuration for application */ /* Configuration for application */
var config = { var config = {

View File

@ -183,6 +183,19 @@ export default class Application {
} }
})) }))
/* Listener: disable search when ESC key is pressed */
new Material.Event.Listener(window, "keyup", ev => {
const code = ev.keyCode || ev.which
if (code === 27) {
const toggle = document.querySelector("[data-md-toggle=search]")
if (toggle.checked) {
toggle.checked = false
dispatch(toggle, "change")
document.forms.search.query.blur()
}
}
}).listen()
/* Listener: fix unclickable toggle due to blur handler */ /* Listener: fix unclickable toggle due to blur handler */
new Material.Event.MatchMedia("(min-width: 960px)", new Material.Event.MatchMedia("(min-width: 960px)",
new Material.Event.Listener("[data-md-toggle=search]", "click", new Material.Event.Listener("[data-md-toggle=search]", "click",