diff options
author | Robert Jaros <rjaros@finn.pl> | 2017-09-25 09:49:27 +0200 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2017-09-25 09:49:27 +0200 |
commit | 726a42ad5643840f84c289c9a6b56d6c3c9067b4 (patch) | |
tree | 61651f82b57adeb635712dca804264584d8371f1 /src/main/kotlin/pl/treksoft/kvision/panel | |
parent | e212e923e18b80d503f53271d6ba534e17b31e23 (diff) | |
download | kvision-726a42ad5643840f84c289c9a6b56d6c3c9067b4.tar.gz kvision-726a42ad5643840f84c289c9a6b56d6c3c9067b4.tar.bz2 kvision-726a42ad5643840f84c289c9a6b56d6c3c9067b4.zip |
Support for SplitPanel drag and dragEnd events
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/panel')
-rw-r--r-- | src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt index 234a9a20..be51149e 100644 --- a/src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt +++ b/src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt @@ -2,6 +2,7 @@ package pl.treksoft.kvision.panel import com.github.snabbdom.VNode import pl.treksoft.jquery.JQuery +import pl.treksoft.jquery.JQueryEventObject import pl.treksoft.kvision.core.Container import pl.treksoft.kvision.html.TAG import pl.treksoft.kvision.html.Tag @@ -17,19 +18,28 @@ open class SplitPanel(val direction: DIRECTION = DIRECTION.VERTICAL, internal val splitter = Splitter(this, direction) + @Suppress("UnsafeCastFromDynamic") internal fun afterInsertSplitter() { if (children.size == 2) { val horizontal = direction == DIRECTION.HORIZONTAL + val self = this children[0].getElementJQueryD().resizable(obj { handleSelector = "#" + splitter.id resizeWidth = !horizontal resizeHeight = horizontal - onDragEnd = { _: dynamic, el: JQuery, _: dynamic -> + onDrag = lok@ { e: JQueryEventObject, _: JQuery, newWidth: Int, newHeight: Int, _: dynamic -> + e.asDynamic()["newWidth"] = newWidth + e.asDynamic()["newHeight"] = newHeight + self.dispatchEvent("dragSplitPanel", obj({ detail = e })) + return@lok !e.isDefaultPrevented() + } + onDragEnd = { e: JQueryEventObject, el: JQuery, _: dynamic -> if (horizontal) { children[0].height = el.height().toInt() } else { children[0].width = el.width().toInt() } + self.dispatchEvent("dragEndSplitPanel", obj({ detail = e })) } }) } |