From 2777fdfd635acdcb0ec538a4988306d1658928e9 Mon Sep 17 00:00:00 2001 From: Sofia Papacharalampous Date: Mon, 1 Jul 2024 16:51:01 +0300 Subject: [PATCH] pause intersection observer on toc expand --- .../table-of-contents/table-of-contents.component.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dmp-frontend/src/app/ui/description/editor/table-of-contents/table-of-contents.component.ts b/dmp-frontend/src/app/ui/description/editor/table-of-contents/table-of-contents.component.ts index 25e451b5e..460a7777f 100644 --- a/dmp-frontend/src/app/ui/description/editor/table-of-contents/table-of-contents.component.ts +++ b/dmp-frontend/src/app/ui/description/editor/table-of-contents/table-of-contents.component.ts @@ -24,8 +24,9 @@ export class TableOfContentsComponent extends BaseComponent implements OnInit, O @Input() anchorFieldsetId: string; tocentries: ToCEntry[] = null; - + private _intersectionObserver: IntersectionObserver; + pauseIntersectionObserver: boolean = false; private _tocentrySelected: ToCEntry = null; get tocentrySelected() { @@ -152,7 +153,7 @@ export class TableOfContentsComponent extends BaseComponent implements OnInit, O debounceTime(300), distinctUntilChanged(), ).subscribe(x => { - if (x.isIntersecting) { + if (x.isIntersecting && !this.pauseIntersectionObserver) { const target_id = x.target.id; if (this._isVisible(target_id)) { this.tocentrySelected = TableOfContentsComponent._findTocEntryById(target_id, this.tocentries); @@ -337,8 +338,10 @@ export class TableOfContentsComponent extends BaseComponent implements OnInit, O } onToCentrySelected(entry: ToCEntry = null, execute: boolean = true) { + this.pauseIntersectionObserver = true; this.tocentrySelected = entry; this.entrySelected.emit({ entry: entry, execute: execute }); + setTimeout(() => this.pauseIntersectionObserver = false, 1000); } /**