-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
282 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
let keyupSubmit; | ||
|
||
document.addEventListener("keyup", function (event) { | ||
if ( | ||
event.defaultPrevented || | ||
event.metaKey || | ||
whitespaceKeys.has(event.key) || | ||
modifierKeys.has(event.key) || | ||
navigationKeys.has(event.key) || | ||
uiKeys.has(event.key) || | ||
deviceKeys.has(event.key) || | ||
functionKeys.has(event.key) || | ||
mediaKeys.has(event.key) || | ||
audioControlKeys.has(event.key) | ||
) { | ||
return; | ||
} | ||
|
||
const { autoSubmit = "", autoSubmitDelay = 0 } = event.target.dataset; | ||
if (autoSubmit) { | ||
const button = document.querySelector("#" + autoSubmit); | ||
if (button) { | ||
const submit = () => button.click(); | ||
if (autoSubmitDelay) { | ||
clearTimeout(keyupSubmit); | ||
keyupSubmit = setTimeout(submit, Number(autoSubmitDelay)); | ||
} else { | ||
submit(); | ||
} | ||
} | ||
} | ||
}); | ||
|
||
document.addEventListener("change", function (event) { | ||
if (event.defaultPrevented) { | ||
return; | ||
} | ||
|
||
const { autoSubmit = "" } = event.target.dataset; | ||
if (autoSubmit) { | ||
const button = document.querySelector("#" + autoSubmit); | ||
if (button) { | ||
button.closest("form").requestSubmit(button); | ||
} | ||
} | ||
}); | ||
|
||
const whitespaceKeys = new Set(["Enter", "Tab", "Alt"]); | ||
|
||
const modifierKeys = new Set([ | ||
"AltGraph", | ||
"CapsLock", | ||
"Control", | ||
"Fn", | ||
"FnLock", | ||
"Hyper", | ||
"Meta", | ||
"NumLock", | ||
"ScrollLock", | ||
"Shift", | ||
"Super", | ||
"Symbol", | ||
"SymbolLock", | ||
]); | ||
|
||
const navigationKeys = new Set([ | ||
"ArrowDown", | ||
"ArrowLeft", | ||
"ArrowRight", | ||
"ArrowUp", | ||
"End", | ||
"Home", | ||
"PageDown", | ||
"PageUp", | ||
"End", | ||
]); | ||
|
||
const uiKeys = new Set([ | ||
"Accept", | ||
"ContextMenu", | ||
"Execute", | ||
"Find", | ||
"Help", | ||
"Pause", | ||
"Play", | ||
"Props", | ||
"Select", | ||
"ZoomIn", | ||
"ZoomOut", | ||
]); | ||
|
||
const deviceKeys = new Set([ | ||
"BrightnessDown", | ||
"BrightnessUp", | ||
"Eject", | ||
"LogOff", | ||
"Power", | ||
"PowerOff", | ||
"PrintScreen", | ||
"Hibernate", | ||
"Standby", | ||
"WakeUp", | ||
]); | ||
|
||
const functionKeys = new Set([ | ||
"F1", | ||
"F2", | ||
"F3", | ||
"F4", | ||
"F5", | ||
"F6", | ||
"F7", | ||
"F8", | ||
"F9", | ||
"F10", | ||
"F11", | ||
"F12", | ||
"F13", | ||
"F14", | ||
"F15", | ||
"F16", | ||
"F17", | ||
"F18", | ||
"F19", | ||
"F20", | ||
"Soft1", | ||
"Soft2", | ||
"Soft3", | ||
"Soft4", | ||
]); | ||
|
||
const mediaKeys = new Set([ | ||
"ChannelDown", | ||
"ChannelUp", | ||
"MediaFastForward", | ||
"MediaPause", | ||
"MediaPlay", | ||
"MediaPlayPause", | ||
"MediaRecord", | ||
"MediaRewind", | ||
"MediaStop", | ||
"MediaTrackNext", | ||
"MediaTrackPrevious", | ||
]); | ||
|
||
const audioControlKeys = new Set([ | ||
"AudioVolumeDown", | ||
"AudioVolumeMute", | ||
"AudioVolumeUp", | ||
"MicrophoneToggle", | ||
"MicrophoneVolumeDown", | ||
"MicrophoneVolumeMute", | ||
"MicrophoneVolumeUp", | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import "./autosubmit"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<!DOCTYPE html> | ||
<html lang="en" xmlns:th="http://www.thymeleaf.org"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<title>select</title> | ||
</head> | ||
<body> | ||
<span | ||
th:fragment="one(id, name, options)" | ||
class="inline-block relative w-full" | ||
th:classappend="${className}" | ||
th:with="autosubmit=${autosubmit ?: ''}" | ||
> | ||
<select | ||
th:id="${id}" | ||
th:name="${name}" | ||
class="appearance-none pl-2 py-1 pr-8 border border-gray-300 rounded" | ||
th:attrappend="data-auto-submit=${autosubmit}" | ||
> | ||
<option th:replace="${options}"></option> | ||
</select> | ||
<span | ||
class="select-caret pointer-events-none absolute inset-y-0 right-0 flex items-center px-2" | ||
> | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
viewBox="0 0 20 20" | ||
width="16" | ||
height="16" | ||
class="fill-current h-4 w-4" | ||
> | ||
<path | ||
d="M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z" | ||
/> | ||
</svg> | ||
</span> | ||
</span> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters