Fixed observer
This commit is contained in:
@ -12,9 +12,6 @@
|
|||||||
@push('page_styles')
|
@push('page_styles')
|
||||||
<style>
|
<style>
|
||||||
body {overflow-y:scroll;}
|
body {overflow-y:scroll;}
|
||||||
{{--@foreach ($levels as $level => $colors)
|
|
||||||
.{{$level}} {background-color: {{$colors->background}}; color: {{$colors->text}};}
|
|
||||||
@endforeach--}}
|
|
||||||
</style>
|
</style>
|
||||||
@endpush
|
@endpush
|
||||||
|
|
||||||
@ -88,7 +85,7 @@
|
|||||||
if (this.total > 0 && this.remaining <= 0) {
|
if (this.total > 0 && this.remaining <= 0) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
$.ajax({
|
return $.ajax({
|
||||||
url: '{{$urls->base}}/log/{{urlencode($log->getFilename())}}/more/' + start + '/' + amount
|
url: '{{$urls->base}}/log/{{urlencode($log->getFilename())}}/more/' + start + '/' + amount
|
||||||
}).then(response => {
|
}).then(response => {
|
||||||
if (response.logs) {
|
if (response.logs) {
|
||||||
@ -97,7 +94,6 @@
|
|||||||
}
|
}
|
||||||
this.remaining -= response.logs.length
|
this.remaining -= response.logs.length
|
||||||
this.start += response.logs.length
|
this.start += response.logs.length
|
||||||
console.debug(this.total, this.remaining)
|
|
||||||
this.draw().more(response.logs)
|
this.draw().more(response.logs)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -115,6 +111,7 @@
|
|||||||
}
|
}
|
||||||
this.draw().unparsed(parent, log)
|
this.draw().unparsed(parent, log)
|
||||||
})
|
})
|
||||||
|
this.draw().markLast(parent)
|
||||||
},
|
},
|
||||||
title: () => {
|
title: () => {
|
||||||
return $('<div></div>').addClass('title')
|
return $('<div></div>').addClass('title')
|
||||||
@ -174,17 +171,38 @@
|
|||||||
}
|
}
|
||||||
content.append(card)
|
content.append(card)
|
||||||
parent.append(title).append(content)
|
parent.append(title).append(content)
|
||||||
|
},
|
||||||
|
markLast: parent => {
|
||||||
|
const children = parent.children('.title')
|
||||||
|
children.removeClass('watch')
|
||||||
|
$(children[children.length - 1]).addClass('watch')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: function() {
|
watch: function() {
|
||||||
return {
|
return {
|
||||||
more: payload => {
|
rewatch: observer => {
|
||||||
if (payload[0].isIntersecting) {
|
const watch = document.querySelector('.watch')
|
||||||
if (payload[0].rootBounds.bottom !== this.watch_pos) {
|
observer.observe(watch)
|
||||||
this.get().more(this.start, this.amount)
|
},
|
||||||
|
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.id = id
|
||||||
$(this.get().id()).accordion()
|
$(this.get().id()).accordion()
|
||||||
|
|
||||||
const ob = new IntersectionObserver(this.watch().more)
|
this.get().more(this.start, this.amount).then(response => {
|
||||||
const watch = document.querySelector('#watch')
|
const ob = new IntersectionObserver(this.watch().more)
|
||||||
ob.observe(watch)
|
this.watch().rewatch(ob)
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user