diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2018-05-01 15:51:40 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2018-05-01 15:51:40 +0900 |
commit | 9da2f5fd786ff7ef64eca0a86efb1c0b9a164244 (patch) | |
tree | b888349817d0016dc1499932671bbe6cd95efdaa /src/shared/utils | |
parent | f9889b7f2b634bfe5a540633d8952f4a6f900658 (diff) | |
parent | 89d6afecfd257ff4fc62748f771abf37ef3a2852 (diff) |
Merge remote-tracking branch 'origin/master' into patch-1
Diffstat (limited to 'src/shared/utils')
-rw-r--r-- | src/shared/utils/dom.js | 26 | ||||
-rw-r--r-- | src/shared/utils/keys.js | 1 |
2 files changed, 26 insertions, 1 deletions
diff --git a/src/shared/utils/dom.js b/src/shared/utils/dom.js index d4fd68a..974d534 100644 --- a/src/shared/utils/dom.js +++ b/src/shared/utils/dom.js @@ -81,4 +81,28 @@ const viewportRect = (e) => { }; }; -export { isContentEditable, viewportRect }; +const isVisible = (element) => { + let rect = element.getBoundingClientRect(); + let style = window.getComputedStyle(element); + + if (style.overflow !== 'visible' && (rect.width === 0 || rect.height === 0)) { + return false; + } + if (rect.right < 0 && rect.bottom < 0) { + return false; + } + if (window.innerWidth < rect.left && window.innerHeight < rect.top) { + return false; + } + if (element.nodeName === 'INPUT' && element.type.toLowerCase() === 'hidden') { + return false; + } + + let { display, visibility } = window.getComputedStyle(element); + if (display === 'none' || visibility === 'hidden') { + return false; + } + return true; +}; + +export { isContentEditable, viewportRect, isVisible }; diff --git a/src/shared/utils/keys.js b/src/shared/utils/keys.js index fba8ce3..8a86dfb 100644 --- a/src/shared/utils/keys.js +++ b/src/shared/utils/keys.js @@ -18,6 +18,7 @@ const fromKeyboardEvent = (e) => { return { key: modifierdKeyName(e.key), + repeat: e.repeat, shiftKey: shift, ctrlKey: e.ctrlKey, altKey: e.altKey, |