(router, el, isParent, autoTitle)
| 71 | * @return {Element} Active element |
| 72 | */ |
| 73 | export 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 | } |
no test coverage detected
searching dependent graphs…