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.
 
 
 
 

1 lines
5.8 KiB

!function(){var e={name:"oojs",namespace:"",$oojs:function(){if(Function.prototype.proxy=function(){var e=this,t=Array.prototype.slice.apply(arguments),n=t.shift();return function(){var s=Array.prototype.slice.apply(arguments);return e.apply(n,s.concat(t))}},"undefined"!=typeof window)this.global=window,this.runtime="browser",this.basePath="http://cpro.baidustatic.cn/js/",this.version="1.0.0",this.global.oojs=e,this.global.define=this.define.proxy(this);else if(global){var t=require("path");this.basePath=t.resolve(__dirname,"../../../src")+"/",this.global=global,this.runtime="nodejs",global.oojs=e,global.define=this.define.proxy(this);var n=module.constructor,s=n.wrap;n.wrap=function(e){return e=e.replace(/define\s*&&\s*define\s*\(/gi,"define(module,"),s(e)},module.exports=this}},fastClone:function(e){var t=function(){};t.prototype=e;var n=new t;return n},create:function(e){var t=Array.prototype.slice.call(arguments,0);t.shift();var n=e.name||"init",s=function(e){this[n]=this[n]||function(){},this[n].apply(this,e)};s.prototype=e;var i=new s(t);i.dispose=i.dispose||function(){},"browser"===this.runtime&&(window.addEventListener?window.addEventListener("unload",i.dispose.proxy(i),!1):window.attachEvent&&window.attachEvent("onunload",i.dispose.proxy(i)));for(var r in e){var a=e[r];a&&e.hasOwnProperty(r)&&"object"==typeof a&&(i[r]=this.fastClone(a))}return i.instances=null,i},define:function(e,t){t||(t=e);var n=t.name;t.namespace=t.namespace||"",t.dispose=t.dispose||function(){};var s=t.namespace.split("."),i="nodejs";"undefined"!=typeof window&&(global=window,i="browser");for(var r,a=s.length,o=global,l=0;a>l;l++)r=s[l],r&&(o[r]=o[r]||{},o=o[r]);if(o[n]=o[n]||{},o[n].name&&o[n].___registered){if(o[n].___registered&&t.classType&&"extend"===t.classType){for(var u in t)u&&t.hasOwnProperty(u)&&(o[n][u]=t[u]);t=o[n]}}else t.___registered=!0,o[n]=t;if(this.loadDeps&&t&&t.deps)this.loadDeps(t);else{var c="$"+n;t[c]&&t[c]()}return e&&(e.exports=t),this},find:function(e){var t,n=e.split(".");t=this.global[n[0]];for(var s=1,i=n.length;i>s;s++){if(!t||!t[n[s]]){t=null;break}t=t[n[s]]}return t},using:function(e){var t=this.find(e);return t||"nodejs"===this.runtime&&(require(this.getClassPath(e)),t=this.find(e)),t},getClassPath:function(e){return this.basePath+e.replace(/\./gi,"/")+".js"},config:function(e){return this.basePath=e.basePath||this.basePath,this}};e.define("undefined"!=typeof module?module:null,e)}(),define&&define({name:"event",namespace:"oojs",eventList:null,groupList:null,eventGroupIndexer:null,$event:function(){},event:function(){this.eventList={},this.groupList={},this.eventGroupIndexer={}},bind:function(e,t){var n=this.eventList[e]=this.eventList[e]||{};return(n.callbacks=n.callbacks||[]).push(t),n.status=!1,this},removeListener:function(e,t){if(this.eventList[e]){var n=this.eventList[e];if(n.callbacks&&n.callbacks.length)for(var s=0,i=n.callbacks.length;i>s;s++)if(t){if(t===n.callbacks[s]){n.callbacks[s]=null;break}}else n.callbacks[s]=null}},unbind:function(e,t){if(e||t)this.removeListener(e,t);else{var n;for(n in this.eventList)n&&this.eventList[n]&&this.eventList.hasOwnProperty(n)&&this.removeListener(n)}},emit:function(e,t){var n=this.eventList[e];if(n&&n.callbacks&&n.callbacks.length){var s=n.callbacks.length;n.data=[];for(var i=0;s>i;i++){var r=n.callbacks[i];r&&n.data.push(r(t))}n.callbacks=null,n.status=!0}for(var a,o=this.eventGroupIndexer[e]||[],i=0,l=o.length;l>i;i++)a=o[i],a&&this.groupEmit(a)},group:function(e,t,n){this.groupList[e]=this.groupList[e]||{};var s=this.groupList[e],i=s.events=s.events||{};n&&(s.callbacks=s.callbacks||[]).push(n);for(var r,t=t||[],a=0,o=t.length;o>a;a++)r=t[a],i[r]=1,(this.eventGroupIndexer[r]=this.eventGroupIndexer[r]||[]).push(e)},groupEmit:function(e){var t=this.groupList[e];if(t){var n,s,i=t.events=t.events||{},r=!0,a={};for(n in i)if(n&&i.hasOwnProperty(n)){if(s=this.eventList[n],!s||!s.status){r=!1,a=null;break}a[n]=s.data}if(n=null,r){t.callbacks=t.callbacks||[];for(var o,l=t.callbacks,u=l.length||0,c=0;u>c;c++)o=t.callbacks[c],o&&(o(a),t.callbacks[c]=null);o=null,t.callbacks=null;for(var h,f=t.afters=t.afters||[],u=f.length||0,c=0;u>c;c++)h=f[c],h&&(h(a),f[c]=null);h=null,t.afters=null}}},afterGroup:function(e,t){var n=this.groupList[e]=this.groupList[e]||{},s=n.afters=n.afters||[];s.push(t)}}),define&&define({name:"oojs",namespace:"",classType:"extend",$oojs:function(){this.ev=oojs.create(oojs.event)},isNullObj:function(e){for(var t in e)if(e.hasOwnProperty(t))return!1;return!0},loadScript:function(e,t,n){if("function"==typeof t&&(n=t,t="1.0.0"),t=t||"1.0.0",e.indexOf("http")<0&&(e=this.basePath+e.replace(/\./g,"/")+".js"),t&&(e+="?v="+t),n=n||function(){},this.ev.bind(e,function(e,t){t&&t()}.proxy(this,n)),this.loading=this.loading||{},!this.loading[e]){this.loading[e]=1;var s=document.createElement("script");s.type="text/javascript",s.async=!0,s.src=e,s.onload=s.onerror=s.onreadystatechange=function(e,t,n){"string"==typeof e&&(t=e,n=t),/loaded|complete|undefined/.test(n.readyState)&&(n.onload=n.onerror=n.onreadystatechange=null,n=void 0,this.ev.emit(t,1))}.proxy(this,e,s);var i=document.getElementsByTagName("script")[0];return i.parentNode.insertBefore(s,i),this}},loadDeps:function(e){var t=e.deps,n="$"+e.name;if("nodejs"===this.runtime){var t=e.deps;for(var s in t)s&&t.hasOwnProperty(s)&&(e[s]=require(this.getClassPath(t[s])));e[n]&&e[n]()}else if(this.isNullObj(t))e[n]&&e[n]();else for(var s in t)if(s&&t.hasOwnProperty(s)){var i=t[s],r=this.using(i);if(r){e[s]=r;continue}this.ev.bind(i,function(e,t){return oojs.using(t)}.proxy(this,i)),this.ev.group("loadDeps",[i],function(e,t,n,s){s[t]=e[n][0]}.proxy(this,s,i,e)),this.ev.afterGroup("loadDeps",function(){var t="$"+e.name;e[t]&&e[t]()}.proxy(this,e));var a=this.basePath+i.replace(/\./gi,"/")+".js",o=function(e){this.ev.emit(e)}.proxy(this,i);this.loadScript(a,o)}return this}});