|
|
@ -8,6 +8,7 @@ export default class Follow { |
|
|
|
this.doc = doc; |
|
|
|
this.doc = doc; |
|
|
|
this.hintElements = {}; |
|
|
|
this.hintElements = {}; |
|
|
|
this.keys = []; |
|
|
|
this.keys = []; |
|
|
|
|
|
|
|
this.onActivatedCallbacks = []; |
|
|
|
|
|
|
|
|
|
|
|
// TODO activate input elements and push button elements
|
|
|
|
// TODO activate input elements and push button elements
|
|
|
|
let links = Follow.getTargetElements(doc); |
|
|
|
let links = Follow.getTargetElements(doc); |
|
|
@ -36,7 +37,7 @@ export default class Follow { |
|
|
|
} else if (keyCode === KeyboardEvent.DOM_VK_ENTER || |
|
|
|
} else if (keyCode === KeyboardEvent.DOM_VK_ENTER || |
|
|
|
keyCode === KeyboardEvent.DOM_VK_RETURN) { |
|
|
|
keyCode === KeyboardEvent.DOM_VK_RETURN) { |
|
|
|
let chars = Follow.codeChars(this.keys); |
|
|
|
let chars = Follow.codeChars(this.keys); |
|
|
|
this.hintElements[chars].activate(); |
|
|
|
this.activate(this.hintElements[chars].target); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} else if (Follow.availableKey(keyCode)) { |
|
|
|
} else if (Follow.availableKey(keyCode)) { |
|
|
|
this.keys.push(keyCode); |
|
|
|
this.keys.push(keyCode); |
|
|
@ -64,7 +65,7 @@ export default class Follow { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} else if (shown.length === 1) { |
|
|
|
} else if (shown.length === 1) { |
|
|
|
this.remove(); |
|
|
|
this.remove(); |
|
|
|
this.hintElements[chars].activate(); |
|
|
|
this.activate(this.hintElements[chars].target); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
shown.forEach((key) => { |
|
|
|
shown.forEach((key) => { |
|
|
@ -75,7 +76,6 @@ export default class Follow { |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
remove() { |
|
|
|
remove() { |
|
|
|
this.doc.removeEventListener('keydown', this.boundKeydown); |
|
|
|
this.doc.removeEventListener('keydown', this.boundKeydown); |
|
|
|
Object.keys(this.hintElements).forEach((key) => { |
|
|
|
Object.keys(this.hintElements).forEach((key) => { |
|
|
@ -83,6 +83,14 @@ export default class Follow { |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
activate(element) { |
|
|
|
|
|
|
|
this.onActivatedCallbacks.forEach(f => f(element)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
onActivated(f) { |
|
|
|
|
|
|
|
this.onActivatedCallbacks.push(f); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static availableKey(keyCode) { |
|
|
|
static availableKey(keyCode) { |
|
|
|
return ( |
|
|
|
return ( |
|
|
|
KeyboardEvent.DOM_VK_0 <= keyCode && keyCode <= KeyboardEvent.DOM_VK_9 || |
|
|
|
KeyboardEvent.DOM_VK_0 <= keyCode && keyCode <= KeyboardEvent.DOM_VK_9 || |
|
|
|