mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-14 12:04:05 +01:00
5 lines
5.9 KiB
JavaScript
Executable File
5 lines
5.9 KiB
JavaScript
Executable File
/*! LAB.js (LABjs :: Loading And Blocking JavaScript)
|
|
v2.0.3 (c) Kyle Simpson
|
|
MIT License
|
|
*/
|
|
(function(j){var N=j.$LAB,A="UseLocalXHR",B="AlwaysPreserveOrder",w="AllowDuplicates",C="CacheBust",l="Debug",D="BasePath",E=/^[^?#]*\//.exec(location.href)[0],F=/^\w+\:\/\/\/?[^\/]+/.exec(E)[0],i=document.head||document.getElementsByTagName("head"),O=(j.opera&&Object.prototype.toString.call(j.opera)=="[object Opera]")||("MozAppearance"in document.documentElement.style),m=function(){},G=m,s=document.createElement("script"),H=typeof s.preload=="boolean",t=H||(s.readyState&&s.readyState=="uninitialized"),I=!t&&s.async===true,P=!t&&!I&&!O;if(j.console&&j.console.log){if(!j.console.error)j.console.error=j.console.log;m=function(a){j.console.log(a)};G=function(a,c){j.console.error(a,c)}}function J(a){return Object.prototype.toString.call(a)=="[object Function]"}function K(a){return Object.prototype.toString.call(a)=="[object Array]"}function Q(a,c){var b=/^\w+\:\/\//;if(/^\/\/\/?/.test(a)){a=location.protocol+a}else if(!b.test(a)&&a.charAt(0)!="/"){a=(c||"")+a}return b.test(a)?a:((a.charAt(0)=="/"?F:E)+a)}function u(a,c){for(var b in a){if(a.hasOwnProperty(b)){c[b]=a[b]}}return c}function R(a){var c=false;for(var b=0;b<a.scripts.length;b++){if(a.scripts[b].ready&&a.scripts[b].exec_trigger){c=true;a.scripts[b].exec_trigger();a.scripts[b].exec_trigger=null}}return c}function v(a,c,b,d){a.onload=a.onreadystatechange=function(){if((a.readyState&&a.readyState!="complete"&&a.readyState!="loaded")||c[b])return;a.onload=a.onreadystatechange=null;d()}}function L(a){a.ready=a.finished=true;for(var c=0;c<a.finished_listeners.length;c++){a.finished_listeners[c]()}a.ready_listeners=[];a.finished_listeners=[]}function S(d,g,e,f,h){setTimeout(function(){var a,c=g.real_src,b;if("item"in i){if(!i[0]){setTimeout(arguments.callee,25);return}i=i[0]}a=document.createElement("script");if(g.type)a.type=g.type;if(g.charset)a.charset=g.charset;if(h){if(t){if(d[l])m("start script preload: "+c);e.elem=a;if(H){a.preload=true;a.onpreload=f}else{a.onreadystatechange=function(){if(a.readyState=="loaded")f()}}a.src=c}else if(h&&c.indexOf(F)==0&&d[A]){b=new XMLHttpRequest();if(d[l])m("start script preload (xhr): "+c);b.onreadystatechange=function(){if(b.readyState==4){b.onreadystatechange=function(){};e.text=b.responseText+"\n//@ sourceURL="+c;f()}};b.open("GET",c);b.send()}else{if(d[l])m("start script preload (cache): "+c);a.type="text/cache-script";v(a,e,"ready",function(){i.removeChild(a);f()});a.src=c;i.insertBefore(a,i.firstChild)}}else if(I){if(d[l])m("start script load (ordered async): "+c);a.async=false;v(a,e,"finished",f);a.src=c;i.insertBefore(a,i.firstChild)}else{if(d[l])m("start script load: "+c);v(a,e,"finished",f);a.src=c;i.insertBefore(a,i.firstChild)}},0)}function M(){var o={},T=t||P,q=[],r={},p;o[A]=true;o[B]=false;o[w]=false;o[C]=false;o[l]=false;o[D]="";function U(a,c,b){var d;function g(){if(d!=null){d=null;L(b)}}if(r[c.src].finished)return;if(!a[w])r[c.src].finished=true;d=b.elem||document.createElement("script");if(c.type)d.type=c.type;if(c.charset)d.charset=c.charset;v(d,b,"finished",g);if(b.elem){b.elem=null}else if(b.text){d.onload=d.onreadystatechange=null;d.text=b.text}else{d.src=c.real_src}i.insertBefore(d,i.firstChild);if(b.text){g()}}function V(c,b,d,g){var e,f,h=function(){b.ready_cb(b,function(){U(c,b,e)})},k=function(){b.finished_cb(b,d)};b.src=Q(b.src,c[D]);b.real_src=b.src+(c[C]?((/\?.*$/.test(b.src)?"&_":"?_")+~~(Math.random()*1E9)+"="):"");if(!r[b.src])r[b.src]={items:[],finished:false};f=r[b.src].items;if(c[w]||f.length==0){e=f[f.length]={ready:false,finished:false,ready_listeners:[h],finished_listeners:[k]};S(c,b,e,((g)?function(){e.ready=true;for(var a=0;a<e.ready_listeners.length;a++){e.ready_listeners[a]()}e.ready_listeners=[]}:function(){L(e)}),g)}else{e=f[0];if(e.finished){k()}else{e.finished_listeners.push(k)}}}function x(){var e,f=u(o,{}),h=[],k=0,y=false,n;function W(a,c){if(f[l])m("script preload finished: "+a.real_src);a.ready=true;a.exec_trigger=c;z()}function X(a,c){if(f[l])m("script execution finished: "+a.real_src);a.ready=a.finished=true;a.exec_trigger=null;for(var b=0;b<c.scripts.length;b++){if(!c.scripts[b].finished)return}c.finished=true;z()}function z(){while(k<h.length){if(J(h[k])){if(f[l])m("$LAB.wait() executing: "+h[k]);try{h[k++]()}catch(err){if(f[l])G("$LAB.wait() error caught: ",err)}continue}else if(!h[k].finished){if(R(h[k]))continue;break}k++}if(k==h.length){y=false;n=false}}function Y(){if(!n||!n.scripts){h.push(n={scripts:[],finished:true})}}e={script:function(){for(var g=0;g<arguments.length;g++){(function(a,c){var b;if(!K(a)){c=[a]}for(var d=0;d<c.length;d++){Y();a=c[d];if(J(a))a=a();if(!a)continue;if(K(a)){b=[].slice.call(a);b.unshift(d,1);[].splice.apply(c,b);d--;continue}if(typeof a=="string")a={src:a};a=u(a,{ready:false,ready_cb:W,finished:false,finished_cb:X});n.finished=false;n.scripts.push(a);V(f,a,n,(T&&y));y=true;if(f[B])e.wait()}})(arguments[g],arguments[g])}return e},wait:function(){if(arguments.length>0){for(var a=0;a<arguments.length;a++){h.push(arguments[a])}n=h[h.length-1]}else n=false;z();return e}};return{script:e.script,wait:e.wait,setOptions:function(a){u(a,f);return e}}}p={setGlobalDefaults:function(a){u(a,o);return p},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(){q[q.length]={type:"script",args:[].slice.call(arguments)};return p},queueWait:function(){q[q.length]={type:"wait",args:[].slice.call(arguments)};return p},runQueue:function(){var a=p,c=q.length,b=c,d;for(;--b>=0;){d=q.shift();a=a[d.type].apply(null,d.args)}return a},noConflict:function(){j.$LAB=N;return p},sandbox:function(){return M()}};return p}j.$LAB=M();(function(a,c,b){if(document.readyState==null&&document[a]){document.readyState="loading";document[a](c,b=function(){document.removeEventListener(c,b,false);document.readyState="complete"},false)}})("addEventListener","DOMContentLoaded")})(this); |