From 88880587c6e807f4eee93bf8f99aa0cd18fe9c02 Mon Sep 17 00:00:00 2001 From: TheGoddessInari Date: Thu, 30 Jul 2020 20:54:23 -0700 Subject: [PATCH] Add hamsket.isInViewport to the service API. --- resources/js/hamsket-service-api.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/resources/js/hamsket-service-api.js b/resources/js/hamsket-service-api.js index 26532b40..f94b3724 100644 --- a/resources/js/hamsket-service-api.js +++ b/resources/js/hamsket-service-api.js @@ -44,6 +44,15 @@ window.hamsket.parseIntOrZero = function (n) { return isNaN(result) ? 0 : result; }; +window.hamsket.isInViewport = function(node) { + const rect = node.getBoundingClientRect(); + + return rect.bottom > 0 && + rect.right > 0 && + rect.left < (window.innerWidth || document.documentElement.clientWidth) && + rect.top < (window.innerHeight || document.documentElement.clientHeight); +}; + contextMenu({ window: remote.getCurrentWebContents(), showCopyImageAddress: true,