summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/Showcase.kt15
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt22
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/modal/Modal.kt16
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/snabbdom/Types.kt22
4 files changed, 40 insertions, 35 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/Showcase.kt b/src/main/kotlin/pl/treksoft/kvision/Showcase.kt
index 1e93d95a..3bccdfb1 100644
--- a/src/main/kotlin/pl/treksoft/kvision/Showcase.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/Showcase.kt
@@ -36,10 +36,13 @@ class Showcase : ApplicationBase() {
val dd = DropDown("Dropdown", listOf("abc" to "#!/x", "def" to "#!/y"), "flag")
root.add(dd)
- dd.setEventListener<Button> {
- showBsDropdown = { e -> println("show" + (e.detail)?.text) }
+ dd.setEventListener<DropDown> {
+ showBsDropdown = { e -> println("show" + (e.detail)) }
shownBsDropdown = { e -> println("shown" + e.detail) }
- hideBsDropdown = { e -> println("hide" + e.detail) }
+ hideBsDropdown = { e ->
+ println("hide" + e.detail)
+ e.detail.preventDefault()
+ }
hiddenBsDropdown = { e -> println("hidden" + e.detail) }
}
@@ -47,7 +50,7 @@ class Showcase : ApplicationBase() {
"Header" to HEADER.POS, "Separtatorek" to SEPARATOR.POS
), "flag", dropup = true)
root.add(dd2)
- dd2.setEventListener<Button> {
+ dd2.setEventListener<DropDown> {
hideBsDropdown = { e -> println("hide" + e.detail) }
hiddenBsDropdown = { e -> println("hidden" + e.detail) }
}
@@ -82,7 +85,9 @@ class Showcase : ApplicationBase() {
modal.add(Tag(TAG.H4, "ABC"))
modal.add(Image(Img("kotlin.png")))
modal.addButton(Button("To jest button"))
-
+/* modal.setEventListener<Modal> {
+ hideBsModal = { e -> e.detail.preventDefault() }
+ }*/
val button = Button("To jest przycisk FA", "fa-flag", BUTTONSTYLE.DANGER)
button.setEventListener<Button> {
click = { _ ->
diff --git a/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt b/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt
index 708752ea..00e8fd9b 100644
--- a/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt
@@ -131,21 +131,21 @@ open class DropDown(text: String, elements: List<StringPair>? = null, icon: Stri
@Suppress("UnsafeCastFromDynamic")
override fun afterInsert(node: VNode) {
- this.getElementJQuery()?.on("show.bs.dropdown", { _, _ ->
- val event = CustomEvent("showBsDropdown", obj({ detail = button }))
+ this.getElementJQuery()?.on("show.bs.dropdown", { e, _ ->
+ val event = CustomEvent("showBsDropdown", obj({ detail = e }))
this.getElement()?.dispatchEvent(event)
})
- this.getElementJQuery()?.on("shown.bs.dropdown", { _, _ ->
- val event = CustomEvent("shownBsDropdown", obj({ detail = button }))
+ this.getElementJQuery()?.on("shown.bs.dropdown", { e, _ ->
+ val event = CustomEvent("shownBsDropdown", obj({ detail = e }))
this.getElement()?.dispatchEvent(event)
})
- this.getElementJQuery()?.on("hide.bs.dropdown", { _, _ ->
- val event = CustomEvent("hideBsDropdown", obj({ detail = button }))
+ this.getElementJQuery()?.on("hide.bs.dropdown", { e, _ ->
+ val event = CustomEvent("hideBsDropdown", obj({ detail = e }))
this.getElement()?.dispatchEvent(event)
})
- this.getElementJQuery()?.on("hidden.bs.dropdown", { _, _ ->
+ this.getElementJQuery()?.on("hidden.bs.dropdown", { e, _ ->
list.visible = false
- val event = CustomEvent("hiddenBsDropdown", obj({ detail = button }))
+ val event = CustomEvent("hiddenBsDropdown", obj({ detail = e }))
this.getElement()?.dispatchEvent(event)
})
}
@@ -161,7 +161,7 @@ open class DropDown(text: String, elements: List<StringPair>? = null, icon: Stri
open fun toggle() {
if (list.visible)
- list.hide()
+ list.hideInternal()
else
list.show()
}
@@ -199,14 +199,14 @@ open class DropDownListTag(private val ariaId: String, classes: Set<String> = se
}
@Suppress("UnsafeCastFromDynamic")
- private fun showInternal() {
+ internal fun showInternal() {
if (getElementJQueryD()?.`is`(":hidden")) {
getElementJQueryD()?.dropdown("toggle")
}
}
@Suppress("UnsafeCastFromDynamic")
- private fun hideInternal() {
+ internal fun hideInternal() {
if (!getElementJQueryD()?.`is`(":hidden")) {
getElementJQueryD()?.dropdown("toggle")
}
diff --git a/src/main/kotlin/pl/treksoft/kvision/modal/Modal.kt b/src/main/kotlin/pl/treksoft/kvision/modal/Modal.kt
index 0b11d45f..1a0bce1a 100644
--- a/src/main/kotlin/pl/treksoft/kvision/modal/Modal.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/modal/Modal.kt
@@ -132,21 +132,21 @@ open class Modal(caption: String? = null, closeButton: Boolean = true,
keyboard = escape
backdrop = if (escape) "true" else "static"
})
- this.getElementJQuery()?.on("show.bs.modal", { _, _ ->
- val event = CustomEvent("showBsModal")
+ this.getElementJQuery()?.on("show.bs.modal", { e, _ ->
+ val event = CustomEvent("showBsModal", obj({ detail = e }))
this.getElement()?.dispatchEvent(event)
})
- this.getElementJQuery()?.on("shown.bs.modal", { _, _ ->
- val event = CustomEvent("shownBsModal")
+ this.getElementJQuery()?.on("shown.bs.modal", { e, _ ->
+ val event = CustomEvent("shownBsModal", obj({ detail = e }))
this.getElement()?.dispatchEvent(event)
})
- this.getElementJQuery()?.on("hide.bs.modal", { _, _ ->
- val event = CustomEvent("hideBsModal")
+ this.getElementJQuery()?.on("hide.bs.modal", { e, _ ->
+ val event = CustomEvent("hideBsModal", obj({ detail = e }))
this.getElement()?.dispatchEvent(event)
})
- this.getElementJQuery()?.on("hidden.bs.modal", { _, _ ->
+ this.getElementJQuery()?.on("hidden.bs.modal", { e, _ ->
this.visible = false
- val event = CustomEvent("hiddenBsModal")
+ val event = CustomEvent("hiddenBsModal", obj({ detail = e }))
this.getElement()?.dispatchEvent(event)
})
}
diff --git a/src/main/kotlin/pl/treksoft/kvision/snabbdom/Types.kt b/src/main/kotlin/pl/treksoft/kvision/snabbdom/Types.kt
index a9ee9442..e8df9971 100644
--- a/src/main/kotlin/pl/treksoft/kvision/snabbdom/Types.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/snabbdom/Types.kt
@@ -9,8 +9,8 @@ import com.github.snabbdom.VNodeData
import com.github.snabbdom.VNodeStyle
import org.w3c.dom.CustomEvent
import org.w3c.dom.CustomEventInit
+import pl.treksoft.jquery.JQueryEventObject
import pl.treksoft.kvision.core.Widget
-import pl.treksoft.kvision.html.Button
external class Object
@@ -21,19 +21,19 @@ fun obj(init: dynamic.() -> Unit): dynamic {
@Suppress("UnsafeCastFromDynamic")
private fun vNodeData(): VNodeData = js("({})")
-class DropDownEvent(type: String, eventInitDict: CustomEventInit) : CustomEvent(type, eventInitDict) {
- override val detail: Button? = null
+class KvEvent(type: String, eventInitDict: CustomEventInit) : CustomEvent(type, eventInitDict) {
+ override val detail: JQueryEventObject = obj({})
}
interface BtOn : On {
- var showBsDropdown: ((DropDownEvent) -> kotlin.Unit)?
- var shownBsDropdown: ((DropDownEvent) -> kotlin.Unit)?
- var hideBsDropdown: ((DropDownEvent) -> kotlin.Unit)?
- var hiddenBsDropdown: ((DropDownEvent) -> kotlin.Unit)?
- var showBsModal: ((CustomEvent) -> kotlin.Unit)?
- var shownBsModal: ((CustomEvent) -> kotlin.Unit)?
- var hideBsModal: ((CustomEvent) -> kotlin.Unit)?
- var hiddenBsModal: ((CustomEvent) -> kotlin.Unit)?
+ var showBsDropdown: ((KvEvent) -> kotlin.Unit)?
+ var shownBsDropdown: ((KvEvent) -> kotlin.Unit)?
+ var hideBsDropdown: ((KvEvent) -> kotlin.Unit)?
+ var hiddenBsDropdown: ((KvEvent) -> kotlin.Unit)?
+ var showBsModal: ((KvEvent) -> kotlin.Unit)?
+ var shownBsModal: ((KvEvent) -> kotlin.Unit)?
+ var hideBsModal: ((KvEvent) -> kotlin.Unit)?
+ var hiddenBsModal: ((KvEvent) -> kotlin.Unit)?
}
interface SnOn<T> : BtOn {