Fixed observer

This commit is contained in:
2023-05-19 12:27:17 -04:00
parent 806d1be9cf
commit 4b82650fe8

View File

@ -12,9 +12,6 @@
@push('page_styles')
<style>
body {overflow-y:scroll;}
{{--@foreach ($levels as $level => $colors)
.{{$level}} {background-color: {{$colors->background}}; color: {{$colors->text}};}
@endforeach--}}
</style>
@endpush
@ -88,7 +85,7 @@
if (this.total > 0 && this.remaining <= 0) {
return
}
$.ajax({
return $.ajax({
url: '{{$urls->base}}/log/{{urlencode($log->getFilename())}}/more/' + start + '/' + amount
}).then(response => {
if (response.logs) {
@ -97,7 +94,6 @@
}
this.remaining -= response.logs.length
this.start += response.logs.length
console.debug(this.total, this.remaining)
this.draw().more(response.logs)
}
})
@ -115,6 +111,7 @@
}
this.draw().unparsed(parent, log)
})
this.draw().markLast(parent)
},
title: () => {
return $('<div></div>').addClass('title')
@ -174,17 +171,38 @@
}
content.append(card)
parent.append(title).append(content)
},
markLast: parent => {
const children = parent.children('.title')
children.removeClass('watch')
$(children[children.length - 1]).addClass('watch')
}
}
},
watch: function() {
return {
more: payload => {
if (payload[0].isIntersecting) {
if (payload[0].rootBounds.bottom !== this.watch_pos) {
this.get().more(this.start, this.amount)
rewatch: observer => {
const watch = document.querySelector('.watch')
observer.observe(watch)
},
more: (entries, observer) => {
entries.forEach(payload => {
if (!$(payload.target).hasClass('watch')) {
return
}
}
if (payload.intersectionRatio > 0) {
if (payload.rootBounds.bottom !== this.watch_pos) {
try {
this.get().more(this.start, this.amount).then(response => {
this.watch().rewatch(observer)
})
} catch (e) {
observer.disconnect()
}
}
}
})
}
}
},
@ -192,9 +210,11 @@
this.id = id
$(this.get().id()).accordion()
const ob = new IntersectionObserver(this.watch().more)
const watch = document.querySelector('#watch')
ob.observe(watch)
this.get().more(this.start, this.amount).then(response => {
const ob = new IntersectionObserver(this.watch().more)
this.watch().rewatch(ob)
})
}
}