forked from getify/LABjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLAB-debug.min.js
6 lines (5 loc) · 6.12 KB
/
LAB-debug.min.js
1
2
3
4
5
6
/*! LAB.js (LABjs :: Loading And Blocking JavaScript)
v2.0.3 (c) Kyle Simpson
MIT License
*/
!function(e){function t(e){return"[object Function]"==Object.prototype.toString.call(e)}function n(e){return"[object Array]"==Object.prototype.toString.call(e)}function r(e,t){var n=/^\w+\:\/\//;return/^\/\/\/?/.test(e)?e=location.protocol+e:n.test(e)||"/"==e.charAt(0)||(e=(t||"")+e),n.test(e)?e:("/"==e.charAt(0)?_:m)+e}function i(e,t){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);return t}function s(e){for(var t=!1,n=0;n<e.scripts.length;n++)e.scripts[n].ready&&e.scripts[n].exec_trigger&&(t=!0,e.scripts[n].exec_trigger(),e.scripts[n].exec_trigger=null);return t}function c(e,t,n,r){e.onload=e.onreadystatechange=function(){e.readyState&&"complete"!=e.readyState&&"loaded"!=e.readyState||t[n]||(e.onload=e.onreadystatechange=null,r())}}function a(e){e.ready=e.finished=!0;for(var t=0;t<e.finished_listeners.length;t++)e.finished_listeners[t]();e.ready_listeners=[],e.finished_listeners=[]}function o(e,t,n,r,i){setTimeout(function(){var s,a,o=t.real_src;if("item"in v){if(!v[0])return void setTimeout(arguments.callee,25);v=v[0]}s=document.createElement("script"),t.type&&(s.type=t.type),t.charset&&(s.charset=t.charset),i?A?(e[g]&&b("start script preload: "+o),n.elem=s,B?(s.preload=!0,s.onpreload=r):s.onreadystatechange=function(){"loaded"==s.readyState&&r()},s.src=o):i&&0==o.indexOf(_)&&e[f]?(a=new XMLHttpRequest,e[g]&&b("start script preload (xhr): "+o),a.onreadystatechange=function(){4==a.readyState&&(a.onreadystatechange=function(){},n.text=a.responseText+"\n//@ sourceURL="+o,r())},a.open("GET",o),a.send()):(e[g]&&b("start script preload (cache): "+o),s.type="text/cache-script",c(s,n,"ready",function(){v.removeChild(s),r()}),s.src=o,v.insertBefore(s,v.firstChild)):E?(e[g]&&b("start script load (ordered async): "+o),s.async=!1,c(s,n,"finished",r),s.src=o,v.insertBefore(s,v.firstChild)):(e[g]&&b("start script load: "+o),c(s,n,"finished",r),s.src=o,v.insertBefore(s,v.firstChild))},0)}function l(){function m(e,t,n){function r(){null!=i&&(i=null,a(n))}var i;C[t.src].finished||(e[p]||(C[t.src].finished=!0),i=n.elem||document.createElement("script"),t.type&&(i.type=t.type),t.charset&&(i.charset=t.charset),c(i,n,"finished",r),n.elem?n.elem=null:n.text?(i.onload=i.onreadystatechange=null,i.text=n.text):i.src=t.real_src,v.insertBefore(i,v.firstChild),n.text&&r())}function _(e,t,n,i){var s,c,l=function(){t.ready_cb(t,function(){m(e,t,s)})},u=function(){t.finished_cb(t,n,e)};t.src=r(t.src,e[y]),t.real_src=t.src+(e[h]?(/\?.*$/.test(t.src)?"&_":"?_")+~~(1e9*Math.random())+"=":""),C[t.src]||(C[t.src]={items:[],finished:!1}),c=C[t.src].items,e[p]||0==c.length?(s=c[c.length]={ready:!1,finished:!1,ready_listeners:[l],finished_listeners:[u]},o(e,t,s,i?function(){s.ready=!0;for(var e=0;e<s.ready_listeners.length;e++)s.ready_listeners[e]();s.ready_listeners=[]}:function(){a(s)},i)):(s=c[0],s.finished?u():s.finished_listeners.push(u))}function x(){function e(e,t){u[g]&&b("script preload finished: "+e.real_src),e.ready=!0,e.exec_trigger=t,c()}function r(e,t,n){n[g]&&b("script execution finished: "+e.real_src),"object"==typeof n&&"function"==typeof n.loadError&&parseInt(t.idx)>0&&!_full_list[parseInt(t.idx)-1].finished&&(clearTimeout(_check_finished),n.loadError.apply(null,arguments)),e.ready=e.finished=!0,e.exec_trigger=null;for(var r=0;r<t.scripts.length;r++)if(!t.scripts[r].finished)return;t.finished=!0,c()}function c(){for(;p<f.length;)if(t(f[p])){u[g]&&b("$LAB.wait() executing: "+f[p]);try{f[p++]()}catch(e){u[g]&&w("$LAB.wait() error caught: ",e)}}else{if(!f[p].finished){if(s(f[p]))continue;break}p++}p==f.length&&(h=!1,l=!1)}function a(){l&&l.scripts||f.push(l={scripts:[],finished:!0})}var o,l,u=i(B,{}),f=[],p=0,h=!1;return o={script:function(){for(var s=0;s<arguments.length;s++)!function(s,c){var f;n(s)||(c=[s]);for(var p=0;p<c.length;p++)a(),s=c[p],t(s)&&(s=s()),s&&(n(s)?(f=[].slice.call(s),f.unshift(p,1),[].splice.apply(c,f),p--):("string"==typeof s&&(s={src:s}),s=i(s,{ready:!1,ready_cb:e,finished:!1,finished_cb:r}),l.idx=_full_list.length,l.finished=!1,l.scripts.push(s),_full_list.push(l),_(u,s,l,E&&h),h=!0,u[d]&&o.wait()))}(arguments[s],arguments[s]);return o},wait:function(){if(arguments.length>0){for(var e=0;e<arguments.length;e++)f.push(arguments[e]);l=f[f.length-1]}else l=!1;return c(),o}},{script:o.script,wait:o.wait,setOptions:function(e){return!_check_finished&&Number.isInteger(e.timeout)&&(_check_finished=setTimeout(function(){for(var t=!0,n=0;n<_full_list.length;n++)if(!_full_list[n].finished){t=!1;break}t||e.loadError.apply(null,arguments)},e.timeout)),i(e,u),o}}}var S,B={},E=A||L,O=[],C={};return B[f]=!0,B[d]=!1,B[p]=!1,B[h]=!1,B[g]=!1,B[y]="",S={setGlobalDefaults:function(e){return i(e,B),S},setOptions:function(){return x().setOptions.apply(null,arguments)},script:function(){return x().script.apply(null,arguments)},wait:function(){return x().wait.apply(null,arguments)},queueScript:function(){return O[O.length]={type:"script",args:[].slice.call(arguments)},S},queueWait:function(){return O[O.length]={type:"wait",args:[].slice.call(arguments)},S},runQueue:function(){for(var e,t=S,n=O.length,r=n;--r>=0;)e=O.shift(),t=t[e.type].apply(null,e.args);return t},noConflict:function(){return e.$LAB=u,S},sandbox:function(){return l()}}}var u=e.$LAB,f="UseLocalXHR",d="AlwaysPreserveOrder",p="AllowDuplicates",h="CacheBust",g="Debug",y="BasePath",m=/^[^?#]*\//.exec(location.href)[0],_=/^\w+\:\/\/\/?[^\/]+/.exec(m)[0],v=document.head||document.getElementsByTagName("head"),x=e.opera&&"[object Opera]"==Object.prototype.toString.call(e.opera)||"MozAppearance"in document.documentElement.style,b=function(){},w=b,S=document.createElement("script"),B="boolean"==typeof S.preload,A=B||S.readyState&&"uninitialized"==S.readyState,E=!A&&S.async===!0,L=!A&&!E&&!x;_full_list=[],_check_finished=null,e.console&&e.console.log&&(e.console.error||(e.console.error=e.console.log),b=function(t){e.console.log(t)},w=function(t,n){e.console.error(t,n)}),e.$LAB=l(),function(e,t,n){null==document.readyState&&document[e]&&(document.readyState="loading",document[e](t,n=function(){document.removeEventListener(t,n,!1),document.readyState="complete"},!1))}("addEventListener","DOMContentLoaded")}(this);