Total Complexity | 9 |
Complexity/F | 3 |
Lines of Code | 37 |
Function Count | 3 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | /* global anchors */ |
||
4 | anchors.options.placement = 'left'; |
||
5 | anchors.add().remove('.no-anchor'); |
||
6 | |||
7 | // Filter UI |
||
8 | var tocElements = document.getElementById('toc').getElementsByTagName('a'); |
||
9 | document.getElementById('filter-input').addEventListener('keyup', function(e) { |
||
10 | |||
11 | var i, element; |
||
12 | |||
13 | // enter key |
||
14 | if (e.keyCode === 13) { |
||
15 | // go to the first displayed item in the toc |
||
16 | for (i = 0; i < tocElements.length; i++) { |
||
17 | element = tocElements[i]; |
||
18 | if (!element.classList.contains('hide')) { |
||
19 | location.replace(element.href); |
||
20 | return e.preventDefault(); |
||
21 | } |
||
22 | } |
||
23 | } |
||
24 | |||
25 | var match = function() { return true; }, |
||
26 | value = this.value.toLowerCase(); |
||
27 | |||
28 | if (!value.match(/^\s*$/)) { |
||
29 | match = function(text) { return text.toLowerCase().indexOf(value) !== -1; }; |
||
30 | } |
||
31 | |||
32 | for (i = 0; i < tocElements.length; i++) { |
||
33 | element = tocElements[i]; |
||
34 | if (match(element.innerHTML)) { |
||
35 | element.classList.remove('hide'); |
||
36 | } else { |
||
37 | element.classList.add('hide'); |
||
38 | } |
||
39 | } |
||
40 | }); |
||
41 |