open link on content index
This commit is contained in:
parent
59a28d0b44
commit
655ac16f38
3 changed files with 19 additions and 10 deletions
|
@ -8,6 +8,7 @@ export default class Follow {
|
|||
this.doc = doc;
|
||||
this.hintElements = {};
|
||||
this.keys = [];
|
||||
this.onActivatedCallbacks = [];
|
||||
|
||||
// TODO activate input elements and push button elements
|
||||
let links = Follow.getTargetElements(doc);
|
||||
|
@ -36,7 +37,7 @@ export default class Follow {
|
|||
} else if (keyCode === KeyboardEvent.DOM_VK_ENTER ||
|
||||
keyCode === KeyboardEvent.DOM_VK_RETURN) {
|
||||
let chars = Follow.codeChars(this.keys);
|
||||
this.hintElements[chars].activate();
|
||||
this.activate(this.hintElements[chars].target);
|
||||
return;
|
||||
} else if (Follow.availableKey(keyCode)) {
|
||||
this.keys.push(keyCode);
|
||||
|
@ -64,7 +65,7 @@ export default class Follow {
|
|||
return;
|
||||
} else if (shown.length === 1) {
|
||||
this.remove();
|
||||
this.hintElements[chars].activate();
|
||||
this.activate(this.hintElements[chars].target);
|
||||
}
|
||||
|
||||
shown.forEach((key) => {
|
||||
|
@ -75,7 +76,6 @@ export default class Follow {
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
remove() {
|
||||
this.doc.removeEventListener('keydown', this.boundKeydown);
|
||||
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) {
|
||||
return (
|
||||
KeyboardEvent.DOM_VK_0 <= keyCode && keyCode <= KeyboardEvent.DOM_VK_9 ||
|
||||
|
|
|
@ -33,10 +33,4 @@ export default class Hint {
|
|||
remove() {
|
||||
this.element.remove();
|
||||
}
|
||||
|
||||
activate() {
|
||||
if (this.target.tagName.toLowerCase() === 'a') {
|
||||
this.target.click();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,13 @@ import messages from '../messages';
|
|||
|
||||
consoleFrames.initialize(window.document);
|
||||
|
||||
const startFollows = (newTab) => {
|
||||
let follow = new Follow(window.document, newTab);
|
||||
follow.onActivated((element) => {
|
||||
element.click();
|
||||
});
|
||||
};
|
||||
|
||||
window.addEventListener('keypress', (e) => {
|
||||
if (e.target instanceof HTMLInputElement) {
|
||||
return;
|
||||
|
@ -34,7 +41,7 @@ const execOperation = (operation) => {
|
|||
case operations.SCROLL_RIGHT:
|
||||
return scrolls.scrollRight(window);
|
||||
case operations.FOLLOW_START:
|
||||
return new Follow(window.document, operation.newTab);
|
||||
return startFollows(operation.newTab);
|
||||
case operations.NAVIGATE_HISTORY_PREV:
|
||||
return navigates.historyPrev(window);
|
||||
case operations.NAVIGATE_HISTORY_NEXT:
|
||||
|
|
Reference in a new issue