diff --git a/app/resources/views/logs/show.blade.php b/app/resources/views/logs/show.blade.php index 89a29ac..6f5ba6d 100644 --- a/app/resources/views/logs/show.blade.php +++ b/app/resources/views/logs/show.blade.php @@ -12,9 +12,6 @@ @push('page_styles') @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 $('
').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) + }) + } }