-
Notifications
You must be signed in to change notification settings - Fork 2
/
full-screen-helper.min.js
2 lines (2 loc) · 3.17 KB
/
full-screen-helper.min.js
1
2
/* full-screen-helper.js 1.0.6 | Copyright (c) 2024 Guilherme Nascimento ([email protected]) | Released under the MIT license */
!function(e){var n,t,l,r,c="undefined"!=typeof window?window:{},s=c.document||{},u=c.$||{},i=null,f=!1,o=!1,a=!1,m=!0,h=!1,d=!!s.exitFullscreen,p=!!s.mozCancelFullScreen,F=!!(s.webkitExitFullscreen||s.webkitCancelFullScreen),w=!!s.webkitCancelFullScreen,_=!!s.webkitExitFullscreen,E=!!s.msExitFullscreen,b=/(^|\s+)fsh-infullscreen($|\s+)/i,g=/(^|\s+)full-screen-helper($|\s+)/i,S=[],v=["webkitfullscreenchange","mozfullscreenchange","fullscreenchange","MSFullscreenChange"],k=d||p||F||E;function y(e,n){if("function"==typeof e){if(!n||!n){S.push(e);return}for(var t=[],l=0,r=S.length;l<r;l++)S[l]!==e&&t.push(e);S=t,t=null}}function $(e,n,t){e.addEventListener?e.addEventListener(n,t):e.attachEvent("on"+n,t)}function x(){return L()&&(c.outerWidth||c.innerWidth||n.clientWidth)==c.screen.width}function N(){if(f)return f;if(!1===r||c.ActiveXObject===e)r=!1;else if(r===e)try{r=new c.ActiveXObject("WScript.Shell"),f=!0,$(c,"resize",C)}catch(n){r=!1}return f}function q(e){("Escape"===(e=e||c.event).key||27==(e.wich||e.keyCode))&&R()}function z(){var e;H(f?x():!!(e=s.fullscreenElement||s.mozFullScreenElement||s.webkitFullscreenElement||s.msFullscreenElement)&&(e!==i&&(i=e),!0))}function C(e){clearTimeout(l),l=setTimeout(z,f?100:10)}function L(){return!!n||(t=s.body,!!(n=s.documentElement||t&&t.parentNode))}function H(e){if(h!==e&&i){if(!L()){i=null;return}e?(b.test(n.className)||(n.className+=" fsh-infullscreen"),g.test(i.className)||(i.className+=" full-screen-helper")):(n.className=n.className.replace(b," "),i.className=i.className.replace(g," "),i=null),h=e,setTimeout(W,1)}}function W(){for(var e=0;e<S.length;e++)S[e]()}function A(){return k||N()}function O(n){var t;if(n=(t=n,!i&&(t===e||t===s?s.body:"string"==typeof t?s.querySelector(t):(!c.HTMLElement||!!t&&t instanceof c.HTMLElement&&t.ownerDocument===s)&&!!t&&1===t.nodeType&&t.ownerDocument===s&&t))){if(d)n.requestFullscreen();else if(p)n.mozRequestFullScreen();else if(F)n.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);else if(E)n.msRequestFullscreen();else if(!a){!function e(n){if(o||(o=!0,$(s,"keydown",q)),N()){x()||(i=n,H(!0),r.SendKeys("{F11}"));return}(a=m)&&O(n)}(n);return}i=n,H(!0)}}function R(){if(i){if(d)s.exitFullscreen();else if(p)s.mozCancelFullScreen();else if(_)s.webkitExitFullscreen();else if(w)s.webkitCancelFullScreen();else if(E)s.msExitFullscreen();else if(!a){x()&&f&&(H(!1),r.SendKeys("{F11}"));return}H(!1)}}function T(e){i===(e||s.body)?R():O(e)}if(k){for(var D=v.length-1;D>=0;D--)$(s,v[D],C);$(c,"resize",C)}if(u&&u.extend&&u.expr&&(u.fn.fullScreenHelper=function(n){var t=this[0];if(t)switch(n){case"toggle":T(t);break;case"request":case e:O(t)}},u.fullScreenHelper=function(e){switch(e){case"exit":R();break;case"supported":return A();case"state":return h}},u.expr[":"].fullscreen=function(e){return g.test(e.className)},!("onfullscreenchange"in s))){var K=u(s);y(function(){K.trigger("fullscreenchange")})}c.FullScreenHelper={supported:A,request:O,toggle:T,exit:R,current:function(){return i},state:function(){return h},viewport:function(e){m=!!e},on:function(e){y(e)},off:function(e){y(e,!0)}}}();