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 %}
|
{% endblock %}
|
||||||
</div>
|
</div>
|
||||||
{% block scripts %}
|
{% 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>
|
<script>app.initialize({url:{base:"{{ base_url }}"}})</script>
|
||||||
{% for path in extra_javascript %}
|
{% for path in extra_javascript %}
|
||||||
<script src="{{ path }}"></script>
|
<script src="{{ path }}"></script>
|
||||||
|
@ -233,30 +233,25 @@ function initialize(config) { // eslint-disable-line func-style
|
|||||||
if (toggle.checked) {
|
if (toggle.checked) {
|
||||||
|
|
||||||
/* Enter: prevent form submission */
|
/* Enter: prevent form submission */
|
||||||
if (ev.key === "Enter") {
|
if (ev.keyCode === 13) {
|
||||||
if (query === document.activeElement)
|
if (query === document.activeElement)
|
||||||
ev.preventDefault()
|
ev.preventDefault()
|
||||||
|
|
||||||
/* Escape: close search */
|
/* Escape: close search */
|
||||||
} else if (ev.key === "Escape") {
|
} else if (ev.keyCode === 27) {
|
||||||
toggle.checked = false
|
toggle.checked = false
|
||||||
toggle.dispatchEvent(new CustomEvent("change"))
|
toggle.dispatchEvent(new CustomEvent("change"))
|
||||||
query.blur()
|
query.blur()
|
||||||
|
|
||||||
/* Horizontal arrows and backspace: focus input */
|
/* Horizontal arrows and backspace: focus input */
|
||||||
} else if ([
|
} else if ([8, 37, 39].indexOf(ev.keyCode) !== -1) {
|
||||||
"ArrowLeft", "ArrowRight", "Backspace"
|
|
||||||
].indexOf(ev.key) !== -1) {
|
|
||||||
if (query !== document.activeElement)
|
if (query !== document.activeElement)
|
||||||
query.focus()
|
query.focus()
|
||||||
|
|
||||||
/* Vertical arrows and tab: select previous or next search result */
|
/* Vertical arrows and tab: select previous or next search result */
|
||||||
} else if ([
|
} else if ([9, 38, 40].indexOf(ev.keyCode) !== -1) {
|
||||||
"ArrowUp", "ArrowDown", "Tab"
|
const map = ev.shiftKey ? 38 : 40
|
||||||
].indexOf(ev.key) !== -1) {
|
const key = ev.keyCode === 9 ? map : ev.keyCode
|
||||||
const key = ev.key === "Tab"
|
|
||||||
? `Arrow${ev.shiftKey ? "Up" : "Down"}`
|
|
||||||
: ev.key
|
|
||||||
|
|
||||||
/* Retrieve all results */
|
/* Retrieve all results */
|
||||||
const links = Array.prototype.slice.call(
|
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 */
|
/* Calculate index depending on direction, add length to form ring */
|
||||||
const index = Math.max(0, (
|
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)
|
) % links.length)
|
||||||
|
|
||||||
/* Set active state and focus */
|
/* Set active state and focus */
|
||||||
@ -295,8 +290,8 @@ function initialize(config) { // eslint-disable-line func-style
|
|||||||
/* Search is closed */
|
/* Search is closed */
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
/* S: Open search if not in input field */
|
/* F/S: Open search if not in input field */
|
||||||
if (ev.key === "s") {
|
if (ev.keyCode === 70 || ev.keyCode === 83) {
|
||||||
query.focus()
|
query.focus()
|
||||||
ev.preventDefault()
|
ev.preventDefault()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user