欢迎来到福编程网,本站提供各种互联网专业知识!

Highslide JS

发布时间:2007-05-29 作者: 来源:转载
/******************************************************************************Name:HighslideJSVersion:3.1.0(March12007)Author:TorsteinH鴑siSupport:http://vikjavev.no/highslide/forumEmail:Seehttp://vikjavev.no/megsjolLicence:HighslideJSisli
/******************************************************************************
Name:HighslideJS
Version:3.1.0(March12007)
Author:TorsteinH鴑si
Support:http://vikjavev.no/highslide/forum
Email:Seehttp://vikjavev.no/megsjol

Licence:
HighslideJSislicensedunderaCreativeCommonsAttribution-NonCommercial2.5
License(http://creativecommons.org/licenses/by-nc/2.5/).

Youarefree:
*tocopy,distribute,display,andperformthework
*tomakederivativeworks

Underthefollowingconditions:
*Attribution.Youmustattributetheworkinthemannerspecifiedbythe
authororlicensor.
*Noncommercial.Youmaynotusethisworkforcommercialpurposes.

*Foranyreuseordistribution,youmustmakecleartoothersthelicense
termsofthiswork.
*Anyoftheseconditionscanbewaivedifyougetpermissionfromthe
copyrightholder.

Yourfairuseandotherrightsareinnowayaffectedbytheabove.
******************************************************************************/

