Skip to content

Commit

Permalink
Update with latest dev-detect.js
Browse files Browse the repository at this point in the history
  • Loading branch information
maxwofford committed Nov 11, 2019
1 parent 1d53253 commit a8077e1
Showing 1 changed file with 50 additions and 54 deletions.
104 changes: 50 additions & 54 deletions js/dev-detect.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,57 +5,53 @@
by Sindre Sorhus
MIT License
*/
;(function() {
'use strict'
var devtools = {
open: false,
orientation: null
}
var threshold = 160
var emitEvent = function(state, orientation) {
window.dispatchEvent(
new CustomEvent('devtoolschange', {
detail: {
open: state,
orientation: orientation
}
})
)
}

setInterval(function() {
var widthThreshold = window.outerWidth - window.innerWidth > threshold
var heightThreshold = window.outerHeight - window.innerHeight > threshold
var orientation = widthThreshold ? 'vertical' : 'horizontal'

if (
!(heightThreshold && widthThreshold) &&
((window.Firebug &&
window.Firebug.chrome &&
window.Firebug.chrome.isInitialized) ||
widthThreshold ||
heightThreshold)
) {
if (!devtools.open || devtools.orientation !== orientation) {
emitEvent(true, orientation)
}

devtools.open = true
devtools.orientation = orientation
} else {
if (devtools.open) {
emitEvent(false, null)
}

devtools.open = false
devtools.orientation = null
}
}, 500)

if (typeof module !== 'undefined' && module.exports) {
module.exports = devtools
} else {
window.devtools = devtools
}
})()
/* END DEVTOOLS-DETECT */
(function () {
'use strict';

const devtools = {
isOpen: false,
orientation: undefined
};

const threshold = 160;

const emitEvent = (isOpen, orientation) => {
window.dispatchEvent(new CustomEvent('devtoolschange', {
detail: {
isOpen,
orientation
}
}));
};

setInterval(() => {
const widthThreshold = window.outerWidth - window.innerWidth > threshold;
const heightThreshold = window.outerHeight - window.innerHeight > threshold;
const orientation = widthThreshold ? 'vertical' : 'horizontal';

if (
!(heightThreshold && widthThreshold) &&
((window.Firebug && window.Firebug.chrome && window.Firebug.chrome.isInitialized) || widthThreshold || heightThreshold)
) {
if (!devtools.isOpen || devtools.orientation !== orientation) {
emitEvent(true, orientation);
}

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

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

if (typeof module !== 'undefined' && module.exports) {
module.exports = devtools;
} else {
window.devtools = devtools;
}
})()

0 comments on commit a8077e1

Please sign in to comment.