Team:Grenoble/script
From 2012.igem.org
(Difference between revisions)
Line 139: | Line 139: | ||
return{w:k?Math.round(h):h,h:k?Math.round(g):g} | return{w:k?Math.round(h):h,h:k?Math.round(g):g} | ||
} | } | ||
- | + | var q={ | |
+ | defaults:{ | ||
+ | mode:'max', | ||
+ | enlarge:1, | ||
+ | reduce:1, | ||
+ | ffHack:0, | ||
+ | zIndex:-1, | ||
+ | position:'absolute', | ||
+ | align:'center', | ||
+ | vertAlign:'top', | ||
+ | fadeAfter:400, | ||
+ | fadeOptions:{duration:1000,frameRate:25} | ||
+ | }, | ||
+ | redim:function(){ | ||
+ | var c=q,a,b,d=w(),e,f,j,k,l,i,g,h,m,n; | ||
+ | a=c.img;f=j=k=l=''; | ||
+ | b=c.opt; | ||
+ | i=a.fileDim; | ||
+ | if(i){ | ||
+ | if(b.mode=='full'){ | ||
+ | g=m=d.w; | ||
+ | h=n=d.h; | ||
+ | if(!b.enlarge){ | ||
+ | if(g>i.w){ | ||
+ | g=m=i.w | ||
+ | } | ||
+ | if(h>i.h){ | ||
+ | h=n=i.h | ||
+ | } | ||
+ | } | ||
+ | if(!b.reduce){ | ||
+ | if(m<i.w){ | ||
+ | m=i.w; | ||
+ | g=Math.max(m,g) | ||
+ | } | ||
+ | if(n<i.h){ | ||
+ | n=i.h; | ||
+ | h=Math.max(n,h) | ||
+ | } | ||
+ | } | ||
+ | }else{ | ||
+ | m=g=d.w; | ||
+ | n=h=0; | ||
+ | if(!b.reduce){ | ||
+ | g=0 | ||
+ | } | ||
+ | } | ||
+ | i=A(i.w,i.h,{min_w:m,win_h:n,max_w:g,max_h:h,round:1}); | ||
+ | a.width=i.w; | ||
+ | a.height=i.h; | ||
+ | if(!a.width){ | ||
+ | a.removeAttribute("width") | ||
+ | } | ||
+ | if(!a.height){ | ||
+ | a.removeAttribute("height") | ||
+ | } | ||
+ | switch(b.align){ | ||
+ | case'left':k='0px'; | ||
+ | break; | ||
+ | case'right':l='0px'; | ||
+ | break; | ||
+ | default:k=-Math.round((i.w-d.w)/2)+'px' | ||
+ | } | ||
+ | if(b.vertAlign=='bottom'){ | ||
+ | j='0px' | ||
+ | }else if(b.vertAlign=='middle'){ | ||
+ | e=b.position=="fixed"?d.h:x().h; | ||
+ | f=(-b.ffHack+(e-a.offsetHeight)/2)+"px" | ||
+ | }else{ | ||
+ | f=a.hack||'0px' | ||
+ | } | ||
+ | s(a,{left:k,right:l,top:f,bottom:j}) | ||
+ | } | ||
+ | } | ||
+ | ,show:function(){ | ||
+ | var c=q,a; | ||
+ | a=c.img; | ||
+ | a.fileDim={ | ||
+ | w:a.naturalWidth||a.clientWidth,h:a.naturalHeight||a.clientHeight | ||
+ | }; | ||
+ | c.redim(); | ||
+ | if(c.fadeIt){ | ||
+ | z(c.img,1,0,c.opt.fadeOptions) | ||
+ | }else{ | ||
+ | p(a,1) | ||
+ | } | ||
+ | }, | ||
+ | init:function(c,a){ | ||
+ | var b=q,d=v('body')[0],e,f,j; | ||
+ | a=u(a,this.defaults); | ||
+ | if(t&&t<7){ | ||
+ | a.position='absolute' | ||
+ | } | ||
+ | b.opt=a; | ||
+ | e=a.fadeAfter; | ||
+ | f=b.img=o.createElement('img'); | ||
+ | f.id="bgMax"; | ||
+ | s(f,{zIndex:a.zIndex,position:a.position}); | ||
+ | j=navigator.userAgent.match(/Firefox.(\d+(\.\d+))/); | ||
+ | if(j&&parseFloat(j[1])<3){ | ||
+ | s(d,{zIndex:0,position:'relative',top:0,left:0}); | ||
+ | f.hack='-'+a.ffHack}d.insertBefore(f,d.childNodes[0]); | ||
+ | f.onload=b.show; | ||
+ | if(e!==false){ | ||
+ | p(f,0); | ||
+ | if(e){ | ||
+ | setTimeout(function(){b.fadeIt=1},e) | ||
+ | }else{ | ||
+ | b.fadeIt=1 | ||
+ | } | ||
+ | } | ||
+ | y(r,'resize',b.redim); | ||
+ | f.src=c | ||
+ | } | ||
+ | }; | ||
+ | r.bgMax=q | ||
}) | }) | ||
(window,document); | (window,document); |
Revision as of 10:03, 12 July 2012