PDA

View Full Version : Remember collaspable div states across multiple pages.



recusancy
07-29-2009, 10:40 PM
Animated Collapsible DIV v2.4

http://www.dynamicdrive.com/dynamicindex17/animatedcollapse.htm

I'm trying to get this to work with multiple divs across multiple pages with the default position being open. I've been able to make the cookies contain which divs are closed (as opposed to the default script which tracks which are open) but I can't tweak the script so that it only closes what is in the cookies rather then open what's in the cookies.

I used a tweaked version of the uninit function which I than tweaked to remember closed rather then open divs. See below:


uninit:function(){
var opendivids=new Array();//ITLAN
var groupswithpersist='';
var persistopenids=this.getCookie('acopendivids'); //ITLAN
if (persistopenids!=null){ //ITLAN
persistopenids=(persistopenids=='nada')? [] : persistopenids.split(','); //ITLAN
}
else { persistopenids=new Array();} //ITLAN
opendivids=persistopenids; //ITLAN
jQuery.each(this.divholders, function(){
index=-1;
index=jQuery.inArray(this.id, persistopenids); //ITLAN
if ((this.$divref.css('display')=='none') && this.getAttr('persist')) {
if (index !=-1){ //ITLAN
//open DIV already in cookie
}
else{ //ITLAN
//add DIV to cookie
opendivids.push(this.id); //ITLAN
}
}
else if (index !=-1) { //ITLAN
//Remove DIV from cookie
opendivids.splice(this.id,1); //ITLAN
}
else{
//Do nothing
}
if (this.getAttr('group') && this.getAttr('persist'))
groupswithpersist+=this.getAttr('group')+','; //store groups with which at least one DIV has persistance enabled: 'group1,group2,etc'
});
if (opendivids!=null) opendivids=opendivids.join(','); //ITLAN
opendivids = (opendivids=='') ? 'nada' : opendivids.replace(/,$/, '');
groupswithpersist = (groupswithpersist=='') ? 'nada' : groupswithpersist.replace(/,$/, '');
this.setCookie('acopendivids', opendivids);
this.setCookie('acgroupswithpersist', groupswithpersist);
},