-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathnotch-detected-event.min.js
9 lines (9 loc) · 1.65 KB
/
notch-detected-event.min.js
1
2
3
4
5
6
7
8
9
/*!
* notch-detected-event.js - v1.2.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";function n(n){setTimeout(function(){var n=e.documentElement;n.style.setProperty("--notch-top","env(safe-area-inset-top)"),n.style.setProperty("--notch-right","env(safe-area-inset-right)"),n.style.setProperty("--notch-bottom","env(safe-area-inset-bottom)"),n.style.setProperty("--notch-left","env(safe-area-inset-left)");var o=t.getComputedStyle(n);[o.getPropertyValue("--notch-top")||"-1",o.getPropertyValue("--notch-right")||"-1",o.getPropertyValue("--notch-bottom")||"-1",o.getPropertyValue("--notch-left")||"-1"].map(parseInt).filter(function(t){return t>0}).length>0&&(n.setAttribute("data-notch","true"),t.dispatchEvent(new CustomEvent("notch-detected",{bubbles:!0,cancelable:!0}))),n.style.removeProperty("--notch-top"),n.style.removeProperty("--notch-right"),n.style.removeProperty("--notch-bottom"),n.style.removeProperty("--notch-left")},n)}t.cordova?e.addEventListener("deviceready",function(){n(1e3)}):t.addEventListener("load",function(){n(1e3)}),t.addEventListener("orientationchange",function(){n(0)}),e.addEventListener("resume",function(){n(0)}),"function"!=typeof t.CustomEvent&&(t.CustomEvent=function(t,n){n=n||{bubbles:!1,cancelable:!1,detail:void 0};var o=e.createEvent("CustomEvent");return o.initCustomEvent(t,n.bubbles,n.cancelable,n.detail),o},t.CustomEvent.prototype=t.Event.prototype)}(this,document);