Jag har ett script för en vertikal meny. När jag klickar i menyn så öppnar den upp sig och visar sub-menyerna, men när jag klickar på samma ännu en gång så går den inte att stänga.
Jag skulle därför behöva sätta en cookie som håller reda på föregående meny, men är väldigt osäker på hur jag kan göra detta? :q
/********************************************************************************
Switch menu function.
********************************************************************************/
createSlideMenu.prototype.switchMenu = function(num){
if(this.going) return
var m = this.menus[num]
if(m.childs.length==0) return
this.going = 1
var y=m.o.y+ m.o.h +this.l[m.lev].between
var clnum = m.num, olev = m.lev, onext = m.nextel
if(this.active[0]>-1){
var n = -1
if(m.lev>0){
if(this.active[m.lev]>-1) n=this.active[m.lev]
else n=this.active[m.lev-1]
}else n = this.active[0]
m = this.menus[n]
if(m.lev == 0 && olev==0) y = m.nexttop!=-1?this.menus[m.nexttop].origy:-1
else if(clnum!=m.num){
var ny = m.o.y + m.o.h + this.l[m.lev].between
if(clnum>m.num && olev==m.lev) y = Math.min(ny,y)
else if(onext==m.num) y = Math.max(ny,y)
}
}
this.moveUp(m.nextel!=-1?m.nextel:m.nexttop,num,y)
}
/********************************************************************************
Move items up
********************************************************************************/
createSlideMenu.prototype.moveUp = function(top,num,y)
{
var move = 0, m, yy=0;
var Date, cookie;
if(this.active[0]>-1 && top>-1){
m = this.menus[top]
if(m.o.y>y){
if((m.o.y-this.pxspeed)<y) yy = -(((m.o.y-y)))
else yy=-this.pxspeed; this.moveItems(yy,top)
move=1
}
}
if(move) setTimeout(this.name+".moveUp("+top+","+num+","+y+")",this.timspeed)
else{
m = this.menus\[num\]
for(var i=m.lev;i\<this.active.length;i++){ //Reset images - actives et cetera
if(this.active*\>-1){
temp = this.menus\[this.active*\]
temp.o.moveIt(temp.o.x-this.inset,temp.o.y)
if(this.useImages) temp.o.bgImg(temp.img) //Change bg
if(this.arrow) temp.ar.replaceChild(document.createTextNode("4"),temp.ar.childNodes\[0\])
ch = temp.childs
for(var j=0;j\<ch.length;j++){
ch\[j\].o.hideIt(); ch\[j\].o.movey(ch\[j\].origy)
}
this.active *\= -1
}
}
//Then open the current one, if childs
if(m.childs.length == 0){this.going = 0; return}
for(i=0;i\<m.childs.length;i++){ //Show all
m.childs*.o.showIt()
y = m.childs*.o.y + m.childs*.o.h
}
y+=this.l\[m.lev\].between
if(m.lev\>0 && m.chnum!=this.menus\[m.parent\].childs.length-1){
yy=y; y = this.menus\[m.parent\].endy + this.l\[m.lev\].between
}
m.o.moveIt(m.o.x+this.inset,m.o.y) //Inset current item:
if(this.useImages) m.o.bgImg(this.l\[m.lev\].roundImg) //Change bg
this.active\[m.lev\] = num //Set active
if(this.arrow) m.ar.replaceChild(document.createTextNode("6"),m.ar.childNodes\[0\])
if(m.nexttop\>-1 \|\| m.nextel\>-1) this.moveDown(m.nexttop,m.nextel,y,yy) //Then start moving all other elements down
else this.going=0
}
}
/********************************************************************************
Move items down
********************************************************************************/
createSlideMenu.prototype.moveDown = function(top,num,y,yyy){
var m = this.menus[top],yy
if(m && m.o.y<y){
if((m.o.y+this.pxspeed)>y) yy = y-m.o.y
else yy=this.pxspeed
this.moveItems(yy,top)
setTimeout(this.name+".moveDown("+top+","+num+","+y+","+yyy+")",this.timspeed)
}else if(num>-1){
this.moveDown(num,-1,yyy,0)
}else this.going=0
}
/********************************************************************************
Slide menu object
********************************************************************************/
function createSlideMenu(name){
document.write('<div id="'+name+'cont">') //The cont div start
this.name = name
this.menus = new Array()
this.curr = 0
this.lasttype = new Array()
this.writesubsonly = 0
this.level = new Array()
this.l = new Array()
this.topmenus = new Array()
this.active = new Array()
return this
}******