1 |
|
2 | var jumpToCode = (function init() {
|
3 |
|
4 | var missingCoverageClasses = ['.cbranch-no', '.cstat-no', '.fstat-no'];
|
5 |
|
6 |
|
7 | var fileListingElements = ['td.pct.low'];
|
8 |
|
9 |
|
10 | var notSelector = ':not(' + missingCoverageClasses.join('):not(') + ') > ';
|
11 |
|
12 |
|
13 | var selector =
|
14 | fileListingElements.join(', ') +
|
15 | ', ' +
|
16 | notSelector +
|
17 | missingCoverageClasses.join(', ' + notSelector);
|
18 |
|
19 |
|
20 | var missingCoverageElements = document.querySelectorAll(selector);
|
21 |
|
22 | var currentIndex;
|
23 |
|
24 | function toggleClass(index) {
|
25 | missingCoverageElements
|
26 | .item(currentIndex)
|
27 | .classList.remove('highlighted');
|
28 | missingCoverageElements.item(index).classList.add('highlighted');
|
29 | }
|
30 |
|
31 | function makeCurrent(index) {
|
32 | toggleClass(index);
|
33 | currentIndex = index;
|
34 | missingCoverageElements.item(index).scrollIntoView({
|
35 | behavior: 'smooth',
|
36 | block: 'center',
|
37 | inline: 'center'
|
38 | });
|
39 | }
|
40 |
|
41 | function goToPrevious() {
|
42 | var nextIndex = 0;
|
43 | if (typeof currentIndex !== 'number' || currentIndex === 0) {
|
44 | nextIndex = missingCoverageElements.length - 1;
|
45 | } else if (missingCoverageElements.length > 1) {
|
46 | nextIndex = currentIndex - 1;
|
47 | }
|
48 |
|
49 | makeCurrent(nextIndex);
|
50 | }
|
51 |
|
52 | function goToNext() {
|
53 | var nextIndex = 0;
|
54 |
|
55 | if (
|
56 | typeof currentIndex === 'number' &&
|
57 | currentIndex < missingCoverageElements.length - 1
|
58 | ) {
|
59 | nextIndex = currentIndex + 1;
|
60 | }
|
61 |
|
62 | makeCurrent(nextIndex);
|
63 | }
|
64 |
|
65 | return function jump(event) {
|
66 | switch (event.which) {
|
67 | case 78:
|
68 | case 74:
|
69 | goToNext();
|
70 | break;
|
71 | case 66:
|
72 | case 75:
|
73 | case 80:
|
74 | goToPrevious();
|
75 | break;
|
76 | }
|
77 | };
|
78 | })();
|
79 | window.addEventListener('keydown', jumpToCode);
|