summaryrefslogtreecommitdiff
path: root/src/scripts/scroll.js
blob: c23e2f2d604107493c733a8935df6ae076e00848 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
function vbscroll(mode, scrollStep, count) {
    var w = window,
        d = document,
        x = y = 0,
        ph = w.innerHeight,
        c = count||1,
        rel = true;
    switch (mode) {
        case 'j':
            y = c * scrollStep;
            break;
        case 'h':
            x = -c * scrollStep;
            break;
        case 'k':
            y = -c * scrollStep;
            break;
        case 'l':
            x = c * scrollStep;
            break;
        case 'd':
            y = c * ph / 2;
            break;
        case 'u':
            y = -c * ph / 2;
            break;
        case '\x06': /* ^F */
            y = c * ph;
            break;
        case '\x02': /* ^B */
            y = -c * ph;
            break;
        case 'G': /* fall through - gg and G differ only in y value when no count is given */
        case 'g':
            x = w.scrollX;
            if (count) {
                y = c * ((d.documentElement.scrollHeight - w.innerHeight) / 100);
            } else {
                y = 'G' == mode ? d.body.scrollHeight : 0;
            }
            rel = false;
            break;
        case '0':
            y   = w.scrollY;
            rel = false;
            break;
        case '$':
            x   = d.body.scrollWidth;
            y   = w.scrollY;
            rel = false;
            break;
        default:
            return 1;
    }
    if (rel) {
        w.scrollBy(x, y);
    } else {
        w.scroll(x, y);
    }
    return 0;
}