/*! * viewport-units-buggyfill v0.6.2 * @web: https://github.com/rodneyrehm/viewport-units-buggyfill/ * @author: Rodney Rehm - http://rodneyrehm.de/en/ */ (function() { (function(root, factory) { 'use strict'; if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. define([], factory); } else if (typeof exports === 'object') { // Node. Does not work with strict CommonJS, but // only CommonJS-like enviroments that support module.exports, // like Node. module.exports = factory(); } else { // Browser globals (root is window) root.viewportUnitsBuggyfill = factory(); } }(this, function() { 'use strict'; /* global document, window, navigator, location, XMLHttpRequest, XDomainRequest, CustomEvent */ var initialized = false; var options; var userAgent = window.navigator.userAgent; var viewportUnitExpression = /([+-]?[0-9.]+)(vh|vw|vmin|vmax)/g; var urlExpression = /(https?:)?\/\// var forEach = [].forEach; var dimensions; var declarations; var styleNode; var isBuggyIE = /MSIE [0-9]\./i.test(userAgent); var isOldIE = /MSIE [0-8]\./i.test(userAgent); var isOperaMini = userAgent.indexOf('Opera Mini') > -1; var isMobileSafari = /(iPhone|iPod|iPad).+AppleWebKit/i.test(userAgent) && (function() { // Regexp for iOS-version tested against the following userAgent strings: // Example WebView UserAgents: // * iOS Chrome on iOS8: "Mozilla/5.0 (iPad; CPU OS 8_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) CriOS/39.0.2171.50 Mobile/12B410 Safari/600.1.4" // * iOS Facebook on iOS7: "Mozilla/5.0 (iPhone; CPU iPhone OS 7_1_1 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Mobile/11D201 [FBAN/FBIOS;FBAV/12.1.0.24.20; FBBV/3214247; FBDV/iPhone6,1;FBMD/iPhone; FBSN/iPhone OS;FBSV/7.1.1; FBSS/2; FBCR/AT&T;FBID/phone;FBLC/en_US;FBOP/5]" // Example Safari UserAgents: // * Safari iOS8: "Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.3 (KHTML, like Gecko) Version/8.0 Mobile/12A4345d Safari/600.1.4" // * Safari iOS7: "Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A4449d Safari/9537.53" var iOSversion = userAgent.match(/OS (\d+)/); // viewport units work fine in mobile Safari and webView on iOS 8+ return iOSversion && iOSversion.length > 1 && parseInt(iOSversion[1]) < 10; })(); var isBadStockAndroid = (function() { // Android stock browser test derived from // http://stackoverflow.com/questions/24926221/distinguish-android-chrome-from-stock-browser-stock-browsers-user-agent-contai var isAndroid = userAgent.indexOf(' Android ') > -1; if (!isAndroid) { return false; } var isStockAndroid = userAgent.indexOf('Version/') > -1; if (!isStockAndroid) { return false; } var versionNumber = parseFloat((userAgent.match('Android ([0-9.]+)') || [])[1]); // anything below 4.4 uses WebKit without *any* viewport support, // 4.4 has issues with viewport units within calc() return versionNumber <= 4.4; })(); // added check for IE10, IE11 and Edge < 20, since it *still* doesn't understand vmax // http://caniuse.com/#feat=viewport-units if (!isBuggyIE) { isBuggyIE = !!navigator.userAgent.match(/MSIE 10\.|Trident.*rv[ :]*1[01]\.| Edge\/1\d\./); } // Polyfill for creating CustomEvents on IE9/10/11 // from https://github.com/krambuhl/custom-event-polyfill try { // eslint-disable-next-line no-new, no-use-before-define new CustomEvent('test'); } catch (e) { var CustomEvent = function(event, params) { var evt; params = params || { bubbles: false, cancelable: false, detail: undefined, }; evt = document.createEvent('CustomEvent'); evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail); return evt; }; CustomEvent.prototype = window.Event.prototype; window.CustomEvent = CustomEvent; // expose definition to window } function debounce(func, wait) { var timeout; return function() { var context = this; var args = arguments; var callback = function() { func.apply(context, args); }; clearTimeout(timeout); timeout = setTimeout(callback, wait); }; } // from http://stackoverflow.com/questions/326069/how-to-identify-if-a-webpage-is-being-loaded-inside-an-iframe-or-directly-into-t function inIframe() { try { return window.self !== window.top; } catch (e) { return true; } } function initialize(initOptions) { if (initialized) { return; } if (initOptions === true) { initOptions = { force: true, }; } options = initOptions || {}; options.isMobileSafari = isMobileSafari; options.isBadStockAndroid = isBadStockAndroid; if (options.ignoreVmax && !options.force && !isOldIE) { // modern IE (10 and up) do not support vmin/vmax, // but chances are this unit is not even used, so // allow overwriting the "hacktivation" // https://github.com/rodneyrehm/viewport-units-buggyfill/issues/56 isBuggyIE = false; } if (isOldIE || (!options.force && !isMobileSafari && !isBuggyIE && !isBadStockAndroid && !isOperaMini && (!options.hacks || !options.hacks.required(options)))) { // this buggyfill only applies to mobile safari, IE9-10 and the Stock Android Browser. if (window.console && isOldIE) { console.info('viewport-units-buggyfill requires a proper CSSOM and basic viewport unit support, which are not available in IE8 and below'); } return { init: function() {}, }; } // fire a custom event that buggyfill was initialize window.dispatchEvent(new CustomEvent('viewport-units-buggyfill-init')); options.hacks && options.hacks.initialize(options); initialized = true; styleNode = document.createElement('style'); styleNode.id = 'patched-viewport'; document[options.appendToBody ? 'body' : 'head'].appendChild(styleNode); // Issue #6: Cross Origin Stylesheets are not accessible through CSSOM, // therefore download and inject them as