-
Notifications
You must be signed in to change notification settings - Fork 4
/
notch-detected-event.min.js
9 lines (9 loc) · 1.46 KB
/
notch-detected-event.min.js
1
2
3
4
5
6
7
8
9
/*!
* notch-detected-event.js - v1.1.1
* A cross-browser script to detect the existence of a device notch/cutout
* https://github.com/john-doherty/notch-detected-event
* @inspiration https://stackoverflow.com/questions/46318395/detecting-mobile-device-notch
* @author John Doherty <www.johndoherty.info>
* @license MIT
*/
!function(t,e){"use strict";t.addEventListener("load",function(){setTimeout(function(){var o=e.documentElement;o.style.setProperty("--notch-top","env(safe-area-inset-top)"),o.style.setProperty("--notch-right","env(safe-area-inset-right)"),o.style.setProperty("--notch-bottom","env(safe-area-inset-bottom)"),o.style.setProperty("--notch-left","env(safe-area-inset-left)");var n=t.getComputedStyle(o);[n.getPropertyValue("--notch-top")||"-1",n.getPropertyValue("--notch-right")||"-1",n.getPropertyValue("--notch-bottom")||"-1",n.getPropertyValue("--notch-left")||"-1"].map(parseInt).filter(function(t){return t>0}).length>0&&(o.setAttribute("data-notch","true"),t.dispatchEvent(new CustomEvent("notch-detected",{bubbles:!0,cancelable:!0}))),o.style.removeProperty("--notch-top"),o.style.removeProperty("--notch-right"),o.style.removeProperty("--notch-bottom"),o.style.removeProperty("--notch-left")},250)}),"function"!=typeof t.CustomEvent&&(t.CustomEvent=function(t,o){o=o||{bubbles:!1,cancelable:!1,detail:void 0};var n=e.createEvent("CustomEvent");return n.initCustomEvent(t,o.bubbles,o.cancelable,o.detail),n},t.CustomEvent.prototype=t.Event.prototype)}(this,document);