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,10 +41,15 @@ export class MenuService {
|
||||||
let $activeMethodHost = this.getCurrentMethodEl();
|
let $activeMethodHost = this.getCurrentMethodEl();
|
||||||
if (!$activeMethodHost) return;
|
if (!$activeMethodHost) return;
|
||||||
var elementInViewPos = this.scrollService.getElementPos($activeMethodHost);
|
var elementInViewPos = this.scrollService.getElementPos($activeMethodHost);
|
||||||
if(isScrolledDown && elementInViewPos === INVIEW_POSITION.BELLOW) {
|
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);
|
stable = this.changeActive(CHANGE.NEXT);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if(!isScrolledDown && elementInViewPos === INVIEW_POSITION.ABOVE ) {
|
if(!isScrolledDown && elementInViewPos === INVIEW_POSITION.ABOVE ) {
|
||||||
stable = this.changeActive(CHANGE.BACK);
|
stable = this.changeActive(CHANGE.BACK);
|
||||||
continue;
|
continue;
|
||||||
|
@ -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() {
|
getCurrentMethodEl() {
|
||||||
return this.getMethodElByPtr(this.activeMethodPtr,
|
return this.getMethodElByPtr(this.activeMethodPtr,
|
||||||
this.categories[this.activeCatIdx].id);
|
this.categories[this.activeCatIdx].id);
|
||||||
|
|
|
@ -14,6 +14,7 @@ export interface MenuMethod {
|
||||||
active: boolean;
|
active: boolean;
|
||||||
summary: string;
|
summary: string;
|
||||||
tag: string;
|
tag: string;
|
||||||
|
pointer: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface MenuCategory {
|
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 */
|
/* 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();
|
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;
|
return INVIEW_POSITION.ABOVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($el.getBoundingClientRect().bottom <= scrollYOffset) {
|
if (mul*$el.getBoundingClientRect().bottom <= mul*scrollYOffset) {
|
||||||
return INVIEW_POSITION.BELLOW;
|
return INVIEW_POSITION.BELLOW;
|
||||||
}
|
}
|
||||||
return INVIEW_POSITION.INVIEW;
|
return INVIEW_POSITION.INVIEW;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user