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

Function getAndActive

src/core/event/sidebar.js:73–106  ·  view source on GitHub ↗
(router, el, isParent, autoTitle)

Source from the content-addressed store, hash-verified

71 * @return {Element} Active element
72 */
73export function getAndActive(router, el, isParent, autoTitle) {
74 el = dom.getNode(el);
75 let links = [];
76 if (el !== null && el !== undefined) {
77 links = dom.findAll(el, 'a');
78 }
79
80 const hash = decodeURI(router.toURL(router.getCurrentPath()));
81 let target;
82
83 links
84 .sort((a, b) => b.href.length - a.href.length)
85 .forEach(a => {
86 const href = decodeURI(a.getAttribute('href'));
87 const node = isParent ? a.parentNode : a;
88
89 a.title = a.title || a.innerText;
90
91 if (hash.indexOf(href) === 0 && !target) {
92 target = a;
93 dom.toggleClass(node, 'add', 'active');
94 } else {
95 dom.toggleClass(node, 'remove', 'active');
96 }
97 });
98
99 if (autoTitle) {
100 dom.$.title = target
101 ? target.title || `${target.innerText} - ${title}`
102 : title;
103 }
104
105 return target;
106}

Callers 3

initFetchMethod · 0.90
_renderSidebarMethod · 0.90
_renderNavMethod · 0.90

Calls 2

toURLMethod · 0.45
getCurrentPathMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…