Source de js/box_utils.js
cbHeight="1.6em"
bL=new Array(new Array("nav-bar","ul"),new Array("sponsor-bar","div"),new Array("quick-bar","ul"),new Array("themes-bar","form"),new Array("bookmarks-bar","form"),new Array("news-bar","form"))
asOffset=5
asZone=30
asTOFact=0.5
asBP=50
asTimer=0
mWait=false
mBox=null
boxTop=0
oTop=0
oY=0
cY=0
function getDivTag(divId)
{
result=""
for(i=0;i<bL.length;i++) {
boxesInfo=bL[i]
if(boxesInfo[0]==divId) result=boxesInfo[1]
}
return result
}
function saveBoxesOrder()
{
boxesString=""
menuBarChildren=getE("menu-bar").childNodes
for(i=0;i<menuBarChildren.length;i++) {
obj=menuBarChildren[i]
if(obj.className=="box") boxesString=boxesString+"|"+obj.id
}
setCookie("boxesBar",boxesString)
}
function windowScroll()
{
if((cY<asZone)&&(getScrollOffset()>0)) {
scrollBy(0,- asOffset)
boxTop-=asOffset
oY+=asOffset
asTimer=setTimeout('windowScroll()',asTOFact*cY)
} else if((cY>(getClientHeight()-asZone))&&(boxTop<getE("menu-bar").offsetHeight+asBP)) {
scrollBy(0,asOffset)
boxTop+=asOffset
oY-=asOffset
asTimer=setTimeout('windowScroll()',asTOFact*(getClientHeight()-cY))
}
if(!mBox) clearTimeout(asTimer)
else mBox.style.top=boxTop+"px"
}
function findPosition(refTop)
{
menuBarChildren=getE("menu-bar").childNodes
for(i=0;i<menuBarChildren.length;i++) {
obj=menuBarChildren[i]
if((obj.className=="box") && (obj.offsetTop>refTop)) return obj
}
return null
}
function moveDiv(evt)
{
if(mWait) return false
mWait=true
setTimeout('mWait=false;',5)
if(mBox==null) return false
if(!evt) evt=event
if(document.selection) document.selection.empty()
if((Math.abs(evt.screenY-oY)>5) || (mBox.className=="moving-box")) {
boxTop=oTop+(evt.screenY-oY)
mBox.className="moving-box"
cY=evt.clientY
windowScroll()
}
return false
}
function boxDrag(evt,box)
{
if(!evt) evt=event
document.body.onmousemove=function(event) {return moveDiv(event)}
document.body.onmouseup=function() {return boxDrop()}
mBox=box
oTop=box.offsetTop
oY=evt.screenY
return false
}
function boxDrop()
{
if(mBox==null) return true
document.body.onmousemove=null
document.body.onmouseup=null
if(boxTop==0) {
if (!getT(mBox,"h1").getElementsByTagName("a").length) changeDisplay(mBox.id,getDivTag(mBox.id))
} else moveBox()
if(asTimer) clearTimeout(asTimer)
mBox=null
return false
}
function moveBox()
{
box=findPosition(boxTop)
swapBoxes(mBox,box)
if(document.selection) document.selection.empty()
else if(window.content) content.getSelection().removeAllRanges()
mBox.className="box"
mBox.style.top="0"
mBox=null
boxTop=0
saveBoxesOrder()
redraw()
}
function swapBoxes(box1,box2)
{
if(!box1) return
menuBar=getE("menu-bar")
if(box2) menuBar.insertBefore(box1,box2)
else menuBar.appendChild(box1)
}
function changeDisplay(elementId,tagName)
{
element=getE(elementId)
tmpLink=getT(element,"a")
if(getES(elementId,"display","display",tagName)=="none") {
getT(element,tagName).style.display="block"
getT(element,"h1").className="expanded"
element.style.height="auto"
tmpLink.className="min-box"
if(tmpLink.mytitle) tmpLink.mytitle=tmpLink.mytitle.replace(/Agrandir/,"Réduire")
else tmpLink.title=tmpLink.title.replace(/Agrandir/,"Réduire")
saveState(elementId,"open")
} else {
getT(element,"h1").className="collapsed"
getT(element,tagName).style.display="none"
if(isIE) element.style.height=cbHeight
else element.style.height="auto"
tmpLink.className="max-box"
if(tmpLink.mytitle) tmpLink.mytitle=tmpLink.mytitle.replace(/Réduire/,"Agrandir")
else tmpLink.title=tmpLink.title.replace(/Réduire/,"Agrandir")
saveState(elementId,"close")
}
redraw()
return false
}
function changeDisplayKb(kbEvent,elementId,tagName)
{
if(isVK(kbEvent,true)) return changeDisplay(elementId,tagName)
else return true
}
function initOneElement(elementId,elementTag,cookieValue)
{
result=""
element=getE(elementId)
if(!element) return result
if(getES(elementId,"position","position")=="absolute") return
getT(element,"h1").onmousedown=function(event) {return boxDrag(event,this.parentNode)}
hideIt=false
if(cookieValue) {
if(cookieValue.indexOf(elementId+":close")!=-1 ) hideIt=true
else if(cookieValue.indexOf(elementId+":open")!=-1 ) {
getT(element,elementTag).style.display="block"
element.style.height="auto"
}
tmpLink=getT(element,"a")
if(hideIt||getES(elementId,"display","display",elementTag)=="none") {
getT(element,elementTag).style.display="none"
tmpLink.className="max-box"
if(tmpLink.mytitle) tmpLink.mytitle=tmpLink.mytitle.replace(/Réduire/,"Agrandir")
else tmpLink.title=tmpLink.title.replace(/Réduire/,"Agrandir")
getT(element,"h1").className="collapsed"
if(isIE) element.style.height=cbHeight
else element.style.height="auto"
result="|"+elementId+":close"
} else result="|"+elementId+":open"
}
return result
}
function initHide()
{
cookieValue=getCookie("boxesState")
if(!cookieValue) cookieValue=new String("")
for(i=0;i<bL.length;i++) {
boxesInfo=bL[i]
currentValue=initOneElement(boxesInfo[0],boxesInfo[1],cookieValue)
if(cookieValue && cookieValue.indexOf(boxesInfo[0])==-1) cookieValue+=currentValue
else {
if(currentValue) {
pattern=new RegExp("\\|"+boxesInfo[0]+"[^|]*")
cookieValue=cookieValue.replace(pattern,currentValue)
}
}
}
setCookie("boxesState",cookieValue)
}
function initMove()
{
for(i=0;i<bL.length;i++) {
boxElt=getE(bL[i][0])
if(boxElt) getT(boxElt,"h1").style.cursor="move"
}
}
function saveState(elementId,state)
{
cookieValue=getCookie("boxesState")
pattern=new RegExp("\\|"+elementId+"[^|]*")
cookieValue=cookieValue.replace(pattern,"|"+elementId+":"+state)
setCookie("boxesState",cookieValue)
}
bL=new Array(new Array("nav-bar","ul"),new Array("sponsor-bar","div"),new Array("quick-bar","ul"),new Array("themes-bar","form"),new Array("bookmarks-bar","form"),new Array("news-bar","form"))
asOffset=5
asZone=30
asTOFact=0.5
asBP=50
asTimer=0
mWait=false
mBox=null
boxTop=0
oTop=0
oY=0
cY=0
function getDivTag(divId)
{
result=""
for(i=0;i<bL.length;i++) {
boxesInfo=bL[i]
if(boxesInfo[0]==divId) result=boxesInfo[1]
}
return result
}
function saveBoxesOrder()
{
boxesString=""
menuBarChildren=getE("menu-bar").childNodes
for(i=0;i<menuBarChildren.length;i++) {
obj=menuBarChildren[i]
if(obj.className=="box") boxesString=boxesString+"|"+obj.id
}
setCookie("boxesBar",boxesString)
}
function windowScroll()
{
if((cY<asZone)&&(getScrollOffset()>0)) {
scrollBy(0,- asOffset)
boxTop-=asOffset
oY+=asOffset
asTimer=setTimeout('windowScroll()',asTOFact*cY)
} else if((cY>(getClientHeight()-asZone))&&(boxTop<getE("menu-bar").offsetHeight+asBP)) {
scrollBy(0,asOffset)
boxTop+=asOffset
oY-=asOffset
asTimer=setTimeout('windowScroll()',asTOFact*(getClientHeight()-cY))
}
if(!mBox) clearTimeout(asTimer)
else mBox.style.top=boxTop+"px"
}
function findPosition(refTop)
{
menuBarChildren=getE("menu-bar").childNodes
for(i=0;i<menuBarChildren.length;i++) {
obj=menuBarChildren[i]
if((obj.className=="box") && (obj.offsetTop>refTop)) return obj
}
return null
}
function moveDiv(evt)
{
if(mWait) return false
mWait=true
setTimeout('mWait=false;',5)
if(mBox==null) return false
if(!evt) evt=event
if(document.selection) document.selection.empty()
if((Math.abs(evt.screenY-oY)>5) || (mBox.className=="moving-box")) {
boxTop=oTop+(evt.screenY-oY)
mBox.className="moving-box"
cY=evt.clientY
windowScroll()
}
return false
}
function boxDrag(evt,box)
{
if(!evt) evt=event
document.body.onmousemove=function(event) {return moveDiv(event)}
document.body.onmouseup=function() {return boxDrop()}
mBox=box
oTop=box.offsetTop
oY=evt.screenY
return false
}
function boxDrop()
{
if(mBox==null) return true
document.body.onmousemove=null
document.body.onmouseup=null
if(boxTop==0) {
if (!getT(mBox,"h1").getElementsByTagName("a").length) changeDisplay(mBox.id,getDivTag(mBox.id))
} else moveBox()
if(asTimer) clearTimeout(asTimer)
mBox=null
return false
}
function moveBox()
{
box=findPosition(boxTop)
swapBoxes(mBox,box)
if(document.selection) document.selection.empty()
else if(window.content) content.getSelection().removeAllRanges()
mBox.className="box"
mBox.style.top="0"
mBox=null
boxTop=0
saveBoxesOrder()
redraw()
}
function swapBoxes(box1,box2)
{
if(!box1) return
menuBar=getE("menu-bar")
if(box2) menuBar.insertBefore(box1,box2)
else menuBar.appendChild(box1)
}
function changeDisplay(elementId,tagName)
{
element=getE(elementId)
tmpLink=getT(element,"a")
if(getES(elementId,"display","display",tagName)=="none") {
getT(element,tagName).style.display="block"
getT(element,"h1").className="expanded"
element.style.height="auto"
tmpLink.className="min-box"
if(tmpLink.mytitle) tmpLink.mytitle=tmpLink.mytitle.replace(/Agrandir/,"Réduire")
else tmpLink.title=tmpLink.title.replace(/Agrandir/,"Réduire")
saveState(elementId,"open")
} else {
getT(element,"h1").className="collapsed"
getT(element,tagName).style.display="none"
if(isIE) element.style.height=cbHeight
else element.style.height="auto"
tmpLink.className="max-box"
if(tmpLink.mytitle) tmpLink.mytitle=tmpLink.mytitle.replace(/Réduire/,"Agrandir")
else tmpLink.title=tmpLink.title.replace(/Réduire/,"Agrandir")
saveState(elementId,"close")
}
redraw()
return false
}
function changeDisplayKb(kbEvent,elementId,tagName)
{
if(isVK(kbEvent,true)) return changeDisplay(elementId,tagName)
else return true
}
function initOneElement(elementId,elementTag,cookieValue)
{
result=""
element=getE(elementId)
if(!element) return result
if(getES(elementId,"position","position")=="absolute") return
getT(element,"h1").onmousedown=function(event) {return boxDrag(event,this.parentNode)}
hideIt=false
if(cookieValue) {
if(cookieValue.indexOf(elementId+":close")!=-1 ) hideIt=true
else if(cookieValue.indexOf(elementId+":open")!=-1 ) {
getT(element,elementTag).style.display="block"
element.style.height="auto"
}
tmpLink=getT(element,"a")
if(hideIt||getES(elementId,"display","display",elementTag)=="none") {
getT(element,elementTag).style.display="none"
tmpLink.className="max-box"
if(tmpLink.mytitle) tmpLink.mytitle=tmpLink.mytitle.replace(/Réduire/,"Agrandir")
else tmpLink.title=tmpLink.title.replace(/Réduire/,"Agrandir")
getT(element,"h1").className="collapsed"
if(isIE) element.style.height=cbHeight
else element.style.height="auto"
result="|"+elementId+":close"
} else result="|"+elementId+":open"
}
return result
}
function initHide()
{
cookieValue=getCookie("boxesState")
if(!cookieValue) cookieValue=new String("")
for(i=0;i<bL.length;i++) {
boxesInfo=bL[i]
currentValue=initOneElement(boxesInfo[0],boxesInfo[1],cookieValue)
if(cookieValue && cookieValue.indexOf(boxesInfo[0])==-1) cookieValue+=currentValue
else {
if(currentValue) {
pattern=new RegExp("\\|"+boxesInfo[0]+"[^|]*")
cookieValue=cookieValue.replace(pattern,currentValue)
}
}
}
setCookie("boxesState",cookieValue)
}
function initMove()
{
for(i=0;i<bL.length;i++) {
boxElt=getE(bL[i][0])
if(boxElt) getT(boxElt,"h1").style.cursor="move"
}
}
function saveState(elementId,state)
{
cookieValue=getCookie("boxesState")
pattern=new RegExp("\\|"+elementId+"[^|]*")
cookieValue=cookieValue.replace(pattern,"|"+elementId+":"+state)
setCookie("boxesState",cookieValue)
}
Si avez des problèmes ou des questions concernant ce fichier source, vous pouvez utiliser le Forum Sources du site