You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
7.3 KiB
77 lines
7.3 KiB
6 years ago
|
/*! LAB.js (LABjs :: Loading And Blocking JavaScript)
|
||
|
v2.0.3 (c) Kyle Simpson
|
||
|
MIT License
|
||
|
https://www.cnblogs.com/zichi/p/4689008.html
|
||
|
*/
|
||
|
(function(o){var K=o.$LAB,y="UseLocalXHR",z="AlwaysPreserveOrder",u="AllowDuplicates",A="CacheBust",B="BasePath",C=/^[^?#]*\//.exec(location.href)[0],D=/^\w+\:\/\/\/?[^\/]+/.exec(C)[0],i=document.head||document.getElementsByTagName("head"),L=(o.opera&&Object.prototype.toString.call(o.opera)=="[object Opera]")||("MozAppearance" in document.documentElement.style),q=document.createElement("script"),E=typeof q.preload=="boolean",r=E||(q.readyState&&q.readyState=="uninitialized"),F=!r&&q.async===true,M=!r&&!F&&!L;function G(a){return Object.prototype.toString.call(a)=="[object Function]"}function H(a){return Object.prototype.toString.call(a)=="[object Array]"}function N(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)=="/"?D:C)+a)}function s(a,c){for(var b in a){if(a.hasOwnProperty(b)){c[b]=a[b]}}return c}function O(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 t(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 I(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 P(d,f,e,g,h){setTimeout(function(){var a,c=f.real_src,b;if("item" in i){if(!i[0]){setTimeout(arguments.callee,25);return}i=i[0]}a=document.createElement("script");if(f.type){a.type=f.type}if(f.charset){a.charset=f.charset}if(h){if(r){e.elem=a;if(E){a.preload=true;a.onpreload=g}else{a.onreadystatechange=function(){if(a.readyState=="loaded"){g()}}}a.src=c}else{if(h&&c.indexOf(D)==0&&d[y]){b=new XMLHttpRequest();b.onreadystatechange=function(){if(b.readyState==4){b.onreadystatechange=function(){};e.text=b.responseText+"\n//@ sourceURL="+c;g()}};b.open("GET",c);b.send()}else{a.type="text/cache-script";t(a,e,"ready",function(){i.removeChild(a);g()});a.src=c;i.insertBefore(a,i.firstChild)}}}else{if(F){a.async=false;t(a,e,"finished",g);a.src=c;i.insertBefore(a,i.firstChild)}else{t(a,e,"finished",g);a.src=c;i.insertBefore(a,i.firstChild)}}},0)}function J(){var l={},Q=r||M,n=[],p={},m;l[y]=true;l[z]=false;l[u]=false;l[A]=false;l[B]="";function R(a,c,b){var d;function f(){if(d!=null){d=null;I(b)}}if(p[c.src].finished){return}if(!a[u]){p[c.src].finished=true}d=b.elem||document.createElement("script");if(c.type){d.type=c.type}if(c.charset){d.charset=c.charset}t(d,b,"finished",f);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){f()}}function S(c,b,d,f){var e,g,h=function(){b.ready_cb(b,function(){R(c,b,e)})},j=function(){b.finished_cb(b,d)};b.src=N(b.src,c[B]);b.real_src=b.src+(c[A]?((/\?.*$/.test(b.src)?"&_":"?_")+~~(Math.random()*1000000000)+"="):"");if(!p[b.src]){p[b.src]={items:[],finished:false}}g=p[b.src].items;if(c[u]||g.length==0){e=g[g.length]={ready:false,finished:false,ready_listeners:[h],finished_listeners:[j]};P(c,b,e,((f)?function(){e.ready=true;for(var a=0;a<e.ready_listeners.length;a++){e.ready_listeners[a]()}e.ready_listeners=[]}:function(){I(e)}),f)}else{e=g[0];if(e.finished){j()}else{e.finished_listeners.push(j)}}}function v(){var e,g=s(l,{}),h=[],j=0,w=false,k;function T(a,c){a.ready=true;a.exec_trigger=c;x()}function U(a,c){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;x()}function x(){while(j<h.length){if(G(h[j])){try{h[j++]()}catch(err){}continue}else{if(!h[j].finished){if(O(h[j])){continue}break}}j++}if(j==h.length){w=false;k=false}}function V(){if(!k||!k.scripts){h.push(k={scripts:[],finished:true})}}e={script:function(){for(var f=0;f<arguments.length;f++){(function(a,c){var b;if(!H(a)){c=[a]}for(var d=0;d<c.length;d++){V();a=c[d];if(G(a)){a=a()}if(!a){continue}if(H(a)){b=[].slice.call(a);b.unshift(
|
||
|
for(;--b>=0;){d=n.shift();a=a[d.type].apply(null,d.args)}return a},noConflict:function(){o.$LAB=K;return m},sandbox:function(){return J()}};return m}o.$LAB=J();(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);
|
||
|
|
||
|
|
||
|
var lib = (function () {
|
||
|
// 始终需要加载的js
|
||
|
var alwaysLoadJs = [
|
||
|
'../../assets/lib/jquery/3.2.1/jquery.min.js'
|
||
|
,'../../assets/lib/layui/layui.js'
|
||
|
,'../../assets/lib/easyopen/sdk.js'
|
||
|
,'../../assets/js/ApiUtil.js'
|
||
|
,'../../assets/js/common.js'
|
||
|
]
|
||
|
|
||
|
var jsArr = [];
|
||
|
|
||
|
/**
|
||
|
* 加载js
|
||
|
* @param jsArr js路径数组,存放js路径
|
||
|
* @param require layui依赖模块
|
||
|
* @param loadSuccess 加载成功后触发
|
||
|
*/
|
||
|
function layuiInit(jsArr, require, loadSuccess) {
|
||
|
// 接着加载自定义的js
|
||
|
jsArr = addVersion(jsArr);
|
||
|
|
||
|
$LAB
|
||
|
.script(alwaysLoadJs) // 先加载全局js
|
||
|
.wait() // 执行加载
|
||
|
.script(jsArr) // 接着加载自定义的js
|
||
|
// 全部加载成后执行
|
||
|
.wait(function () {
|
||
|
layui.use(require, loadSuccess);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 给js添加版本号,防止缓存
|
||
|
* @param jsArr js路径数组
|
||
|
*/
|
||
|
function addVersion(jsArr) {
|
||
|
if (typeof jsArr === 'string') {
|
||
|
jsArr = [jsArr];
|
||
|
}
|
||
|
var v = new Date().getTime();
|
||
|
for (var i = 0; i < jsArr.length; i++) {
|
||
|
jsArr[i] = jsArr[i] + '?v=' + (v++);
|
||
|
}
|
||
|
return jsArr;
|
||
|
}
|
||
|
|
||
|
return {
|
||
|
/**
|
||
|
* 加载js模块
|
||
|
* @param jsPath js相对路径,针对于使用页面。可以是字符串,也可以是数组
|
||
|
* @returns {lib}
|
||
|
*/
|
||
|
importJs: function (jsPath) {
|
||
|
jsArr = jsPath || [];
|
||
|
return this;
|
||
|
}
|
||
|
/**
|
||
|
* layui初始化,同layui.use()
|
||
|
* @param require
|
||
|
* @param loadSuccess
|
||
|
*/
|
||
|
, use: function (require, loadSuccess) {
|
||
|
layuiInit(jsArr, require, loadSuccess);
|
||
|
}
|
||
|
}
|
||
|
})();
|