Template:UCAS-China/igemUCAS.js

/*!

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

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