Template:UCAS-China/igemUCAS.js

/*!

* igemUCAS JavaScript Library v0.18.17
* Copyright UCAS iGEM team
*/

(function(c,a){var b=c.iU=a(c);b()})(window,function(d){var f=d.document,j=(function(){var n="",o=1,p=function(q,r){n=n.concat(o," ",q,": ",r,"\n");o++},m=function(q){var r={string:function(t){if((!t)||typeof t!="string"){p(q,"parameter should be of .")}return r},number:function(t){if((!t)||typeof t!="number"){p(q,"parameter should be of number type.")}return r},keyUnused:function(t,s){if(t[s]){p(q,"key "+s+" has been used.")}return r},assert:function(t,s){if(!t){p(q,s)}return r}};return r};m.displayErrors=function(){if(n.length==0){alert("No errors, Congrats!")}else{alert(n)}};return m})(),e={SEGW:24,INF:2000000},i={merge:function(n,o){for(var m in o){if(n[m]){if(typeof n[m]=="object"&&typeof o[m]=="object"){n[m]=i.merge(n[m],o[m])}else{n[m]=o[m]}}else{n[m]=o[m]}}return n},getUid:(function(){var m=-1;return function(){m++;return(function(o){return"_"+o+"_"})(m)}})(),realWidth:function(m){return m*d.innerWidth/e.SEGW}};var b={general:{"font-family":"Georgia","font-size":"25px"},span:{},a:{"text-decoration":"none","mouseover":function(){},"mouseleave":function(){}}};function k(n,o,m){this.elem=(typeof n=="string")?f.createElement(n):n;this.elem.id=o||i.getUid();this.elem.style.visibility="hidden";this.span=m;this.styles={};this.iU_base.appendChild(this.elem);this.state="unused"}k.prototype={constructor:k,adaptWidth:function(){var o=i.realWidth(this.span);if(o==this.elem.clientWidth){return this.elem.clientHeight}var n=(this.elem.height||this.elem.clientHeight)/(this.elem.width||this.elem.clientWidth),m=o*n;this.css({width:o+"px",height:m+"px"});return this.elem.clientHeight},updataSchema:function(){this.css(b.general);for(var m in this.elem.childNodes){var o=this.elem.childNodes[m],n=b[(o.tagName||"").toLowerCase()];if(n){k.prototype.css.call(o,n)}}},css:function(p){var o=this.elem||this;if(this.styles){for(var r in this.styles){o.style[r]=this.styles[r]}}for(var r in p){var n="",q=false;for(var m=0;m<r.length;m++){if(r[m]=="-"){q=true}else{n+=q?r[m].toUpperCase():r[m];q=false}}if(typeof p[r]=="function"){o.addEventListener(n,p[r])}else{o.style[n]=p[r]}if(this.styles){this.styles[n]=p[r]}}},render:function(m){this.adaptWidth();this.css({"position":"absolute","left":(m+this.left)+"px","top":this.top+"px","visibility":"visible"})},toString:function(){return"["+this.elem.tagName.toLowerCase()+"] "+this.elem.innerHTML.substr(0,50)+"\n"}};var l={textAdapt:function(){this.css({"width":i.realWidth(this.span)+"px"});return this.elem.clientHeight},upgradeText:function(){for(var n=0,m=this.elem.childNodes.length;n<m;n++){var o=this.elem.childNodes[n];if(!o.attributes){var p=f.createElement("span");p.innerHTML=o.textContent;this.elem.replaceChild(p,o)}}}};function c(m){this.span=m.span;this.padding=m.padding;this.spacing=m.spacing;this.marginCross=m.marginCross;this.marginTop=m.marginTop;this.height=d.innerHeight-m.marginTop-m.marginBottom;this.page=0;this.frontier=0;this.reserve=0;this.usedW=0;this.comps=[];this.buffer=[];this.isVisible=true}c.prototype={constructor:c,operate:function(){var o=false;while(!o&&this.buffer.length>0){switch(this.buffer[0].state){case"wait":o=true;break;case"dispose":this.buffer.shift();break;case"unused":var m=this.buffer.shift(),n=m.adaptWidth();if(this.page==0){this.page=1}else{if(this.usedW==0||this.usedW+m.span>this.span){if(this.frontier+n>this.height){this.page+=1;this.frontier=0}else{this.frontier+=this.spacing}this.reserve=this.frontier;this.usedW=0}}m.left=i.realWidth(this.span*(this.page-1)+this.usedW+this.page*this.padding);m.top=this.reserve+this.marginTop;m.state="used";this.usedW+=m.span;this.frontier=Math.max(this.frontier,this.reserve+n);this.comps.push(m)}}},script:function(o){var n=o["span"]?o["span"].value:this.span;n=(n<0)?(n+this.span):Math.min(n,this.span);var m=new k(o,o["name"],n);l.upgradeText.call(m);m.updataSchema();m.adaptWidth=l.textAdapt;m.adaptWidth();this.buffer.push(m)},hide:function(){if(this.isVisible){for(var n=0,m=this.comps.length;n<m;n++){this.comps[n].elem.style["visibility"]="hidden"}}},getBreadth:function(){return this.page*this.span+(this.page+1)*this.marginCross},render:function(m){this.isVisible=true;for(var o=0,n=this.comps.length;o<n;o++){this.comps[o].render(m)}}};function a(m){this.flows=[]}a.prototype={constructor:a,render:function(r){var v=0,t=[];for(var q=0,u=this.flows.length;q<u;q++){var n=this.flows[q],s=r-v,m=n.getBreadth(),o=d.innerWidth;n.operate();if(s<-m||s>o){n.hide()}else{t.push([n,s])}v+=m}for(var p in t){t[p][0].render(-t[p][1])}return v}};var g={initRoot:function(o){var m=f.getElementById("igemUCAS");if(!m){return null}m.style.visibility="hidden";m.style["z-index"]="-100";if(o){var n=f.getElementsByTagName("html")[0];n.style.overflowX="hidden";n.style.overflowY="hidden";n.style.padding="0px";n.style.margin="0px"}j("fn.initRoot").assert(m,"");return m},initWebGL:function(n){var m=f.createElement("canvas");m.id="bgCanvas";m.width=d.innerWidth;m.height=d.innerHeight; n.parentNode.appendChild(m);var o=m.getContext("webgl")||m.getContext("experimental-webgl");if(o){k.prototype.css.call(m,{"position":"absolute","top":"0","left":"0","z-index":"-90","overflow":"hidden","visibility":"visible"})}return o},initBase:function(m){var n=f.createElement("div");n.id="UCASigem";n.style.position="absolute";m.parentNode.appendChild(n);return n},root_not_found:function(){},gl_not_supported:function(){},defaultConfig:{overflow:true,webgl:true}};function h(){p=i.merge(p,d.schema||{});var s=g.initRoot((d.configs||g.defaultConfig).overflow);if(!s){return g.root_not_found()}var w=g.initBase(s);k.prototype.iU_base=w;var r=(d.configs||g.defaultConfig).webgl||g.initWebGL(s);if(!r){g.gl_not_supported()}var p=i.merge(g.defaultSchema,d.schema||{});c.prototype.schema=p;var v=new a(d.innerHeight);while(s.children.length>0){var t=s.children[0];if((t.tagName||"").toLowerCase()=="div"){var u=t["spacing"]?t["spacing"].value.split(/\t/):"",m=new c({span:t["span"]?t["span"].value:8,padding:t["padding"]?t["padding"].value:1,spacing:parseInt(u[0])||40,marginTop:parseInt(u[1])||100,marginBottom:u[2]?parseInt(u[2]):(parseInt(u[1])||100)});v.flows.push(m);while(t.children.length>0){var o=t.children[0];switch(((o||{}).tagName||"").toLowerCase()){case"p":m.script(o);break;default:t.removeChild(o);break}}}s.removeChild(t)}s.parentNode.removeChild(s);var q=0;var n=function(x){x=x||d.event;q+=x.wheelDelta||x.detail;q=q<0?0:q;v.render(q)};v.render(q);d.onmousewheel=f.onmousewheel=n}h.displayErrors=j.displayErrors;return h});