diff --git a/src/main/kotlin/kweb/html/events/keySpecificKeyup.kt b/src/main/kotlin/kweb/plugins/specificKeyUp/SpecificKeyUp.kt old mode 100755 new mode 100644 similarity index 79% rename from src/main/kotlin/kweb/html/events/keySpecificKeyup.kt rename to src/main/kotlin/kweb/plugins/specificKeyUp/SpecificKeyUp.kt index aab01d2c3b..d10b7db8c2 --- a/src/main/kotlin/kweb/html/events/keySpecificKeyup.kt +++ b/src/main/kotlin/kweb/plugins/specificKeyUp/SpecificKeyUp.kt @@ -1,7 +1,19 @@ -package kweb.html.events +package kweb.plugins.specificKeyUp import kweb.Element import kweb.InputElement +import kweb.html.events.KeyboardEvent +import kweb.html.events.OnImmediateReceiver +import kweb.html.events.OnReceiver +import kweb.plugins.KwebPlugin + +/** + * @author sanity + * + * This plugin allows registering a listener on a specific key to avoid sending all `keyup` events + * to the backend. + */ +object SpecificKeyUpPlugin : KwebPlugin() private const val ENTER_PRESSED_EVENT_ATTACHED_FLAG = "enterPressedEventAttached" @@ -11,7 +23,7 @@ fun InputElement.attachKeySpecificKeyupEvent(vararg keys: String) { flags += ENTER_PRESSED_EVENT_ATTACHED_FLAG this.execute(""" $jsExpression.addEventListener("keyup", function(origEvent) { - var keys = [${keys.map { "\"$it\"" }.joinToString(separator = ",")}] + var keys = [${keys.joinToString(separator = ",") { "\"$it\"" }}] if (keys.includes(origEvent.key)) { if (window.CustomEvent) { var keySpecificKeyUpEvent = new CustomEvent('keySpecificKeyUpEvent');