|
|
@ -9,20 +9,21 @@ const TARGET_SELECTOR = [ |
|
|
|
'[contenteditable=true]', '[contenteditable=""]' |
|
|
|
'[contenteditable=true]', '[contenteditable=""]' |
|
|
|
].join(','); |
|
|
|
].join(','); |
|
|
|
|
|
|
|
|
|
|
|
const inWindow = (window, element) => { |
|
|
|
const inWindow = (win, element) => { |
|
|
|
let { |
|
|
|
let { |
|
|
|
top, left, bottom, right |
|
|
|
top, left, bottom, right |
|
|
|
} = element.getBoundingClientRect(); |
|
|
|
} = element.getBoundingClientRect(); |
|
|
|
|
|
|
|
let doc = win.doc; |
|
|
|
return ( |
|
|
|
return ( |
|
|
|
top >= 0 && left >= 0 && |
|
|
|
top >= 0 && left >= 0 && |
|
|
|
bottom <= (window.innerHeight || document.documentElement.clientHeight) && |
|
|
|
bottom <= (win.innerHeight || doc.documentElement.clientHeight) && |
|
|
|
right <= (window.innerWidth || document.documentElement.clientWidth) |
|
|
|
right <= (win.innerWidth || doc.documentElement.clientWidth) |
|
|
|
); |
|
|
|
); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
export default class FollowComponent { |
|
|
|
export default class FollowComponent { |
|
|
|
constructor(wrapper, store) { |
|
|
|
constructor(win, store) { |
|
|
|
this.wrapper = wrapper; |
|
|
|
this.win = win; |
|
|
|
this.store = store; |
|
|
|
this.store = store; |
|
|
|
this.hintElements = {}; |
|
|
|
this.hintElements = {}; |
|
|
|
this.state = {}; |
|
|
|
this.state = {}; |
|
|
@ -141,8 +142,7 @@ export default class FollowComponent { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
create() { |
|
|
|
create() { |
|
|
|
let doc = this.wrapper.ownerDocument; |
|
|
|
let elements = FollowComponent.getTargetElements(this.win); |
|
|
|
let elements = FollowComponent.getTargetElements(doc); |
|
|
|
|
|
|
|
let producer = new HintKeyProducer(DEFAULT_HINT_CHARSET); |
|
|
|
let producer = new HintKeyProducer(DEFAULT_HINT_CHARSET); |
|
|
|
let hintElements = {}; |
|
|
|
let hintElements = {}; |
|
|
|
Array.prototype.forEach.call(elements, (ele) => { |
|
|
|
Array.prototype.forEach.call(elements, (ele) => { |
|
|
@ -160,15 +160,15 @@ export default class FollowComponent { |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static getTargetElements(doc) { |
|
|
|
static getTargetElements(win) { |
|
|
|
let all = doc.querySelectorAll(TARGET_SELECTOR); |
|
|
|
let all = win.document.querySelectorAll(TARGET_SELECTOR); |
|
|
|
let filtered = Array.prototype.filter.call(all, (element) => { |
|
|
|
let filtered = Array.prototype.filter.call(all, (element) => { |
|
|
|
let style = window.getComputedStyle(element); |
|
|
|
let style = win.getComputedStyle(element); |
|
|
|
return style.display !== 'none' && |
|
|
|
return style.display !== 'none' && |
|
|
|
style.visibility !== 'hidden' && |
|
|
|
style.visibility !== 'hidden' && |
|
|
|
element.type !== 'hidden' && |
|
|
|
element.type !== 'hidden' && |
|
|
|
element.offsetHeight > 0 && |
|
|
|
element.offsetHeight > 0 && |
|
|
|
inWindow(window, element); |
|
|
|
inWindow(win, element); |
|
|
|
}); |
|
|
|
}); |
|
|
|
return filtered; |
|
|
|
return filtered; |
|
|
|
} |
|
|
|
} |
|
|
|