Files
OverlayScrollbars/docs/_framework/plugins/js/viewport-units-buggyfill.min.js
T
2022-10-14 11:50:29 +02:00

6 lines
4.9 KiB
JavaScript

/*!
* viewport-units-buggyfill v0.6.2
* @web: https://github.com/rodneyrehm/viewport-units-buggyfill/
* @author: Rodney Rehm - http://rodneyrehm.de/en/
*/
!function(){!function(e,t){"use strict";"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?module.exports=t():e.viewportUnitsBuggyfill=t()}(this,function(){"use strict";var e,t,n,i,r,o=!1,a=window.navigator.userAgent,s=/([+-]?[0-9.]+)(vh|vw|vmin|vmax)/g,c=/(https?:)?\/\//,u=[].forEach,d=/MSIE [0-9]\./i.test(a),l=/MSIE [0-8]\./i.test(a),f=a.indexOf("Opera Mini")>-1,h=/(iPhone|iPod|iPad).+AppleWebKit/i.test(a)&&((r=a.match(/OS (\d+)/))&&r.length>1&&parseInt(r[1])<10),p=a.indexOf(" Android ")>-1&&a.indexOf("Version/")>-1&&parseFloat((a.match("Android ([0-9.]+)")||[])[1])<=4.4;d||(d=!!navigator.userAgent.match(/MSIE 10\.|Trident.*rv[ :]*1[01]\.| Edge\/1\d\./));try{new w("test")}catch(P){var w=function(e,t){var n;return t=t||{bubbles:!1,cancelable:!1,detail:undefined},(n=document.createEvent("CustomEvent")).initCustomEvent(e,t.bubbles,t.cancelable,t.detail),n};w.prototype=window.Event.prototype,window.CustomEvent=w}function v(e,t){var n;return function(){var i=this,r=arguments,o=function(){e.apply(i,r)};clearTimeout(n),n=setTimeout(o,t)}}function m(){try{return window.self!==window.top}catch(P){return!0}}function g(t){if(!o){if(!0===t&&(t={force:!0}),(e=t||{}).isMobileSafari=h,e.isBadStockAndroid=p,!e.ignoreVmax||e.force||l||(d=!1),l||!e.force&&!h&&!d&&!p&&!f&&(!e.hacks||!e.hacks.required(e)))return window.console&&l&&console.info("viewport-units-buggyfill requires a proper CSSOM and basic viewport unit support, which are not available in IE8 and below"),{init:function(){}};window.dispatchEvent(new w("viewport-units-buggyfill-init")),e.hacks&&e.hacks.initialize(e),o=!0,(i=document.createElement("style")).id="patched-viewport",document[e.appendToBody?"body":"head"].appendChild(i),S(function(){var t=v(b,e.refreshDebounceWait||100);window.addEventListener("orientationchange",t,!0),window.addEventListener("pageshow",t,!0),(e.force||d||m())&&(window.addEventListener("resize",t,!0),e._listeningToResize=!0),e.hacks&&e.hacks.initializeEvents(e,b,t),b()})}}function y(){i.textContent=k(),i.parentNode.appendChild(i),window.dispatchEvent(new w("viewport-units-buggyfill-style"))}function b(){o&&(E(),setTimeout(function(){y()},1))}function x(e){try{if(!e.cssRules)return}catch(P){if("SecurityError"!==P.name)throw P;return}for(var t=[],n=0;n<e.cssRules.length;n++){var i=e.cssRules[n];t.push(i)}return t}function E(){return n=[],u.call(document.styleSheets,function(e){var t=x(e);t&&"patched-viewport"!==e.ownerNode.id&&"ignore"!==e.ownerNode.getAttribute("data-viewport-units-buggyfill")&&(e.media&&e.media.mediaText&&window.matchMedia&&!window.matchMedia(e.media.mediaText).matches||u.call(t,T))}),n}function T(t){if(7===t.type){var i;try{i=t.cssText}catch(P){return}return s.lastIndex=0,void(s.test(i)&&!c.test(i)&&(n.push([t,null,i]),e.hacks&&e.hacks.findDeclarations(n,t,null,i)))}if(t.style)u.call(t.style,function(i){var r=t.style.getPropertyValue(i);t.style.getPropertyPriority(i)&&(r+=" !important"),s.lastIndex=0,s.test(r)&&(n.push([t,i,r]),e.hacks&&e.hacks.findDeclarations(n,t,i,r))});else{if(!t.cssRules)return;u.call(t.cssRules,function(e){T(e)})}}function k(){t=M();var e,i,r=[],o=[];return n.forEach(function(t){var n=R.apply(null,t),a=n.selector.length?n.selector.join(" {\n")+" {\n":"",s=new Array(n.selector.length+1).join("\n}");if(!a||a!==e)return o.length&&(r.push(e+o.join("\n")+i),o.length=0),void(a?(e=a,i=s,o.push(n.content)):(r.push(n.content),e=null,i=null));a&&!e&&(e=a,i=s),o.push(n.content)}),o.length&&r.push(e+o.join("\n")+i),f&&r.push("* { content: normal !important; }"),r.join("\n\n")}function R(t,n,i){var r,o=[];r=i.replace(s,C),e.hacks&&(r=e.hacks.overwriteDeclaration(t,n,r)),n&&(o.push(t.selectorText),r=n+": "+r+";");for(var a=t.parentRule;a;)a.media?o.unshift("@media "+a.media.mediaText):a.conditionText&&o.unshift("@supports "+a.conditionText),a=a.parentRule;return{selector:o,content:r}}function C(e,n,i){var r=t[i];return parseFloat(n)/100*r+"px"}function M(){var e=window.innerHeight,t=window.innerWidth;return{vh:e,vw:t,vmax:Math.max(t,e),vmin:Math.min(t,e)}}function S(e){var t=0,n=function(){--t||e()};u.call(document.styleSheets,function(e){e.href&&A(e.href)!==A(location.href)&&"ignore"!==e.ownerNode.getAttribute("data-viewport-units-buggyfill")&&(t++,O(e.ownerNode,n))}),t||e()}function A(e){return e.slice(0,e.indexOf("/",e.indexOf("://")+3))}function O(e,t){I(e.href,function(){var n=document.createElement("style");n.media=e.media,n.setAttribute("data-href",e.href),n.textContent=this.responseText,e.parentNode.replaceChild(n,e),t()},t)}function I(e,t,n){var i=new XMLHttpRequest;if("withCredentials"in i)i.open("GET",e,!0);else{if("undefined"==typeof XDomainRequest)throw new Error("cross-domain XHR not supported");(i=new XDomainRequest).open("GET",e)}return i.onload=t,i.onerror=n,i.send(),i}return{version:"0.6.1",findProperties:E,getCss:k,init:g,refresh:b}})}();