mirror of
https://github.com/Redocly/redoc.git
synced 2025-07-29 09:29:57 +03:00
Merge pull request #5 from sofico-global/fiva/winEventScroll
feat: add listening for redocUpdatePosition event on window to update…
This commit is contained in:
commit
21279e1d9f
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "redoc",
|
||||
"version": "2.0.0-0.2.0",
|
||||
"version": "2.0.0-0.2.1",
|
||||
"description": "ReDoc",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
|
|
@ -58,6 +58,8 @@ export class AppStore {
|
|||
private scroll: ScrollService;
|
||||
private disposer: Lambda | null = null;
|
||||
|
||||
private readonly listener: EventListenerOrEventListenerObject = this.updateOnEvent.bind(this);
|
||||
|
||||
constructor(
|
||||
spec: OpenAPISpec,
|
||||
specUrl?: string,
|
||||
|
@ -73,7 +75,7 @@ export class AppStore {
|
|||
MenuStore.updateOnHistory(this.history.currentId, this.scroll);
|
||||
|
||||
// Listen for external event to update
|
||||
window.addEventListener('redocUpdatePosition', this.updateOnEvent);
|
||||
window.addEventListener('redocUpdatePosition', this.listener);
|
||||
|
||||
// override the openApi standard to version 3.1.0
|
||||
// TODO remove when fully supporting open API 3.1.0
|
||||
|
@ -101,7 +103,7 @@ export class AppStore {
|
|||
dispose() {
|
||||
this.scroll.dispose();
|
||||
this.menu.dispose();
|
||||
window.removeEventListener('redocUpdatePosition', this.updateOnEvent);
|
||||
window.removeEventListener('redocUpdatePosition', this.listener);
|
||||
if (this.search) {
|
||||
this.search.dispose();
|
||||
}
|
||||
|
@ -129,10 +131,6 @@ export class AppStore {
|
|||
};
|
||||
}
|
||||
|
||||
private updateOnEvent(): void {
|
||||
MenuStore.updateOnHistory(this.history.currentId, this.scroll);
|
||||
}
|
||||
|
||||
private updateMarkOnMenu(idx: number) {
|
||||
const start = Math.max(0, idx);
|
||||
const end = Math.min(this.menu.flatItems.length, start + 5);
|
||||
|
@ -157,6 +155,10 @@ export class AppStore {
|
|||
this.marker.addOnly(elements);
|
||||
this.marker.mark();
|
||||
}
|
||||
|
||||
private updateOnEvent(): void {
|
||||
MenuStore.updateOnHistory(this.history.currentId, this.scroll);
|
||||
}
|
||||
}
|
||||
|
||||
const DEFAULT_OPTIONS: RedocRawOptions = {
|
||||
|
|
Loading…
Reference in New Issue
Block a user