require-polyfills
Version:
Collection of polyfils that load automatically using require-bundle-js by detecting what is missing in the browser.
3 lines (2 loc) • 2.67 kB
JavaScript
loadjs=function(){var h=function(){},u={},c={},f={};function s(e,n){if(e){var t=f[e];if(c[e]=n,t)for(;t.length;)t[0](e,n),t.splice(0,1)}}function l(e,n){e.call&&(e={success:e}),n.length?(e.error||h)(n):(e.success||h)(e)}function a(e,r,n){for(var o=(e=e.push?e:[e]).length,t=o,i=[],u=function(e,n,t){if("e"==n&&i.push(e),"b"==n){if(!t)return;i.push(e)}--o||r(i)},s=0;s<t;s++)!function t(r,o,i,u){var s,c,e=document,n=i.async,f=(i.numRetries||0)+1,l=i.before||h,a=r.replace(/[\?|#].*$/,""),d=r.replace(/^(css|img)!/,"");u=u||0,/(^css!|\.css$)/.test(a)?((c=e.createElement("link")).rel="stylesheet",c.href=d,(s="hideFocus"in c)&&c.relList&&(s=0,c.rel="preload",c.as="style")):/(^img!|\.(png|gif|jpg|svg|webp)$)/.test(a)?(c=e.createElement("img")).src=d:((c=e.createElement("script")).src=r,c.async=void 0===n||n),c.onload=c.onerror=c.onbeforeload=function(e){var n=e.type[0];if(s)try{c.sheet.cssText.length||(n="e")}catch(e){18!=e.code&&(n="e")}if("e"==n){if((u+=1)<f)return t(r,o,i,u)}else if("preload"==c.rel&&"style"==c.as)return c.rel="stylesheet";o(r,n,e.defaultPrevented)},!1!==l(r,c)&&e.head.appendChild(c)}(e[s],u,n)}function t(e,n,t){var r,o;if(n&&n.trim&&(r=n),o=(r?t:n)||{},r){if(r in u)throw"LoadJS";u[r]=!0}function i(n,t){a(e,function(e){l(o,e),n&&l({success:n,error:t},e),s(r,e)},o)}if(o.returnPromise)return new Promise(i);i()}return t.ready=function(e,n){return function(e,t){e=e.push?e:[e];for(var n,r,o=[],i=e.length,u=i,s=function(e,n){n.length&&o.push(e),--u||t(o)};i--;)n=e[i],(r=c[n])?s(n,r):(f[n]=f[n]||[]).push(s)}(e,function(e){l(n,e)}),t},t.done=function(e){s(e,[])},t.reset=function(){u={},c={},f={}},t.isDefined=function(e){return e in u},t}(),function(e,n){"function"==typeof define&&define.amd?define([],n()):"object"==typeof exports?module.exports=n():e.RequireBundle=n()}("undefined"!=typeof global?global:this.window||this.global,function(e){"use strict";var o={},i={};return o.getIds=function(){return Object.keys(i)},o.hasBundle=function(e){return i.hasOwnProperty(e)},o.getBundle=function(e){return o.hasBundle(e)?i[e]:[]},o.register=function(e,n,t,r){return o.hasBundle(e)?(console.log("Bundle already registered: `"+e+"`"),!1):(i[e]={bundleId:e,deps:n,autoLoadSelector:t,callbackFn:r},!0)},o.require=function(e,n){Array.isArray(e)||(e=[e]),"function"!=typeof n&&(n=function(){}),e.forEach(function(e){var n=o.getBundle(e);n&&(loadjs.isDefined(e)||loadjs(n.deps,e))}),loadjs.ready(e,n)},window.addEventListener("load",function(){o.getIds().forEach(function(e){var n=i[e];"string"==typeof n.autoLoadSelector&&document.querySelector(n.autoLoadSelector)&&o.require(e,n.callbackFn)})}),o});
//# sourceMappingURL=maps/require-bundle.min.js.map