aboutsummaryrefslogtreecommitdiff
path: root/src/content/components/common/follow.js
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2018-05-01 15:51:40 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2018-05-01 15:51:40 +0900
commit9da2f5fd786ff7ef64eca0a86efb1c0b9a164244 (patch)
treeb888349817d0016dc1499932671bbe6cd95efdaa /src/content/components/common/follow.js
parentf9889b7f2b634bfe5a540633d8952f4a6f900658 (diff)
parent89d6afecfd257ff4fc62748f771abf37ef3a2852 (diff)
Merge remote-tracking branch 'origin/master' into patch-1
Diffstat (limited to 'src/content/components/common/follow.js')
-rw-r--r--src/content/components/common/follow.js28
1 files changed, 25 insertions, 3 deletions
diff --git a/src/content/components/common/follow.js b/src/content/components/common/follow.js
index 7a35105..2a55ea3 100644
--- a/src/content/components/common/follow.js
+++ b/src/content/components/common/follow.js
@@ -4,7 +4,8 @@ import * as dom from 'shared/utils/dom';
const TARGET_SELECTOR = [
'a', 'button', 'input', 'textarea', 'area',
- '[contenteditable=true]', '[contenteditable=""]', '[tabindex]'
+ '[contenteditable=true]', '[contenteditable=""]', '[tabindex]',
+ '[role="button"]'
].join(',');
@@ -29,11 +30,27 @@ const inViewport = (win, element, viewSize, framePosition) => {
return true;
};
+const isAriaHiddenOrAriaDisabled = (win, element) => {
+ if (!element || win.document.documentElement === element) {
+ return false;
+ }
+ for (let attr of ['aria-hidden', 'aria-disabled']) {
+ if (element.hasAttribute(attr)) {
+ let hidden = element.getAttribute(attr).toLowerCase();
+ if (hidden === '' || hidden === 'true') {
+ return true;
+ }
+ }
+ }
+ return isAriaHiddenOrAriaDisabled(win, element.parentNode);
+};
+
export default class Follow {
constructor(win, store) {
this.win = win;
this.store = store;
this.newTab = false;
+ this.background = false;
this.hints = {};
this.targets = [];
@@ -47,6 +64,7 @@ export default class Follow {
this.win.parent.postMessage(JSON.stringify({
type: messages.FOLLOW_KEY_PRESS,
key: key.key,
+ ctrlKey: key.ctrlKey,
}), '*');
return true;
}
@@ -68,6 +86,7 @@ export default class Follow {
type: messages.OPEN_URL,
url: element.href,
newTab: true,
+ background: this.background,
});
}
@@ -79,12 +98,13 @@ export default class Follow {
}), '*');
}
- createHints(keysArray, newTab) {
+ createHints(keysArray, newTab, background) {
if (keysArray.length !== this.targets.length) {
throw new Error('illegal hint count');
}
this.newTab = newTab;
+ this.background = background;
this.hints = {};
for (let i = 0; i < keysArray.length; ++i) {
let keys = keysArray[i];
@@ -150,7 +170,8 @@ export default class Follow {
case messages.FOLLOW_REQUEST_COUNT_TARGETS:
return this.countHints(sender, message.viewSize, message.framePosition);
case messages.FOLLOW_CREATE_HINTS:
- return this.createHints(message.keysArray, message.newTab);
+ return this.createHints(
+ message.keysArray, message.newTab, message.background);
case messages.FOLLOW_SHOW_HINTS:
return this.showHints(message.keys);
case messages.FOLLOW_ACTIVATE:
@@ -170,6 +191,7 @@ export default class Follow {
style.visibility !== 'hidden' &&
element.type !== 'hidden' &&
element.offsetHeight > 0 &&
+ !isAriaHiddenOrAriaDisabled(win, element) &&
inViewport(win, element, viewSize, framePosition);
});
return filtered;