MCPcopy
hub / github.com/docsifyjs/docsify / scrollActiveSidebar

Function scrollActiveSidebar

src/core/event/scroll.js:96–143  ·  view source on GitHub ↗
(router)

Source from the content-addressed store, hash-verified

94}
95
96export function scrollActiveSidebar(router) {
97 const cover = dom.find('.cover.show');
98 coverHeight = cover ? cover.offsetHeight : 0;
99
100 const sidebar = dom.getNode('.sidebar');
101 let lis = [];
102 if (sidebar !== null && sidebar !== undefined) {
103 lis = dom.findAll(sidebar, 'li');
104 }
105
106 for (let i = 0, len = lis.length; i < len; i += 1) {
107 const li = lis[i];
108 const a = li.querySelector('a');
109 if (!a) {
110 continue;
111 }
112
113 let href = a.getAttribute('href');
114
115 if (href !== '/') {
116 const {
117 query: { id },
118 path,
119 } = router.parse(href);
120 if (id) {
121 href = getNavKey(path, id);
122 }
123 }
124
125 if (href) {
126 nav[decodeURIComponent(href)] = li;
127 }
128 }
129
130 if (isMobile) {
131 return;
132 }
133
134 const path = removeParams(router.getCurrentPath());
135 dom.off('scroll', () => highlight(path));
136 dom.on('scroll', () => highlight(path));
137 dom.on(sidebar, 'mouseover', () => {
138 hoverOver = true;
139 });
140 dom.on(sidebar, 'mouseleave', () => {
141 hoverOver = false;
142 });
143}
144
145export function scrollIntoView(path, id) {
146 if (!id) {

Callers 1

_bindEventOnRenderedMethod · 0.90

Calls 4

getNavKeyFunction · 0.85
highlightFunction · 0.85
parseMethod · 0.45
getCurrentPathMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…