Compare commits

...

2 commits

Author SHA1 Message Date
Lars Westermann 4aeb97a79e
Fix scroll in calendar edit list 2019-06-11 18:19:44 +02:00
Lars Westermann 6d6deaeac1
Improve calendar scolling 2019-06-11 18:07:57 +02:00
3 changed files with 38 additions and 2 deletions

View file

@ -10,6 +10,9 @@ import org.w3c.dom.*
import kotlin.browser.document
import kotlin.browser.window
import kotlin.js.Date
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min
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
private val calendarTableHeader = calendar.getElementsByClassName("calendar-header")[0] as HTMLElement
val htmlBody = document.body ?: createHtmlView()
val day = calendarTable.dataset["day"]?.toIntOrNull() ?: -1
val referenceDate = calendarTable.dataset["reference"]?.toLongOrNull() ?: -1L
val nowDate = calendarTable.dataset["now"]?.toLongOrNull() ?: -1L
@ -111,8 +116,34 @@ class Calendar(calendar: HTMLElement) : View(calendar) {
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)
scrollVerticalBy(it.deltaY * multiplier, ScrollBehavior.INSTANT)
scrollVerticalBy(verticalScroll, ScrollBehavior.INSTANT)
it.preventDefault()
}

View file

@ -60,6 +60,10 @@ class CalendarEdit(
}
}
onWheel {
it.stopPropagation()
}
WorkGroupRepository.onCreate {
if (loaded) {
launch {

View file

@ -174,7 +174,8 @@ class CalendarEntry(private val calendar: CalendarBody, view: HTMLElement) : Vie
init {
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()
return@onMouseDown
}