aboutsummaryrefslogtreecommitdiff
path: root/src/shared/utils/dom.js
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2018-05-01 13:51:07 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2018-05-01 13:51:07 +0900
commit4d7c24f38a6861e1d498b6e7dd5c7be2d1a0ad15 (patch)
tree0948f730a25eeda127c56a0f01009f14d066e4dc /src/shared/utils/dom.js
parent177940981ed9c4f096ad7db20f0b7ee044fd7b17 (diff)
parentfb8a0f36aa4d070df936cc7598ef8dd988ee1b15 (diff)
Merge remote-tracking branch 'origin/master' into background-adjacent-tabs
Diffstat (limited to 'src/shared/utils/dom.js')
-rw-r--r--src/shared/utils/dom.js26
1 files changed, 25 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 };