(path)
| 31 | } |
| 32 | |
| 33 | function highlight(path) { |
| 34 | if (!enableScrollEvent) { |
| 35 | return; |
| 36 | } |
| 37 | |
| 38 | const sidebar = dom.getNode('.sidebar'); |
| 39 | const anchors = dom.findAll('.anchor'); |
| 40 | const wrap = dom.find(sidebar, '.sidebar-nav'); |
| 41 | let active = dom.find(sidebar, 'li.active'); |
| 42 | const doc = document.documentElement; |
| 43 | const top = ((doc && doc.scrollTop) || document.body.scrollTop) - coverHeight; |
| 44 | let last; |
| 45 | |
| 46 | for (let i = 0, len = anchors.length; i < len; i += 1) { |
| 47 | const node = anchors[i]; |
| 48 | |
| 49 | if (node.offsetTop > top) { |
| 50 | if (!last) { |
| 51 | last = node; |
| 52 | } |
| 53 | |
| 54 | break; |
| 55 | } else { |
| 56 | last = node; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | if (!last) { |
| 61 | return; |
| 62 | } |
| 63 | |
| 64 | const li = nav[getNavKey(path, last.getAttribute('data-id'))]; |
| 65 | |
| 66 | if (!li || li === active) { |
| 67 | return; |
| 68 | } |
| 69 | |
| 70 | active && active.classList.remove('active'); |
| 71 | li.classList.add('active'); |
| 72 | active = li; |
| 73 | |
| 74 | // Scroll into view |
| 75 | // https://github.com/vuejs/vuejs.org/blob/master/themes/vue/source/js/common.js#L282-L297 |
| 76 | if (!hoverOver && dom.body.classList.contains('sticky')) { |
| 77 | const height = sidebar.clientHeight; |
| 78 | const curOffset = 0; |
| 79 | const cur = active.offsetTop + active.clientHeight + 40; |
| 80 | const isInView = |
| 81 | active.offsetTop >= wrap.scrollTop && cur <= wrap.scrollTop + height; |
| 82 | const notThan = cur - curOffset < height; |
| 83 | |
| 84 | sidebar.scrollTop = isInView |
| 85 | ? wrap.scrollTop |
| 86 | : notThan |
| 87 | ? curOffset |
| 88 | : cur - height; |
| 89 | } |
| 90 | } |
no test coverage detected
searching dependent graphs…