Mercurial > hg > Members > nobuyasu > Consensus
view public/viewer/form.js @ 114:2c280381bd53 draft
create traverse function
author | Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 18 Mar 2013 05:42:11 +0900 |
parents | a76259e2ca9f |
children |
line wrap: on
line source
/**/(function(){/**/ function $(id){return document.getElementById(id)} var popupInfo; function popupInit(a,b,w,h,dx,dy,callback){ popupInfo={ w:w,h:h,dx:dx,dy:dy, main:{obj:a,pos:{x:0,y:0,z:0,opacity:0}}, sub:{obj:b,pos:{x:0,y:0,z:0,opacity:0}}, count:1,time:0,callback:callback }; } function cbfunc(main,sub,zm,zs){ var cm=main.getElementsByClassName("cover")[0]; var cs=sub.getElementsByClassName("cover")[0]; cm.style.opacity=(1-zm)/2;cm.style.display=zm==1?'none':'block' cs.style.opacity=(1-zs)/2;cs.style.display=zs==1?'none':'block' main.style.boxShadow=zm?"0 0 "+Math.floor(zm*50)+"px white":"none"; sub.style.boxShadow=zs?"0 0 "+Math.floor(zs*50)+"px white":"none"; } window.popupInit=init; function init(){ popupInit($('claiminfo'),$('mentioninfo'),600,400,650,-200,cbfunc); $('claim_cover').onclick=function(){popupShowMainSub();} $('mention_cover').onclick=function(){popupShowSubMain();} $('popup_background').onclick=function(){popupHideAll();} } window.popupShowMain=popupShowMain; function popupShowMain(){ with(popupInfo){ if(main.pos.opacity==0&&sub.pos.opacity==0)main.pos={x:0,y:0,z:1,opacity:0} if(main.pos.z==0&&main.pos.opacity==0)main.pos.z=1; popupGoto({x:0,y:0,z:1,opacity:1},{x:sub.pos.x,y:sub.pos.y,z:sub.pos.z,opacity:0}) } } window.popupShowMainSub=popupShowMainSub; function popupShowMainSub(){ with(popupInfo){ if(main.pos.opacity==0)main.pos={x:0,y:0,z:1,opacity:0} if(sub.pos.opacity==0)sub.pos={x:100,y:-100,z:0,opacity:0} popupGoto({x:0,y:0,z:1,opacity:1},{x:100,y:-100,z:0,opacity:1}) } } window.popupShowSubMain=popupShowSubMain; function popupShowSubMain(){ with(popupInfo){ if(main.pos.opacity==0)main.pos={x:100,y:-100,z:0,opacity:0} if(sub.pos.opacity==0)sub.pos={x:0,y:0,z:1,opacity:0} popupGoto({x:100,y:-100,z:0,opacity:1},{x:0,y:0,z:1,opacity:1}) } } window.popupHideAll=popupHideAll; function popupHideAll(){ with(popupInfo){ popupGoto({x:main.pos.x,y:main.pos.y,z:main.pos.z,opacity:0},{x:sub.pos.x,y:sub.pos.y,z:sub.pos.z,opacity:0}) } } function popupGoto(mainpos,subpos){ if(popupInfo.count!=1)return; popupInfo.count=0; popupInfo.main.nextpos=mainpos; popupInfo.sub.nextpos=subpos; popupInfo.time=new Date(); popupFunc(); } function popupFunc(){ popupInfo.count=(new Date()-popupInfo.time)/500; if(popupInfo.count>1)popupInfo.count=1; var t=popupInfo.count; t=2*t-t*t; with(popupInfo){ var d=main.pos.opacity&&sub.pos.opacity&&main.nextpos.opacity&&sub.nextpos.opacity?1:0; var md=(main.pos.z-main.nextpos.z)*d; var mx=main.pos.x*(1-t)+t*main.nextpos.x+md*dx*2*t*(1-t); var my=main.pos.y*(1-t)+t*main.nextpos.y+md*dy*t*(1-t); var sd=(sub.pos.z-sub.nextpos.z)*d; var sx=sub.pos.x*(1-t)+t*sub.nextpos.x+sd*dx*2*t*(1-t); var sy=sub.pos.y*(1-t)+t*sub.nextpos.y+sd*dy*2*t*(1-t); main.obj.style.left=mx-w/2; main.obj.style.top=my-h/2; sub.obj.style.left=sx-w/2; sub.obj.style.top=sy-h/2; main.obj.style.zIndex=(t<0.5?main.pos.z:main.nextpos.z)*10+10; sub.obj.style.zIndex=(t<0.5?sub.pos.z:sub.nextpos.z)*10+10; var am=main.obj.style.opacity=(main.pos.opacity?1:0)*(1-t)+t*(main.nextpos.opacity?1:0); var as=sub.obj.style.opacity=(sub.pos.opacity?1:0)*(1-t)+t*(sub.nextpos.opacity?1:0); main.obj.style.display=am?"block":"none"; sub.obj.style.display=as?"block":"none"; var amax=am<as?as:am; $("popup_base").style.opacity=amax; $("popup_base").style.display=amax?"block":"none"; callback(main.obj,sub.obj,main.pos.z*(1-t)+t*main.nextpos.z,sub.pos.z*(1-t)+t*sub.nextpos.z); if(popupInfo.count==1){ main.pos=main.nextpos; sub.pos=sub.nextpos; if(popupInfo.main.opacity==0&&popupInfo.sub.opacity==0){ popupInfo.main.pos={x:0,y:0,z:0,opacity:0} popupInfo.sub.pos={x:0,y:0,z:0,opacity:0} } }else setTimeout(popupFunc,10); } } /**/})()/**/ function HashSet(arr){ if(arr)for(var i=0;i<arr.length;i++)this['#'+arr[i]]=true; } HashSet.prototype.add=function(name){this['#'+name]=true;} HashSet.prototype.remove=function(name){delete this['#'+name];} HashSet.prototype.toArray=function(){ var arr=[]; for(var i in this)if(i[0]=='#')arr.push(i.substr(1)); return arr.sort(); } function createUserSelectItem(name,status,map){ var div=createUserElement(name,status); div.css("display","inline-block"); var selected=status; if(!status)status="unknown" div.click(function(){ selected=selected?"":status; if(!selected){map.remove(name);div.css("opacity",0.4);} else{map.add(name);div.css("opacity",1);$(div[0].firstChild).css("background",userStatusBackgroundColor[selected]||'black');} }); return div; } var userStatusBackgroundColor={agreed:"url(agreed.png)",denied:"url(denied.png)",author:"url(author.png)",unknown:"url(unknown.png)",pend:"url(pend.png)"}; function createUserElement(user,status){ var div=$("<div class='userItem'><div class='userStatus'></div><div></div></div>"); $(div[0].lastChild).text(user); div.css("cursor","pointer") if(!status)div.css("opacity",0.4); $(div[0].firstChild).css("background",userStatusBackgroundColor[status]||"gray"); return div; }