varhs={

//Applyyourownsettingshere,oroverridetheminthehtmlfile.
graphicsDir:'highslide/graphics/',
restoreCursor:"zoomout.cur",//necessaryforpreload
fullExpandIcon:'fullexpand.gif',
expandSteps:10,//numberofstepsinzoom.Eachsteplastsforduration/stepmilliseconds.
expandDuration:250,//milliseconds
restoreSteps:10,
restoreDuration:250,
allowMultipleInstances:true,
hideThumbOnExpand:true,
captionSlideSpeed:1,//setto0todisableslideineffect
outlineWhileAnimating:0,//notrecommended,animationgetsjaggyonslowsystems.
outlineStartOffset:3,//endsat10
marginLeft:10,
marginRight:35,//leaveroomforscrollbars+outline
marginTop:10,
marginBottom:35,//leaveroomforscrollbars+outline
zIndexCounter:1001,//adjusttootherabsolutelypositionedelements
fullExpandTitle:'放大到实际尺寸',
restoreTitle:'单击可关闭图片,本窗口可拖动。使用←→键察看上一图或下一图片。',
focusTitle:'切换到这幅图片',
loadingText:'loading...',
loadingTitle:'点击关闭',
loadingOpacity:0.75,
showCredits:false,//youcansetthistofalseifyouwant
creditsText:'PoweredbyHighslideJS',
creditsHref:'http://vikjavev.no/highslide/?user=1',
creditsTitle:'GototheHighslideJShomepage',

//Thesesettingscanalsobeoverriddeninlineforeachimage
anchor:'auto',//wheretheimageexpandsfrom
align:'auto',//positionintheclient(overridesanchor)
captionId:null,
captionTemplateId:null,
slideshowGroup:null,//definesgroupsfornext/previouslinksandkeystrokes
spaceForCaption:30,//leavesspacebelowimageswithcaptions
minWidth:200,
minHeight:200,
allowSizeReduction:true,//allowtheimagetoreducetofitclientsize.Iffalse,thisoverridesminWidthandminHeight
outlineType:'drop-shadow',//setnulltodisableoutlines
wrapperClassName:null,//forenhancedcss-control
enableKeyListener:true,


//ENDOFYOURSETTINGS


//declareinternalproperties
preloadTheseImages:newArray(),
continuePreloading:true,
expandedImagesCounter:0,
expanders:newArray(),
overrides:newArray(
'anchor',
'align',
'outlineType',
'outlineWhileAnimating',
'spaceForCaption',
'wrapperClassName',
'minWidth',
'minHeight',
'captionId',
'captionTemplateId',
'allowSizeReduction',
'slideshowGroup',
'enableKeyListener'
),
overlays:newArray(),
toggleImagesGroup:null,
pendingOutlines:newArray(),

//dragfunctionality
ie:(document.all&&!window.opera),
safari:navigator.userAgent.indexOf("Safari")!=-1,
hasFocused:false,

$:function(id){
returndocument.getElementById(id);
},

push:function(arr,val){
arr[arr.length]=val;
},

createElement:function(tag,attribs,styles,parent){
varel=document.createElement(tag);
if(attribs)hs.setAttribs(el,attribs);
if(styles)hs.setStyles(el,styles);
if(parent)parent.appendChild(el);
returnel;
},

setAttribs:function(el,attribs){
for(varxinattribs){
el[x]=attribs[x];
}
},

setStyles:function(el,styles){
for(varxinstyles){
try{el.style[x]=styles[x];}
catch(e){}
}
},

ieVersion:function(){
arr=navigator.appVersion.split("MSIE");
returnparseFloat(arr[1]);
},

clientInfo:function(){
variebody=(document.compatMode&&document.compatMode!="BackCompat")
?document.documentElement:document.body;

this.width=hs.ie?iebody.clientWidth:self.innerWidth;
this.height=hs.ie?iebody.clientHeight:self.innerHeight;
this.scrollLeft=hs.ie?iebody.scrollLeft:pageXOffset;
this.scrollTop=hs.ie?iebody.scrollTop:pageYOffset;
},

position:function(el){
varparent=el;
varp=Array();
p.x=parent.offsetLeft;
p.y=parent.offsetTop;
while(parent.offsetParent){
parent=parent.offsetParent;
p.x+=parent.offsetLeft;
p.y+=parent.offsetTop;
}
returnp;
},

expand:function(a,params,contentType){
try{
newHsExpander(a,params,contentType);
returnfalse;

}catch(e){
returntrue;
}

},

focusTopmost:function(){
vartopZ=0;
vartopmostKey=-1;
for(i=0;iif(hs.expanders[i]){
if(hs.expanders[i].wrapper.style.zIndex&&hs.expanders[i].wrapper.style.zIndex>topZ){
topZ=hs.expanders[i].wrapper.style.zIndex;

topmostKey=i;
}
}
}
if(topmostKey==-1)hs.focusKey=-1;
elsehs.expanders[topmostKey].focus();
},


closeId:function(elId){//fortextlinks
for(i=0;iif(hs.expanders[i]&&(hs.expanders[i].thumb.id==elId||hs.expanders[i].a.id==elId)){
hs.expanders[i].doClose();
return;
}
}
},

close:function(el){
varkey=hs.getWrapperKey(el);
if(hs.expanders[key])hs.expanders[key].doClose();
returnfalse;
},


toggleImages:function(closeId,expandEl){
if(closeId)hs.closeId(closeId);
if(hs.ie)expandEl.href=expandEl.href.replace('about:(blank)?','');//mysteriousIEthing
hs.toggleImagesExpandEl=expandEl;
returnfalse;
},

getAdjacentAnchor:function(key,op){
varaAr=document.getElementsByTagName('A');
varhsAr=newArray;
varactiveI=-1;
varj=0;
for(i=0;iif(hs.isHsAnchor(aAr[i])&&((hs.expanders[key].slideshowGroup==hs.getParam(aAr[i],'slideshowGroup')))){
hsAr[j]=aAr[i];
if(hs.expanders[key]&&aAr[i]==hs.expanders[key].a){
activeI=j;
}
j++;
}
}
returnhsAr[activeI+op];

},

getParam:function(a,param){
try{
vars=a.onclick.toString();
varoneLine=s.replace(/s/g,'');
varsParams=oneLine.replace(/.*?hs.(htmlE|e)xpands*?(s*?thiss*?,s*?{(.*?)}.*?$/,'$2');
if(hs.safari){//stupidbug
for(vari=0;isParams=sParams.replace(hs.overrides[i]+':',','+hs.overrides[i]+':').replace(/^s*?,/,'');
}
}
if(oneLine==sParams)returnnull;
eval('vararr={'+sParams+'};');
for(varxinarr){
if(x==param)returnarr[x];
}
}catch(e){
returnnull;
}
},

getSrc:function(a){
varsrc=hs.getParam(a,'src');
if(src)returnsrc;
returna.rel.replace(/_slash_/g,'/')||a.href;
},

previousOrNext:function(el,op){
if(typeofel=='object')varactiveKey=hs.getWrapperKey(el);
elseif(typeofel=='number')varactiveKey=el;
if(hs.expanders[activeKey]){
hs.toggleImagesExpandEl=hs.getAdjacentAnchor(activeKey,op);
hs.expanders[activeKey].doClose();
}

returnfalse;
},

previous:function(el){
returnhs.previousOrNext(el,-1);
},

next:function(el){
returnhs.previousOrNext(el,1);
},

keyHandler:function(e){
if(!e)e=window.event;
if(!e.target)e.target=e.srcElement;//ie
if(e.target.form)return;//formelementhasfocus

varop=null;
switch(e.keyCode){
case34://PageDown
case39://Arrowright
case40://Arrowleft
op=1;
break;
case33://PageUp
case37://Arrowleft
case38://Arrowdown
op=-1;
break;
case27://Escape
case13://Enter
if(hs.expanders[hs.focusKey])hs.expanders[hs.focusKey].doClose();
returnfalse;
}
if(op!=null){
hs.removeEventListener(document,'keydown',hs.keyHandler);
if(hs.expanders[hs.focusKey]&&!hs.expanders[hs.focusKey].enableKeyListener)returntrue;
returnhs.previousOrNext(hs.focusKey,op);
}
elsereturntrue;
},

registerOverlay:function(overlay){
hs.push(hs.overlays,overlay);
},

getWrapperKey:function(el){
varkey=-1;
while(el.parentNode){
el=el.parentNode;
if(el.id&&el.id.match(/^highslide-wrapper-[0-9]+$/)){
key=el.id.replace(/^highslide-wrapper-([0-9]+)$/,"$1");
break;
}
}
returnkey;
},

cleanUp:function(){
if(hs.toggleImagesExpandEl){
hs.toggleImagesExpandEl.onclick();
hs.toggleImagesExpandEl=null;
}else{
for(i=0;iif(hs.expanders[i]&&hs.expanders[i].isExpanded)hs.focusTopmost();
}
}
},

mouseClickHandler:function(e)
{
if(!e)e=window.event;
if(e.button>1)returntrue;
if(!e.target)e.target=e.srcElement;


varfobj=e.target;

while(fobj.parentNode
&&!(fobj.className&&fobj.className.match(/highslide-(image|move|html)/)))
{
fobj=fobj.parentNode;
}

if(!fobj.parentNode)return;

hs.dragKey=hs.getWrapperKey(fobj);
if(fobj.className.match(/highslide-(image|move)/)){
varisDraggable=true;
varwLeft=parseInt(hs.expanders[hs.dragKey].wrapper.style.left);
varwTop=parseInt(hs.expanders[hs.dragKey].wrapper.style.top);
}

if(e.type=='mousedown'){
if(isDraggable)//dragorfocus
{
hs.dragObj=hs.expanders[hs.dragKey].content;

if(fobj.className.match('highslide-image'))hs.dragObj.style.cursor='move';

hs.leftBeforeDrag=wLeft;
hs.topBeforeDrag=wTop;

hs.dragX=e.clientX;
hs.dragY=e.clientY;
hs.addEventListener(document,'mousemove',hs.mouseMoveHandler);
if(e.preventDefault)e.preventDefault();//FF

if(hs.dragObj.className.match(/highslide-(image|html)-blur/)){
hs.expanders[hs.dragKey].focus();
hs.hasFocused=true;
}
returnfalse;
}
elseif(fobj.className.match(/highslide-html/)){//justfocus
hs.expanders[hs.dragKey].focus();
hs.expanders[hs.dragKey].redoShowHide();
hs.hasFocused=false;//why??
}

}elseif(e.type=='mouseup'){
hs.removeEventListener(document,'mousemove',hs.mouseMoveHandler);
if(isDraggable&&hs.expanders[hs.dragKey]){
if(fobj.className.match('highslide-image')){
fobj.style.cursor=hs.styleRestoreCursor;
}
varhasMoved=wLeft!=hs.leftBeforeDrag||wTop!=hs.topBeforeDrag;
if(!hasMoved&&!hs.hasFocused&&!fobj.className.match(/highslide-move/)){
hs.expanders[hs.dragKey].doClose();
}elseif(hasMoved||(!hasMoved&&hs.hasHtmlExpanders)){
hs.expanders[hs.dragKey].redoShowHide();
}
hs.hasFocused=false;

}elseif(fobj.className.match('highslide-image-blur')){
fobj.style.cursor=hs.styleRestoreCursor;
}
}
},

mouseMoveHandler:function(e)
{
if(!hs.expanders[hs.dragKey]||!hs.expanders[hs.dragKey].wrapper)return;
if(!e)e=window.event;

varexp=hs.expanders[hs.dragKey];
varw=exp.wrapper;
w.style.left=hs.leftBeforeDrag+e.clientX-hs.dragX+'px';
w.style.top=hs.topBeforeDrag+e.clientY-hs.dragY+'px';

if(exp.objOutline){
varo=exp.objOutline;
o.outer.style.left=(parseInt(w.style.left)-o.offset)+'px';
o.outer.style.top=(parseInt(w.style.top)-o.offset)+'px';
}

returnfalse;
},

addEventListener:function(el,event,func){
if(document.addEventListener)el.addEventListener(event,func,false);
elseif(document.attachEvent)el.attachEvent('on'+event,func);
elseel[event]=func;
},

removeEventListener:function(el,event,func){
if(document.removeEventListener)el.removeEventListener(event,func,false);
elseif(document.detachEvent)el.detachEvent('on'+event,func);
elseel[event]=null;
},

isHsAnchor:function(a){
return(a.className&&(a.className.match("highslide$")||a.className.match("highslide")));
},

preloadFullImage:function(i){
if(hs.continuePreloading&&hs.preloadTheseImages[i]&&hs.preloadTheseImages[i]!='undefined'){
varimg=document.createElement('img');
img.onload=function(){hs.preloadFullImage(i+1);};
img.src=hs.preloadTheseImages[i];
}
},

preloadImages:function(number){
if(number)this.numberOfImagesToPreload=number;

varj=0;

varaTags=document.getElementsByTagName('A');
for(i=0;ia=aTags[i];
if(hs.isHsAnchor(a)){
if(jhs.preloadTheseImages[j]=hs.getSrc(a);
j++;
}
}
}

//preloadoutlines
newHsOutline(hs.outlineType,function(){hs.preloadFullImage(0)});

//preloadcursor
varcur=document.createElement('img');
cur.src=hs.graphicsDir+hs.restoreCursor;
},

genContainer:function(){
if(!hs.container){
hs.container=hs.createElement('div',
null,
{position:'absolute',left:0,top:0,width:'100%',zIndex:hs.zIndexCounter},
document.body
);
}
}
};//endhsobject

//-----------------------------------------------------------------------------
HsOutline=function(outlineType,onLoad){
if(!outlineType)return;
if(onLoad)this.onLoad=onLoad;
this.outlineType=outlineType;
this.outline=newArray();
varv=hs.ieVersion();

hs.genContainer();

this.hasAlphaImageLoader=hs.ie&&v>=5.5&&v<8;
this.hasPngSupport=!hs.ie||(hs.ie&&v>=8);
this.hasOutline=this.outlineType&&(this.hasAlphaImageLoader||this.hasPngSupport);

this.outer=hs.createElement(
'table',
{
cellSpacing:0//saf
},
{
visibility:'hidden',
position:'absolute',
zIndex:hs.zIndexCounter++,
borderCollapse:'collapse'
},
hs.container
);
this.tbody=hs.createElement('tbody',null,null,this.outer);

this.preloadOutlineElement(1);//recursive
};

HsOutline.prototype.preloadOutlineElement=function(i){
if(this.outline[i]&&this.outline[i].onload){//Geckomultipleonloadsbug
this.outline[i].onload=null;
return;
}

this.offset=this.hasOutline?10:0;
if(i==1||i==4||i==6)this.tr=hs.createElement('tr',null,null,this.tbody);
if(i==5)this.inner=hs.createElement('td',null,{padding:0,margin:0,border:0,position:'relative'},this.tr);

varfiles=Array(0,8,1,2,7,3,6,5,4);
varsrc=hs.graphicsDir+"outlines/"+this.outlineType+"/"+files[i]+".png";

if(this.hasAlphaImageLoader){
varbgKey='filter';
varbgValue="progid:DXImageTransform.Microsoft.AlphaImageLoader("
+"enabled=true,sizingMethod=scalesrc='"+src+"')";
}elseif(this.hasPngSupport||this.hasIe7Bug){
varbgKey='background';
varbgValue='url('+src+')';
}
varstyles={lineHeight:0,fontSize:0,padding:0,margin:0,border:0};
if(this.hasOutline)styles[bgKey]=bgValue;

vartd=hs.createElement('td',null,styles);

varimg=hs.createElement('img',null,{visibility:'hidden',display:'block'},td);//foronloadtrigger

vardim=2*this.offset;
hs.setStyles(td,{height:dim+'px',width:dim+'px'});

varpThis=this;
if(i<8)img.onload=function(){pThis.preloadOutlineElement(i+1);};
elseimg.onload=function(){
hs.pendingOutlines[pThis.outlineType]=pThis;
if(pThis.onLoad)pThis.onLoad();
};

this.tr.appendChild(td);
if(this.hasOutline)img.src=src;
elseimg.onload();
};

HsOutline.prototype.destroy=function(){
this.outer.parentNode.removeChild(this.outer);
};

//-----------------------------------------------------------------------------
//Theexpanderobject
HsExpander=function(a,params,contentType){
hs.continuePreloading=false;

//overrideinlineparameters
for(i=0;ivarname=hs.overrides[i];
if(params&&typeofparams[name]!='undefined')this[name]=params[name];
elsethis[name]=hs[name];
}

if(params&¶ms.thumbnailId){
varel=hs.$(params.thumbnailId);

}else{//firstimgwithinanchor
for(i=0;iif(a.childNodes[i].tagName&&a.childNodes[i].tagName=='IMG'){
varel=a.childNodes[i];
break;
}
}
}
if(!el)el=a;


//cancelother
for(i=0;iif(hs.expanders[i]&&hs.expanders[i].thumb!=el&&!hs.expanders[i].onLoadStarted){
hs.expanders[i].cancelLoading();
}
}
//checkifalreadyopen
for(i=0;iif(hs.expanders[i]&&hs.expanders[i].thumb==el){
hs.expanders[i].focus();
returnfalse;
}

elseif(hs.expanders[i]&&!hs.allowMultipleInstances){
hs.expanders[i].doClose();
}

}

this.key=hs.expandedImagesCounter++;
hs.expanders[this.key]=this;
if(contentType=='html'){
this.isHtml=true;
this.contentType='html';
}else{
this.isImage=true;
this.contentType='image';
}

this.a=a;

this.thumbsUserSetId=el.id||a.id;
this.thumb=el;

this.overlays=newArray();

varpos=hs.position(el);

//instanciatethewrapper
this.wrapper=hs.createElement(
'div',
{
id:'highslide-wrapper-'+this.key,
className:this.wrapperClassName
},
{
visibility:'hidden',
position:'absolute',
zIndex:hs.zIndexCounter++
}
);

//storepropertiesofthumbnail
this.thumbWidth=el.width?el.width:el.offsetWidth;
this.thumbHeight=el.height?el.height:el.offsetHeight;
this.thumbLeft=pos.x;
this.thumbTop=pos.y;
this.thumbClass=el.className;

//thumbborders
this.thumbOffsetBorderW=(this.thumb.offsetWidth-this.thumbWidth)/2;
this.thumbOffsetBorderH=(this.thumb.offsetHeight-this.thumbHeight)/2;

//getthewrapper
if(hs.pendingOutlines[this.outlineType]){
this.connectOutline();
this[this.contentType+'Create']();
}elseif(!this.outlineType){
hs.genContainer();
this[this.contentType+'Create']();
}else{
this.displayLoading();
varpThis=this;
newHsOutline(this.outlineType,
function(){
pThis.connectOutline();
pThis[pThis.contentType+'Create']();
}
);
}

};

HsExpander.prototype.connectOutline=function(x,y){
varw=hs.pendingOutlines[this.outlineType];
this.objOutline=w;
hs.pendingOutlines[this.outlineType]=null;
};

HsExpander.prototype.displayLoading=function(){
if(this.onLoadStarted||this.loading)return;

this.originalCursor=this.a.style.cursor;
this.a.style.cursor='wait';

if(!hs.loading){
hs.loading=hs.createElement('a',
{
className:'highslide-loading',
title:hs.loadingTitle,
innerHTML:hs.loadingText
},
{
position:'absolute'
},hs.container
);
if(hs.ie)hs.loading.style.filter='alpha(opacity='+(100*hs.loadingOpacity)+')';
elsehs.loading.style.opacity=hs.loadingOpacity;
}

this.loading=hs.loading;
this.loading.href='javascript:hs.expanders['+this.key+'].cancelLoading()';
this.loading.visibility='visible';

this.loading.style.left=(this.thumbLeft+this.thumbOffsetBorderW
+(this.thumbWidth-this.loading.offsetWidth)/2)+'px';
this.loading.style.top=(this.thumbTop
+(this.thumbHeight-this.loading.offsetHeight)/2)+'px';
setTimeout(
"if(hs.expanders["+this.key+"]&&hs.expanders["+this.key+"].loading)"
+"hs.expanders["+this.key+"].loading.style.visibility='visible';",
100
);
};

HsExpander.prototype.imageCreate=function(){
varimg=document.createElement('img');
varkey=this.key;

varimg=document.createElement('img');
this.content=img;
img.onload=function(){if(hs.expanders[key])hs.expanders[key].onLoad();};
img.className='highslide-image'+this.thumbClass;
img.style.visibility='hidden';//preventflickeringinIE
img.style.display='block';
img.style.position='absolute';
img.style.zIndex=3;
img.title=hs.restoreTitle;
img.onmouseover=function(){
if(hs.expanders[key])hs.expanders[key].onMouseOver();
};
img.onmouseout=function(e){
varrel=e?e.relatedTarget:event.toElement;
if(hs.expanders[key])hs.expanders[key].onMouseOut(rel);
};
if(hs.safari)hs.container.appendChild(img);
img.src=hs.getSrc(this.a);

this.displayLoading();
};

HsExpander.prototype.onLoad=function(){
try{

if(!this.content)return;
if(this.onLoadStarted)return;//oldGeckoloop
elsethis.onLoadStarted=true;


if(this.loading){
this.loading.style.visibility='hidden';
this.loading=null;
this.a.style.cursor=this.originalCursor||'';
}

if(this.isImage){
this.newWidth=this.content.width;
this.newHeight=this.content.height;
this.fullExpandWidth=this.newWidth;
this.fullExpandHeight=this.newHeight;

this.content.width=this.thumbWidth;
this.content.height=this.thumbHeight;
}

//identifycaptiondiv
varmodMarginBottom=hs.marginBottom;
if(!this.captionId&&this.thumbsUserSetId)this.captionId='caption-for-'+this.thumbsUserSetId;
if(this.captionId&&(hs.$(this.captionId)||hs.$(this.captionId+'-taken'))){
this.origCaption=hs.$(this.captionId+'-taken')?hs.$(this.captionId+'-taken'):hs.$(this.captionId);
this.caption=this.origCaption.cloneNode(1);
modMarginBottom+=this.spaceForCaption;
if(!hs.$(this.captionId+'-taken'))this.origCaption.id=this.captionId+'-taken';
if(!hs.$(this.captionId))this.caption.id=this.captionId;
elsethis.caption.id=null;
if(this.captionTemplateId&&hs.$(this.captionTemplateId)){
this.origCapTpl=hs.$(this.captionTemplateId);
this.capTpl=this.origCapTpl.cloneNode(1);
this.capTpl.innerHTML
=this.capTpl.innerHTML.replace(/s/g,'').replace('{caption}',this.caption.innerHTML);
this.caption=this.capTpl;

}
}

this.wrapper.appendChild(this.content);
this.content.style.position='relative';//Saf
if(this.caption)this.wrapper.appendChild(this.caption);
this.wrapper.style.left=this.thumbLeft+'px';
this.wrapper.style.top=this.thumbTop+'px';
hs.container.appendChild(this.wrapper);

//correctforborders
this.offsetBorderW=(this.content.offsetWidth-this.thumbWidth)/2;
this.offsetBorderH=(this.content.offsetHeight-this.thumbHeight)/2;
varmodMarginRight=hs.marginRight+2*this.offsetBorderW;
modMarginBottom+=2*this.offsetBorderH;

varratio=this.newWidth/this.newHeight;
varminWidth=this.allowSizeReduction?this.minWidth:this.newWidth;
varminHeight=this.allowSizeReduction?this.minHeight:this.newHeight;

varjustify={x:'auto',y:'auto'};
if(this.align=='center'){
justify.x='center';
justify.y='center';
}else{
if(this.anchor.match(/^top/))justify.y=null;
if(this.anchor.match(/right$/))justify.x='max';
if(this.anchor.match(/^bottom/))justify.y='max';
if(this.anchor.match(/left$/))justify.x=null;
}

client=newhs.clientInfo();

//justify
this.x={
min:parseInt(this.thumbLeft)-this.offsetBorderW+this.thumbOffsetBorderW,
span:this.newWidth,
minSpan:this.newWidthjustify:justify.x,
marginMin:hs.marginLeft,
marginMax:modMarginRight,
scroll:client.scrollLeft,
clientSpan:client.width,
thumbSpan:this.thumbWidth
};
varoldRight=this.x.min+parseInt(this.thumbWidth);
this.x=this.justify(this.x);

this.y={
min:parseInt(this.thumbTop)-this.offsetBorderH+this.thumbOffsetBorderH,
span:this.newHeight,
minSpan:this.newHeightjustify:justify.y,
marginMin:hs.marginTop,
marginMax:modMarginBottom,
scroll:client.scrollTop,
clientSpan:client.height,
thumbSpan:this.thumbHeight
};
varoldBottom=this.y.min+parseInt(this.thumbHeight);
this.y=this.justify(this.y);

if(this.isHtml)this.htmlSizeOperations();
if(this.isImage)this.correctRatio(ratio);

varx=this.x;
vary=this.y;

//Selectboxbug
varimgPos={x:x.min-20,y:y.min-20,w:x.span+40,h:y.span+40+this.spaceForCaption};
hs.hideSelects=(hs.ie&&hs.ieVersion()<7);
if(hs.hideSelects)this.showHideElements('SELECT','hidden',imgPos);
//Iframesbug
hs.hideIframes=(window.opera||navigator.vendor=='KDE'||(hs.ie&&hs.ieVersion()<5.5));
if(hs.hideIframes)this.showHideElements('IFRAME','hidden',imgPos);

//Makeoutlineready
if(this.objOutline&&!this.outlineWhileAnimating)this.positionOutline(x.min,y.min,x.span,y.span);
varo2=this.objOutline?this.objOutline.offset:0;

//Applysizechange
this.changeSize(
1,
this.thumbLeft+this.thumbOffsetBorderW-this.offsetBorderW,
this.thumbTop+this.thumbOffsetBorderH-this.offsetBorderH,
this.thumbWidth,
this.thumbHeight,
x.min,
y.min,
x.span,
y.span,
hs.expandDuration,
hs.expandSteps,
hs.outlineStartOffset,
o2
);

}catch(e){
if(hs.expanders[this.key]&&hs.expanders[this.key].a)
window.location.href=hs.getSrc(hs.expanders[this.key].a);
}
};

HsExpander.prototype.changeSize=function(dir,x1,y1,w1,h1,x2,y2,w2,h2,dur,steps,oo1,oo2){
dW=(w2-w1)/steps;
dH=(h2-h1)/steps;
dX=(x2-x1)/steps;
dY=(y2-y1)/steps;
dOo=(oo2-oo1)/steps;
for(i=1;i<=steps;i++){
w1+=dW;
h1+=dH;
x1+=dX;
y1+=dY;
oo1+=dOo;

varobj="hs.expanders["+this.key+"]";
vars="if("+obj+"){";
if(i==1){
s+=obj+".content.style.visibility='visible';"
+"if("+obj+".thumb.tagName=='IMG'&&hs.hideThumbOnExpand)"+obj+".thumb.style.visibility='hidden';"
}
if(i==steps){
w1=w2;
h1=h2;
x1=x2;
y1=y2;
oo1=oo2;
}
s+=obj+"."+this.contentType+"SetSize("+Math.round(w1)+","+Math.round(h1)+","
+Math.round(x1)+","+Math.round(y1)+","+Math.round(oo1);
if(i==steps)s+=','+dir;
s+=");}";
setTimeout(s,Math.round(i*(dur/steps)));
}
};

HsExpander.prototype.imageSetSize=function(w,h,x,y,offset,end){
try{
this.content.width=w;
this.content.height=h;

if(this.objOutline&&this.outlineWhileAnimating){
varo=this.objOutline.offset-offset;
this.positionOutline(x+o,y+o,w-2*o,h-2*o,1);
}

hs.setStyles(this.wrapper,
{
'visibility':'visible',
'left':x+'px',
'top':y+'px'
}
);

if(end==1)this.onExpanded();
elseif(end==-1)this.onEndClose();
}catch(e){
window.location.href=hs.getSrc(this.a);
}
};

HsExpander.prototype.positionOutline=function(x,y,w,h,vis){
if(!this.objOutline)return;
varo=this.objOutline;
if(vis)o.outer.style.visibility='visible';
o.outer.style.left=(x-o.offset)+'px';
o.outer.style.top=(y-o.offset)+'px';
o.outer.style.width=(w+2*(this.offsetBorderW+o.offset))+'px';
w+=2*(this.offsetBorderW-o.offset);
h+=+2*(this.offsetBorderH-o.offset);
o.inner.style.width=w>=0?w+'px':0;
o.inner.style.height=h>=0?h+'px':0;
};

HsExpander.prototype.onExpanded=function(){
if(this.objOutline)this.objOutline.outer.style.visibility='visible';
this.isExpanded=true;
this.focus();
if(this.isHtml&&this.objectLoadTime=='after')this.writeExtendedContent();
this.createCustomOverlays();
if(hs.showCredits)this.writeCredits();

if(this.caption)this.writeCaption();

if(this.fullExpandWidth>this.x.span)this.createFullExpand();
if(!this.caption)this.onDisplayFinished();

};

HsExpander.prototype.onDisplayFinished=function(){
varkey=this.key;
varoutlineType=this.outlineType;
newHsOutline(outlineType,function(){if(hs.expanders[key])hs.expanders[key].preloadNext();});
};

HsExpander.prototype.preloadNext=function(){
varnextA=hs.getAdjacentAnchor(this.key,1);
if(nextA){
varimg=document.createElement('img');
img.src=hs.getSrc(nextA);
}
};

HsExpander.prototype.justify=function(p){
if(p.justify=='auto'||p.justify=='center'){
varhasMovedMin=false;
varallowReduce=true;
//calculatep.min
if(p.justify=='center')p.min=Math.round(p.scroll+(p.clientSpan-p.span-p.marginMax)/2);
elsep.min=Math.round(p.min-((p.span-p.thumbSpan)/2));//auto
if(p.minp.min=p.scroll+p.marginMin;
hasMovedMin=true;
}

if(p.spanp.span=p.minSpan;
allowReduce=false;
}
//calculateright/newWidth
if(p.min+p.span>p.scroll+p.clientSpan-p.marginMax){
if(hasMovedMin&&allowReduce)p.span=p.clientSpan-p.marginMin-p.marginMax;//can'texpandmore
elseif(p.spanp.min=p.scroll+p.clientSpan-p.span-p.marginMin-p.marginMax;
}else{//imagelargerthanclient
p.min=p.scroll+p.marginMin;
if(allowReduce)p.span=p.clientSpan-p.marginMin-p.marginMax;
}

}

if(p.spanp.span=p.minSpan;
allowReduce=false;
}

}elseif(p.justify=='max'){
p.min=Math.floor(p.min-p.span+p.thumbSpan);
}

if(p.mintmpMin=p.min;
p.min=p.marginMin;
if(allowReduce)p.span=p.span-(p.min-tmpMin);
}
returnp;
};

HsExpander.prototype.correctRatio=function(ratio){
varx=this.x;
vary=this.y;
varchanged=false;
if(x.span/y.span>ratio){//widthgreater
vartmpWidth=x.span;
x.span=y.span*ratio;
if(x.spanx.span=x.minSpan;
y.span=x.span/ratio;
}
changed=true;

}elseif(x.span/y.spanvartmpHeight=y.span;
y.span=x.span/ratio;
changed=true;
}

if(changed){
x.min=parseInt(this.thumbLeft)-this.offsetBorderW+this.thumbOffsetBorderW;
x.minSpan=x.span;
this.x=this.justify(x);

y.min=parseInt(this.thumbTop)-this.offsetBorderH+this.thumbOffsetBorderH;
y.minSpan=y.span;
this.y=this.justify(y);
}
};

HsExpander.prototype.cancelLoading=function(){
this.a.style.cursor=this.originalCursor;
if(this.loading)hs.loading.style.visibility='hidden';
hs.expanders[this.key]=null;
};

HsExpander.prototype.writeCredits=function(){
varcredits=hs.createElement('a',
{
href:hs.creditsHref,
className:'highslide-credits',
innerHTML:hs.creditsText,
title:hs.creditsTitle
}
);
this.createOverlay(credits,'topleft');
};

HsExpander.prototype.writeCaption=function(){
try{
this.wrapper.style.width=this.wrapper.offsetWidth+'px';
this.caption.style.visibility='hidden';
this.caption.style.position='relative';
if(hs.ie)this.caption.style.zoom=1;
this.caption.className+='highslide-display-block';

varcapHeight=this.caption.offsetHeight;
varslideHeight=(capHeightthis.caption.style.top='-'+slideHeight+'px';

this.caption.style.zIndex=2;

varstep=1;
if(slideHeight>400)step=4;
elseif(slideHeight>200)step=2;
elseif(slideHeight>100)step=1;
if(hs.captionSlideSpeed)step=step*hs.captionSlideSpeed;
elsestep=slideHeight;

vart=0;
for(vartop=-slideHeight;top<=0;top+=step,t+=10){
varend=(top>=0)?1:0;
vareval="if(hs.expanders["+this.key+"]){"
+"hs.expanders["+this.key+"].placeCaption("+top+","+end+");"
+"}";
setTimeout(eval,t);
}

}catch(e){}
};

HsExpander.prototype.placeCaption=function(top,end){
if(!this.caption)return;
this.caption.style.top=top+'px';
this.caption.style.visibility='visible';
if(this.objOutline)this.objOutline.inner.style.height
=(this.wrapper.offsetHeight+top-2*this.objOutline.offset)+'px';
if(end)this.onDisplayFinished();
};

HsExpander.prototype.showHideElements=function(tagName,visibility,imgPos){
varels=document.getElementsByTagName(tagName);
if(els){
for(i=0;iif(els[i].nodeName==tagName){
varhiddenBy=els[i].getAttribute('hidden-by');

if(visibility=='visible'&&hiddenBy){
hiddenBy=hiddenBy.replace('['+this.key+']','');
els[i].setAttribute('hidden-by',hiddenBy);
if(!hiddenBy)els[i].style.visibility='visible';

}elseif(visibility=='hidden'){//hideifbehind
varelPos=hs.position(els[i]);
elPos.w=els[i].offsetWidth;
elPos.h=els[i].offsetHeight;

varclearsX=(elPos.x+elPos.wimgPos.x+imgPos.w);
varclearsY=(elPos.y+elPos.himgPos.y+imgPos.h);
varwrapperKey=hs.getWrapperKey(els[i]);
if(!clearsX&&!clearsY&&wrapperKey!=this.key){//elementfallsbehindimage
if(!hiddenBy){
els[i].setAttribute('hidden-by','['+this.key+']');
}elseif(!hiddenBy.match('['+this.key+']')){
els[i].setAttribute('hidden-by',hiddenBy+'['+this.key+']');
}
els[i].style.visibility='hidden';
}elseif(hiddenBy=='['+this.key+']'||hs.focusKey==wrapperKey){//onmove
els[i].setAttribute('hidden-by','');
els[i].style.visibility='visible';
}elseif(hiddenBy&&hiddenBy.match('['+this.key+']')){
els[i].setAttribute('hidden-by',hiddenBy.replace('['+this.key+']',''));
}
}
}
}
}
};

HsExpander.prototype.focus=function(){
//blurothers
for(i=0;iif(hs.expanders[i]&&i==hs.focusKey){
varblurExp=hs.expanders[i];
blurExp.content.className+='highslide-'+blurExp.contentType+'-blur';
if(blurExp.caption){
blurExp.caption.className+='highslide-caption-blur';
}
if(blurExp.isImage){
blurExp.content.style.cursor=hs.ie?'hand':'pointer';
blurExp.content.title=hs.focusTitle;
}
}
}

//focusthis
this.wrapper.style.zIndex=hs.zIndexCounter++;
if(this.objOutline)this.objOutline.outer.style.zIndex=this.wrapper.style.zIndex;

this.content.className='highslide-'+this.contentType;
if(this.caption){
this.caption.className=this.caption.className.replace('highslide-caption-blur','');
}

if(this.isImage){
this.content.title=hs.restoreTitle;

hs.styleRestoreCursor=window.opera?'pointer':'url('+hs.graphicsDir+hs.restoreCursor+'),pointer';
if(hs.ie&&hs.ieVersion()<6)hs.styleRestoreCursor='hand';
this.content.style.cursor=hs.styleRestoreCursor;
}

hs.focusKey=this.key;
hs.addEventListener(document,'keydown',hs.keyHandler);
};

HsExpander.prototype.doClose=function(){
hs.removeEventListener(document,'keydown',hs.keyHandler);
try{
if(!hs.expanders[this.key])return;

this.isClosing=true;

varx=parseInt(this.wrapper.style.left);
vary=parseInt(this.wrapper.style.top);
varw=(this.isImage)?this.content.width:parseInt(this.content.style.width);
varh=(this.isImage)?this.content.height:parseInt(this.content.style.height);

if(this.objOutline&&this.outlineWhileAnimating)this.positionOutline(x,y,w,h);
elseif(this.objOutline)this.objOutline.destroy();

//removechildren
varn=this.wrapper.childNodes.length;
for(i=n-1;i>=0;i--){
varchild=this.wrapper.childNodes[i];
if(child!=this.content){
this.wrapper.removeChild(this.wrapper.childNodes[i]);
}
}

if(this.objectLoadTime=='after')this.destroyObject();
if(this.scrollerDiv&&this.scrollerDiv!='scrollingContent')
this[this.scrollerDiv].style.overflow='hidden';

this.wrapper.style.width='auto';
this.content.style.cursor='default';
varo2=this.objOutline?this.objOutline.offset:0;

this.changeSize(
-1,
x,
y,
w,
h,
this.thumbLeft-this.offsetBorderW+this.thumbOffsetBorderW,
this.thumbTop-this.offsetBorderH+this.thumbOffsetBorderH,
this.thumbWidth,
this.thumbHeight,
hs.restoreDuration,
hs.restoreSteps,
o2,
hs.outlineStartOffset
);

}catch(e){
hs.expanders[this.key].onEndClose();
}
};

HsExpander.prototype.onEndClose=function(){
this.thumb.style.visibility='visible';

if(hs.hideSelects)this.showHideElements('SELECT','visible');
if(hs.hideIframes)this.showHideElements('IFRAME','visible');

this.wrapper.parentNode.removeChild(this.wrapper);
if(this.objOutline&&this.outlineWhileAnimating)this.objOutline.destroy();

hs.expanders[this.key]=null;

hs.cleanUp();
};

HsExpander.prototype.createOverlay=function(el,position,hideOnMouseOut,opacity){
if(typeofel=='string'&&hs.$(el)){
el=hs.$(el).cloneNode(true);
el.id=null;
}
if(!el||typeofel=='string'||!this.isImage)return;

if(!position)varposition='centercenter';
varoverlay=hs.createElement(
'div',
null,
{
'position':'absolute',
'zIndex':3
},
this.wrapper
);
if(opacity&&opacity<1){
if(hs.ie)overlay.style.filter='alpha(opacity='+(opacity*100)+')';
elseoverlay.style.opacity=opacity;
}
el.className+='highslide-display-block';
overlay.appendChild(el);


varleft=this.offsetBorderW;
vardLeft=this.content.width-overlay.offsetWidth;
vartop=this.offsetBorderH;
vardTop=this.content.height-overlay.offsetHeight;

if(position.match(/^bottom/))top+=dTop;
if(position.match(/^center/))top+=dTop/2;
if(position.match(/right$/))left+=dLeft;
if(position.match(/center$/))left+=dLeft/2;
overlay.style.left=left+'px';
overlay.style.top=top+'px';

if(hideOnMouseOut)overlay.setAttribute('hideOnMouseOut',true);

hs.push(this.overlays,overlay);
};

HsExpander.prototype.createCustomOverlays=function(){
for(i=0;ivaro=hs.overlays[i];
if(o.thumbnailId==null||o.thumbnailId==this.thumbsUserSetId){
this.createOverlay(o.overlayId,o.position,o.hideOnMouseOut,o.opacity);
}
}
};

HsExpander.prototype.onMouseOver=function(){
for(i=0;ithis.overlays[i].style.visibility='visible';
}
};

HsExpander.prototype.onMouseOut=function(rel){
varhideThese=newArray();
varj=0;
for(i=0;ivarnode=rel;
while(node&&node.parentNode){
if(node==this.overlays[i])return;
node=node.parentNode;
}

if(this.overlays[i].getAttribute('hideOnMouseOut')){
hideThese[j]=this.overlays[i];
j++;
}
}
for(i=0;ihideThese[i].style.visibility='hidden';
}
};

HsExpander.prototype.createFullExpand=function(){
vara=hs.createElement(
'a',
{
href:'javascript:hs.expanders['+this.key+'].doFullExpand();',
title:hs.fullExpandTitle
},
{
background:'url('+hs.graphicsDir+hs.fullExpandIcon+')',
display:'block',
margin:'010px10px0',
width:'45px',
height:'44px'
}
);

this.createOverlay(a,'bottomright',true,0.75);
this.fullExpandIcon=a;
};

HsExpander.prototype.doFullExpand=function(){
try{

this.fullExpandIcon.parentNode.removeChild(this.fullExpandIcon);
this.focus();

this.x.min=parseInt(this.wrapper.style.left)-(this.fullExpandWidth-this.content.width)/2;
if(this.x.minthis.wrapper.style.left=this.x.min+'px';

varborderOffset=this.wrapper.offsetWidth-this.content.width;


this.content.width=this.fullExpandWidth;
this.content.height=this.fullExpandHeight;

this.x.span=this.content.width;
this.wrapper.style.width=(this.x.span+borderOffset)+'px';

this.y.span=this.wrapper.offsetHeight-2*this.offsetBorderH;
this.positionOutline(this.x.min,this.y.min,this.x.span,this.y.span);

//repositionoverlays
for(xinthis.overlays){
this.overlays[x].parentNode.removeChild(this.overlays[x]);
}
if(hs.showCredits)this.writeCredits();
this.createCustomOverlays();

this.redoShowHide();

}catch(e){
//window.location.href=hs.expanders[this.key].content.src;
}
};

//onendmoveandresize
HsExpander.prototype.redoShowHide=function(){
varimgPos={
x:parseInt(this.wrapper.style.left)-20,
y:parseInt(this.wrapper.style.top)-20,
w:this.content.offsetWidth+40,
h:this.content.offsetHeight+40+this.spaceForCaption
};
if(hs.hideSelects)this.showHideElements('SELECT','hidden',imgPos);
if(hs.hideIframes)this.showHideElements('IFRAME','hidden',imgPos);

};

//sethandlers
hs.addEventListener(document,'mousedown',hs.mouseClickHandler);
hs.addEventListener(document,'mouseup',hs.mouseClickHandler);

相关推荐