Skip to content

Commit

Permalink
Fix false negative on page load (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
Richienb authored Jul 6, 2020
1 parent 4797932 commit 7b6b2d0
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ MIT License
}));
};

setInterval(() => {
const main = ({emitEvents = true} = {}) => {
const widthThreshold = window.outerWidth - window.innerWidth > threshold;
const heightThreshold = window.outerHeight - window.innerHeight > threshold;
const orientation = widthThreshold ? 'vertical' : 'horizontal';
Expand All @@ -33,21 +33,24 @@ MIT License
!(heightThreshold && widthThreshold) &&
((window.Firebug && window.Firebug.chrome && window.Firebug.chrome.isInitialized) || widthThreshold || heightThreshold)
) {
if (!devtools.isOpen || devtools.orientation !== orientation) {
if ((!devtools.isOpen || devtools.orientation !== orientation) && emitEvents) {
emitEvent(true, orientation);
}

devtools.isOpen = true;
devtools.orientation = orientation;
} else {
if (devtools.isOpen) {
if (devtools.isOpen && emitEvents) {
emitEvent(false, undefined);
}

devtools.isOpen = false;
devtools.orientation = undefined;
}
}, 500);
};

main({emitEvents: false});
setInterval(main, 500);

if (typeof module !== 'undefined' && module.exports) {
module.exports = devtools;
Expand Down

0 comments on commit 7b6b2d0

Please sign in to comment.