MCPcopy
hub / github.com/rapi-doc/RapiDoc / scrollToPath

Method scrollToPath

src/rapidoc.js:988–1044  ·  view source on GitHub ↗
(elementId, expandPath = true, scrollNavItemToView = true)

Source from the content-addressed store, hash-verified

986
987 // Public Method (scrolls to a given path and highlights the left-nav selection)
988 async scrollToPath(elementId, expandPath = true, scrollNavItemToView = true) {
989 if (this.renderStyle === 'focused') {
990 // for focused mode update this.focusedElementId to update the rendering, else it wont find the needed html elements
991 // focusedElementId will get validated in the template
992 this.focusedElementId = elementId;
993 await sleep(0);
994 }
995 if (this.renderStyle === 'view') {
996 this.expandAndGotoOperation(elementId, expandPath, true);
997 } else {
998 let isValidElementId = false;
999 const contentEl = this.shadowRoot.getElementById(elementId);
1000 if (contentEl) {
1001 isValidElementId = true;
1002 contentEl.scrollIntoView({ behavior: this.scrollBehavior, block: 'start' });
1003 } else {
1004 isValidElementId = false;
1005 }
1006 if (isValidElementId) {
1007 // for focused style it is important to reset request-body-selection and response selection which maintains the state for in case of multiple req-body or multiple response mime-type
1008 if (this.renderStyle === 'focused') {
1009 const requestEl = this.shadowRoot.querySelector('api-request');
1010 if (requestEl) {
1011 requestEl.afterNavigationFocusedMode();
1012 }
1013 const responseEl = this.shadowRoot.querySelector('api-response');
1014 if (responseEl) {
1015 responseEl.resetSelection();
1016 }
1017 }
1018
1019 // Update Location Hash
1020 if (this.updateRoute === 'true') {
1021 this.replaceHistoryState(elementId);
1022 }
1023
1024 // Update NavBar View and Styles
1025 const newNavEl = this.shadowRoot.getElementById(`link-${elementId}`);
1026
1027 if (newNavEl) {
1028 if (scrollNavItemToView) {
1029 newNavEl.scrollIntoView({ behavior: this.scrollBehavior, block: 'center' });
1030 }
1031 await sleep(0);
1032 const oldNavEl = this.shadowRoot.querySelector('.nav-bar-tag.active, .nav-bar-path.active, .nav-bar-info.active, .nav-bar-h1.active, .nav-bar-h2.active, .operations.active');
1033 if (oldNavEl) {
1034 oldNavEl.classList.remove('active');
1035 oldNavEl.part.remove('active');
1036 oldNavEl.part.remove('section-navbar-active-item');
1037 }
1038 newNavEl.classList.add('active'); // must add the class after scrolling
1039 newNavEl.part.add('section-navbar-active-item');
1040 // this.requestUpdate();
1041 }
1042 }
1043 }
1044 }
1045

Callers 4

connectedCallbackMethod · 0.95
scrollToEventTargetMethod · 0.95

Calls 7

replaceHistoryStateMethod · 0.95
sleepFunction · 0.90
resetSelectionMethod · 0.45
removeMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected