mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2024-06-14 11:52:32 +03:00
Changed keyboard event handlers to key codes for compatibility
This commit is contained in:
parent
de54e6e800
commit
9d066f5f78
File diff suppressed because one or more lines are too long
3
material/assets/javascripts/application-c6f9af8d0c.js
Normal file
3
material/assets/javascripts/application-c6f9af8d0c.js
Normal file
File diff suppressed because one or more lines are too long
@ -151,7 +151,7 @@
|
||||
{% endblock %}
|
||||
</div>
|
||||
{% block scripts %}
|
||||
<script src="{{ base_url }}/assets/javascripts/application-66b3bb18b3.js"></script>
|
||||
<script src="{{ base_url }}/assets/javascripts/application-c6f9af8d0c.js"></script>
|
||||
<script>app.initialize({url:{base:"{{ base_url }}"}})</script>
|
||||
{% for path in extra_javascript %}
|
||||
<script src="{{ path }}"></script>
|
||||
|
@ -233,30 +233,25 @@ function initialize(config) { // eslint-disable-line func-style
|
||||
if (toggle.checked) {
|
||||
|
||||
/* Enter: prevent form submission */
|
||||
if (ev.key === "Enter") {
|
||||
if (ev.keyCode === 13) {
|
||||
if (query === document.activeElement)
|
||||
ev.preventDefault()
|
||||
|
||||
/* Escape: close search */
|
||||
} else if (ev.key === "Escape") {
|
||||
} else if (ev.keyCode === 27) {
|
||||
toggle.checked = false
|
||||
toggle.dispatchEvent(new CustomEvent("change"))
|
||||
query.blur()
|
||||
|
||||
/* Horizontal arrows and backspace: focus input */
|
||||
} else if ([
|
||||
"ArrowLeft", "ArrowRight", "Backspace"
|
||||
].indexOf(ev.key) !== -1) {
|
||||
} else if ([8, 37, 39].indexOf(ev.keyCode) !== -1) {
|
||||
if (query !== document.activeElement)
|
||||
query.focus()
|
||||
|
||||
/* Vertical arrows and tab: select previous or next search result */
|
||||
} else if ([
|
||||
"ArrowUp", "ArrowDown", "Tab"
|
||||
].indexOf(ev.key) !== -1) {
|
||||
const key = ev.key === "Tab"
|
||||
? `Arrow${ev.shiftKey ? "Up" : "Down"}`
|
||||
: ev.key
|
||||
} else if ([9, 38, 40].indexOf(ev.keyCode) !== -1) {
|
||||
const map = ev.shiftKey ? 38 : 40
|
||||
const key = ev.keyCode === 9 ? map : ev.keyCode
|
||||
|
||||
/* Retrieve all results */
|
||||
const links = Array.prototype.slice.call(
|
||||
@ -275,7 +270,7 @@ function initialize(config) { // eslint-disable-line func-style
|
||||
|
||||
/* Calculate index depending on direction, add length to form ring */
|
||||
const index = Math.max(0, (
|
||||
links.indexOf(focus) + links.length + (key === "ArrowUp" ? -1 : +1)
|
||||
links.indexOf(focus) + links.length + (key === 38 ? -1 : +1)
|
||||
) % links.length)
|
||||
|
||||
/* Set active state and focus */
|
||||
@ -295,8 +290,8 @@ function initialize(config) { // eslint-disable-line func-style
|
||||
/* Search is closed */
|
||||
} else {
|
||||
|
||||
/* S: Open search if not in input field */
|
||||
if (ev.key === "s") {
|
||||
/* F/S: Open search if not in input field */
|
||||
if (ev.keyCode === 70 || ev.keyCode === 83) {
|
||||
query.focus()
|
||||
ev.preventDefault()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user