mirror of
https://github.com/Redocly/redoc.git
synced 2025-01-31 18:14:07 +03:00
Fix side menu items wrong sync with description headers
This commit is contained in:
parent
9955cb8fec
commit
ca654511ae
|
@ -41,9 +41,14 @@ export class MenuService {
|
|||
let $activeMethodHost = this.getCurrentMethodEl();
|
||||
if (!$activeMethodHost) return;
|
||||
var elementInViewPos = this.scrollService.getElementPos($activeMethodHost);
|
||||
if(isScrolledDown && elementInViewPos === INVIEW_POSITION.BELLOW) {
|
||||
stable = this.changeActive(CHANGE.NEXT);
|
||||
continue;
|
||||
if(isScrolledDown) {
|
||||
//&& elementInViewPos === INVIEW_POSITION.BELLOW
|
||||
let $nextEl = this.getRelativeCatOrItem(1);
|
||||
let nextInViewPos = this.scrollService.getElementPos($nextEl, true);
|
||||
if (elementInViewPos === INVIEW_POSITION.BELLOW && nextInViewPos === INVIEW_POSITION.ABOVE) {
|
||||
stable = this.changeActive(CHANGE.NEXT);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if(!isScrolledDown && elementInViewPos === INVIEW_POSITION.ABOVE ) {
|
||||
stable = this.changeActive(CHANGE.BACK);
|
||||
|
@ -53,6 +58,25 @@ export class MenuService {
|
|||
}
|
||||
}
|
||||
|
||||
getRelativeCatOrItem(offset: number = 0) {
|
||||
let ptr, cat;
|
||||
cat = this.categories[this.activeCatIdx];
|
||||
if (cat.methods.length === 0) {
|
||||
ptr = null;
|
||||
cat = this.categories[this.activeCatIdx + Math.sign(offset)] || cat;
|
||||
} else {
|
||||
let cat = this.categories[this.activeCatIdx];
|
||||
let idx = this.activeMethodIdx + offset;
|
||||
if ((idx >= cat.methods.length - 1) || idx < 0) {
|
||||
cat = this.categories[this.activeCatIdx + Math.sign(offset)] || cat;
|
||||
idx = offset > 0 ? -1 : cat.methods.length - 1;
|
||||
}
|
||||
ptr = cat.methods[idx] && cat.methods[idx].pointer;
|
||||
}
|
||||
|
||||
return this.getMethodElByPtr(ptr, cat.id);
|
||||
}
|
||||
|
||||
getCurrentMethodEl() {
|
||||
return this.getMethodElByPtr(this.activeMethodPtr,
|
||||
this.categories[this.activeCatIdx].id);
|
||||
|
|
|
@ -14,6 +14,7 @@ export interface MenuMethod {
|
|||
active: boolean;
|
||||
summary: string;
|
||||
tag: string;
|
||||
pointer: string;
|
||||
}
|
||||
|
||||
export interface MenuCategory {
|
||||
|
|
|
@ -29,13 +29,14 @@ export class ScrollService {
|
|||
}
|
||||
|
||||
/* returns 1 if element if above the view, 0 if in view and -1 below the view */
|
||||
getElementPos($el) {
|
||||
getElementPos($el, inverted=false) {
|
||||
let scrollYOffset = this.scrollYOffset();
|
||||
if (Math.floor($el.getBoundingClientRect().top) > scrollYOffset) {
|
||||
let mul = inverted ? -1 : 1;
|
||||
if (mul*Math.floor($el.getBoundingClientRect().top) > mul*scrollYOffset) {
|
||||
return INVIEW_POSITION.ABOVE;
|
||||
}
|
||||
|
||||
if ($el.getBoundingClientRect().bottom <= scrollYOffset) {
|
||||
if (mul*$el.getBoundingClientRect().bottom <= mul*scrollYOffset) {
|
||||
return INVIEW_POSITION.BELLOW;
|
||||
}
|
||||
return INVIEW_POSITION.INVIEW;
|
||||
|
|
Loading…
Reference in New Issue
Block a user