tuzhu_req.js 实现仿百度图片首页效果
tuzhu_req.js处理文件请求加载异步同步功能,仿效百度图片首页效果制作
/*土著人开发的require组件@土著人(http://www.tuzhuren.com)*/ !function(){ functione(){} Function.prototype.bind||(Function.prototype.bind=function(t){ varn=this; if("function"!=typeofn) thrownewTypeError("Function.prototype.bindcalledonincompatible"+n); varo=r.call(arguments,1), i=function(){ if(thisinstanceofi){ vare=n.apply(this,o.concat(r.call(arguments))); returnObject(e)===e?e:this; } returnn.apply(t,o.concat(r.call(arguments))); }; returnn.prototype&&(e.prototype=n.prototype,i.prototype=newe,e.prototype=null),i; }); vart=Array.prototype, r=t.slice; }(); varrequire,define; !function(e){ functiont(e,t){ if(!(einu)){ u[e]=!0; varr=document.createElement("script"); if(t){ varo=setTimeout(t,require.timeout); r.onerror=function(){ clearTimeout(o),t() },r.onreadystatechange=function(){ "complete"==this.readyState&&clearTimeout(o) } } returnr.type="text/javascript",r.src=e,n.appendChild(r),r; } } functionr(e,r,n){ vari=o[e]||(o[e]=[]); i.push(r); vara,u=c[e]||{}, s=u.pkg; a=s?p[s].url:u.url||e,t(a,n&&function(){ n(e); }); } functionisFunction(it){ returnObject.prototype.toString.call(it)==='[objectFunction]'; } functionisArray(it){ returnObject.prototype.toString.call(it)==='[objectArray]'; } varn=document.getElementsByTagName("head")[0], o={}, i={}, a={}, u={}, c={}, p={}; define=function(name,deps,callback){ if(isArray(deps)&&isFunction(callback)){ deps=callback; } i[name]=deps; varr=o[e]; if(r){ for(varn=0,a=r.length;a>n;++n) r[n](); deleteo[name]; } },require=function(e){ e=require.alias(e); vart=a[e]; if(t) returnt.exports; varr=i[e]; if(!r) returnfalse; t=a[e]={ exports:{} }; varn="function"==typeofr?r.apply(t,[require,t.exports,t]):r; returnn&&(t.exports=n),t.exports; },require.async=function(t,n,o){ functiona(e){ for(vart=e.length-1;t>=0;--t){ varn=e[t], p=c[n]; p&&"deps"inp&&a(p.deps),nini||nins||(s[n]=!0,l++,r(n,u,o)); } } functionu(){ if(0==l--){ varr,o,i=[]; for(r=0,o=t.length;o>r;++r) try{ i[r]=require(t[r]) }catch(a){} n&&n.apply(e,i); } } "string"==typeoft&&(t=[t]); for(varp=t.length-1;p>=0;--p) t[p]=require.alias(t[p]); vars={}, l=0; a(t),u(); },require.resourceMap=function(e){ vart,r; r=e.res; for(tinr) r.hasOwnProperty(t)&&(c[t]=r[t]); r=e.pkg; for(tinr) r.hasOwnProperty(t)&&(p[t]=r[t]); },require.loadJs=function(e){ t(e); },require.loadCss=function(e){ if(e.content){ vart=document.createElement("style"); t.type="text/css",t.styleSheet?t.styleSheet.cssText=e.content:t.innerHTML=e.content,n.appendChild(t); }elseif(e.url){ varr=document.createElement("link"); r.href=e.url,r.rel="stylesheet",r.type="text/css",n.appendChild(r); } },require.alias=function(e){ returne },require.timeout=5e3,define.amd={ jQuery:!0, version:"1.0.0" } }(this); !function(){ (function(){ varwidgets=[], nameIdxMap={}, callbacks=[], remainings=0; require.widget={ register:function(name){ varidx=nameIdxMap[name]; if(idx==undefined){ nameIdxMap[name]=widgets.length; widgets.push(1); remainings++; }else{ widgets[idx]++; } }, ready:function(callback,ctx){ callbacks.push({ func:callback, context:ctx }); if(remainings<1){ _ready(); } }, loaded:function(name){ varidx=nameIdxMap[name], num=widgets[idx]-1; widgets[idx]=num; if(num==0&&remainings){ remainings--; } if(remainings<1){ _ready(); } } }; function_ready(){ varcallback; while(callback=callbacks.pop()){ callback.func.call(callback.ctx); } } })(); }();
希望本文能够给大家学习使用javascript处理文件请求加载异步同步功能有所帮助。