Completed
Pull Request — master (#72)
by Matt
06:06
created

public/js/keyboard_nav.js   A

Complexity

Total Complexity 6
Complexity/F 3

Size

Lines of Code 28
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 22
mnd 4
bc 4
fnc 2
dl 0
loc 28
rs 10
bpm 2
cpm 3
noi 0
c 0
b 0
f 0
1
$(function() {
2
    window.addEventListener("keydown", function (event) {
3
        if (event.defaultPrevented) {
4
            return; // Do nothing if the event was already processed
5
        }
6
        var url;
7
        switch (event.key) {
8
            case "Left": // IE/Edge specific value
9
            case "ArrowLeft":
10
                url = $("#navigatePrev").attr('href');
11
                if (url) {
12
                    window.location.href = url;
13
                }
14
            break;
15
            case "Right": // IE/Edge specific value
16
            case "ArrowRight":
17
                url = $("#navigateNext").attr('href');
18
            break;
19
            default:
20
            return; // Quit when this doesn't handle the key event.
21
        }
22
        if (url) {
23
            window.location.href = url;
24
        }
25
        // Cancel the default action to avoid it being handled twice
26
        event.preventDefault();
27
        }, true);
28
});
29