Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
3 lines (2 sloc) 2.2 KB
/*! micro-requirejs 2018-03-01 */
window.rjs=function(e,n){"use strict";var t={debug:!1},r=function(n){var t=e.document.createElement("link");return t.type="text/css",t.rel="stylesheet",t.href=n,t.async=!0,t},i=function(n){var t=e.document.createElement("script");return t.type="text/javascript",t.src=n,t.async=!0,t};return new function(){var n=new function(){return{eventStack:[],pendingListeners:[],reset:function(){this.eventStack=[],this.pendingListeners=[]},resolvePendingListeners:function(){var e=this;this.pendingListeners.forEach(function(n,t){n&&e.isEveryEventResolved(n.events)&&(n.handler(),delete e.pendingListeners[t])})},isEveryEventResolved:function(e){var n=this;return e.every(function(e){return-1!==n.eventStack.indexOf(e)})},trigger:function(e){t.debug&&console.log(">> `"+e+"` triggered"),this.eventStack.push(e),this.resolvePendingListeners()},on:function(n,r){if(t.debug&&console.log(">> `"+e.JSON.stringify(n)+"` subscribed"),!Array.isArray(n))throw new TypeError("The first parameter must an array");if("function"!=typeof r)throw new TypeError("The second parameter must a function");if(this.isEveryEventResolved(n))return r();this.pendingListeners.push({events:n,handler:r})}}},o=function(){"complete"===e.document.readyState||"loaded"===e.document.readyState?n.trigger("DOMContentLoaded"):e.document.addEventListener("DOMContentLoaded",function(){n.trigger("DOMContentLoaded")},!1)};return o(),{define:function(t,o,s,a){var c=function(e){var n=e.split(".").pop().toLowerCase();switch(n){case"css":return r(e);case"js":return i(e)}throw new Error("Unknown file extension "+n)}(t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")),d=a?s.bind(a):s;if("string"!=typeof o)throw new TypeError("You have to specify dependency name");c.setAttribute("data-rjs",!0),e.document.body.appendChild(c),void 0===c.onload?c.onreadystatechange=function(){"loaded"===c.readyState&&(n.trigger(o),d&&d())}:c.onload=function(){n.trigger(o),d&&d()}},require:function(e,t,r){r&&(t=t.bind(r)),n.on(e,t)},init:function(e){t=e||{debug:!1},n.reset(),o()},reset:function(){var e=document.querySelectorAll("script[data-rjs]"),n=document.querySelectorAll("link[data-rjs]");[].concat(e,n).forEach(function(e){e.type&&e.parentNode.removeChild(e)})}}}}(this);