aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2017-10-14 06:46:31 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2017-10-14 06:46:31 +0900
commitbebf8e23275156d39decbc974bcc05fa1d977d26 (patch)
tree5b6de3451d6cff78d2d45e16039629d539e46c32
parent890f84c34382253d6c178a5a09149832d145c60f (diff)
get hints from window
-rw-r--r--src/content/components/follow.js22
-rw-r--r--src/content/index.js2
-rw-r--r--test/content/components/follow.test.js2
3 files changed, 13 insertions, 13 deletions
diff --git a/src/content/components/follow.js b/src/content/components/follow.js
index 119a493..3307893 100644
--- a/src/content/components/follow.js
+++ b/src/content/components/follow.js
@@ -9,20 +9,21 @@ const TARGET_SELECTOR = [
'[contenteditable=true]', '[contenteditable=""]'
].join(',');
-const inWindow = (window, element) => {
+const inWindow = (win, element) => {
let {
top, left, bottom, right
} = element.getBoundingClientRect();
+ let doc = win.doc;
return (
top >= 0 && left >= 0 &&
- bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
- right <= (window.innerWidth || document.documentElement.clientWidth)
+ bottom <= (win.innerHeight || doc.documentElement.clientHeight) &&
+ right <= (win.innerWidth || doc.documentElement.clientWidth)
);
};
export default class FollowComponent {
- constructor(wrapper, store) {
- this.wrapper = wrapper;
+ constructor(win, store) {
+ this.win = win;
this.store = store;
this.hintElements = {};
this.state = {};
@@ -141,8 +142,7 @@ export default class FollowComponent {
}
create() {
- let doc = this.wrapper.ownerDocument;
- let elements = FollowComponent.getTargetElements(doc);
+ let elements = FollowComponent.getTargetElements(this.win);
let producer = new HintKeyProducer(DEFAULT_HINT_CHARSET);
let hintElements = {};
Array.prototype.forEach.call(elements, (ele) => {
@@ -160,15 +160,15 @@ export default class FollowComponent {
});
}
- static getTargetElements(doc) {
- let all = doc.querySelectorAll(TARGET_SELECTOR);
+ static getTargetElements(win) {
+ let all = win.document.querySelectorAll(TARGET_SELECTOR);
let filtered = Array.prototype.filter.call(all, (element) => {
- let style = window.getComputedStyle(element);
+ let style = win.getComputedStyle(element);
return style.display !== 'none' &&
style.visibility !== 'hidden' &&
element.type !== 'hidden' &&
element.offsetHeight > 0 &&
- inWindow(window, element);
+ inWindow(win, element);
});
return filtered;
}
diff --git a/src/content/index.js b/src/content/index.js
index 64d86bb..65be89f 100644
--- a/src/content/index.js
+++ b/src/content/index.js
@@ -9,7 +9,7 @@ import reducers from 'content/reducers';
import messages from 'shared/messages';
const store = createStore(reducers);
-const followComponent = new FollowComponent(window.document.body, store);
+const followComponent = new FollowComponent(window, store);
const contentInputComponent =
new ContentInputComponent(window.document.body, store);
const keymapperComponent = new KeymapperComponent(store);
diff --git a/test/content/components/follow.test.js b/test/content/components/follow.test.js
index 5c3e1d5..c8ae58b 100644
--- a/test/content/components/follow.test.js
+++ b/test/content/components/follow.test.js
@@ -8,7 +8,7 @@ describe('FollowComponent', () => {
});
it('returns visible links', () => {
- let targets = FollowComponent.getTargetElements(window.document);
+ let targets = FollowComponent.getTargetElements(window);
expect(targets).to.have.lengthOf(3);
let ids = Array.prototype.map.call(targets, (e) => e.id);