From d270d087dab24175949a819b2ab2037d31c28b6b Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Fri, 15 May 2020 17:07:19 +0200 Subject: Add new generic onClick handler extension function. --- src/main/kotlin/pl/treksoft/kvision/core/Widget.kt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/main/kotlin/pl/treksoft/kvision') diff --git a/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt b/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt index d077415e..c0e684ba 100644 --- a/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt +++ b/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt @@ -27,6 +27,7 @@ import com.github.snabbdom.h import org.w3c.dom.CustomEventInit import org.w3c.dom.DragEvent import org.w3c.dom.Node +import org.w3c.dom.events.MouseEvent import pl.treksoft.jquery.JQuery import pl.treksoft.jquery.jQuery import pl.treksoft.kvision.KVManager @@ -868,6 +869,20 @@ fun Container.widget( return widget } +/** + * An extension function for defining event handlers. + */ inline fun T.onEvent(noinline block: SnOn.() -> Unit): Int { return this.setEventListener(block) } + +/** + * An extension function for defining on click event handlers. + */ +inline fun T.onClick(noinline handler: T.(MouseEvent) -> Unit): Int { + return this.setEventListener { + click = { e -> + self.handler(e) + } + } +} -- cgit