-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgoodScrollManager.js
44 lines (37 loc) · 1.81 KB
/
goodScrollManager.js
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
/*
* (c) Eric Mink, [email protected], 2019
*
* This file is an example how to use Brotkeys.js for handling scrolling with the J and K keys.
* It contains some additional code in comparison to badScrollManager.js that makes it less tedious to use.
*/
var manager;
var wordMap = new Map([]);
// these single characters that can interrupt at any time during the word-typing mode
var interruptMap = new Map([
["D", function(){console.log("user disabled shortcuts"); manager.disable(); manager.leave_f_mode();}],
]);
// Make sure the manager does not use j and k (case-insensitive), using the optional third argument to the HotkeyManager constructor.
let ignoredKeys = ['k', 'J']
manager = new HotkeyManager(wordMap, interruptMap, ignoredKeys);
manager.interrupt_caseInsensitivity = false;
// please notify me on entering and leaving fmode simply by showing the link hints
// this is the simplest way to do this. for other options, see the examples in brotkeys.js#brotkeys_autogenerate_manager_for_anchors and brotkeys.js#brotkeys_autogenerate_manager_for_class_tag
var notifyFModeFunc = manager.genToggleKeysOnNotify(); // returns a function
manager.setNotifyFModeFunction(notifyFModeFunc); // takes the function as callback for when FMode is triggered
manager.log_prefix = "[Scrolling Brotkeys Manager] "; // optional prefix for logging to the console
// add a link hint to every anchor tag (<a/>)
manager.autogenerate(manager.GenerationEnum.tag_anchor);
// add a link hint to every element with css class "linkhintgen"
manager.autogenerate(manager.GenerationEnum.class_tagged, "linkhintgen", undefined);
// set up scrolling on j and k
function handleKeyDown(e){
// j
if (e.keyCode==74) {
window.scrollBy(0, 50);
}
// k
if (e.keyCode==75){
window.scrollBy(0,-50);
}
}
$(document).keydown(handleKeyDown);