Improve calendar scolling
This commit is contained in:
parent
8913ccc3ce
commit
6d6deaeac1
|
@ -10,6 +10,9 @@ import org.w3c.dom.*
|
||||||
import kotlin.browser.document
|
import kotlin.browser.document
|
||||||
import kotlin.browser.window
|
import kotlin.browser.window
|
||||||
import kotlin.js.Date
|
import kotlin.js.Date
|
||||||
|
import kotlin.math.abs
|
||||||
|
import kotlin.math.max
|
||||||
|
import kotlin.math.min
|
||||||
|
|
||||||
class Calendar(calendar: HTMLElement) : View(calendar) {
|
class Calendar(calendar: HTMLElement) : View(calendar) {
|
||||||
|
|
||||||
|
@ -18,6 +21,8 @@ class Calendar(calendar: HTMLElement) : View(calendar) {
|
||||||
val calendarTable = calendar.getElementsByClassName("calendar-table")[0] as HTMLElement
|
val calendarTable = calendar.getElementsByClassName("calendar-table")[0] as HTMLElement
|
||||||
private val calendarTableHeader = calendar.getElementsByClassName("calendar-header")[0] as HTMLElement
|
private val calendarTableHeader = calendar.getElementsByClassName("calendar-header")[0] as HTMLElement
|
||||||
|
|
||||||
|
val htmlBody = document.body ?: createHtmlView()
|
||||||
|
|
||||||
val day = calendarTable.dataset["day"]?.toIntOrNull() ?: -1
|
val day = calendarTable.dataset["day"]?.toIntOrNull() ?: -1
|
||||||
val referenceDate = calendarTable.dataset["reference"]?.toLongOrNull() ?: -1L
|
val referenceDate = calendarTable.dataset["reference"]?.toLongOrNull() ?: -1L
|
||||||
val nowDate = calendarTable.dataset["now"]?.toLongOrNull() ?: -1L
|
val nowDate = calendarTable.dataset["now"]?.toLongOrNull() ?: -1L
|
||||||
|
@ -111,8 +116,34 @@ class Calendar(calendar: HTMLElement) : View(calendar) {
|
||||||
else -> 1.0
|
else -> 1.0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var verticalScroll = it.deltaY * multiplier
|
||||||
|
|
||||||
|
if (verticalScroll > 0) {
|
||||||
|
val x = html.offsetTop - htmlBody.scrollTop
|
||||||
|
if (x > 0) {
|
||||||
|
val bodyScroll = min(x, verticalScroll)
|
||||||
|
verticalScroll -= bodyScroll
|
||||||
|
htmlBody.scrollBy(ScrollToOptions(0.0, bodyScroll, ScrollBehavior.INSTANT))
|
||||||
|
} else {
|
||||||
|
if (calendarTable.scrollTop + calendarTable.clientHeight + 5 >= calendarTable.scrollHeight) {
|
||||||
|
htmlBody.scrollBy(ScrollToOptions(0.0, verticalScroll, ScrollBehavior.INSTANT))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (verticalScroll < 0) {
|
||||||
|
val x = html.offsetTop - htmlBody.scrollTop
|
||||||
|
if (x < 0) {
|
||||||
|
val bodyScroll = max(x, verticalScroll)
|
||||||
|
verticalScroll -= bodyScroll
|
||||||
|
htmlBody.scrollBy(ScrollToOptions(0.0, bodyScroll, ScrollBehavior.INSTANT))
|
||||||
|
} else {
|
||||||
|
if (calendarTable.scrollTop == 0.0) {
|
||||||
|
htmlBody.scrollBy(ScrollToOptions(0.0, verticalScroll, ScrollBehavior.INSTANT))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
scrollHorizontalBy(it.deltaX * multiplier, ScrollBehavior.INSTANT)
|
scrollHorizontalBy(it.deltaX * multiplier, ScrollBehavior.INSTANT)
|
||||||
scrollVerticalBy(it.deltaY * multiplier, ScrollBehavior.INSTANT)
|
scrollVerticalBy(verticalScroll, ScrollBehavior.INSTANT)
|
||||||
|
|
||||||
it.preventDefault()
|
it.preventDefault()
|
||||||
}
|
}
|
||||||
|
|
|
@ -174,7 +174,8 @@ class CalendarEntry(private val calendar: CalendarBody, view: HTMLElement) : Vie
|
||||||
|
|
||||||
init {
|
init {
|
||||||
onMouseDown { event ->
|
onMouseDown { event ->
|
||||||
if (!editable || event.target != html || "pending" in classList) {
|
val isValidTarget = event.target == html || event.target == nameView
|
||||||
|
if (!editable || !isValidTarget || "pending" in classList) {
|
||||||
event.stopPropagation()
|
event.stopPropagation()
|
||||||
return@onMouseDown
|
return@onMouseDown
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue