Logged Out
Create an Account
Login:
Password:

Forgot your password?
Java ... Cookies ... Need some help

Java ... Cookies ... Need some help
[Back to Index]  [Bottom of Thread]
Thread Tags
Primary: [Advanced Layout]
Secondary: None
So, I have sort of backed myself into a bit of a hole with my site ... One of the reasons, once upon a time, that I started to code my own site is so that I would understand everything I was doing ... but it took too much time, and this site is probably better than I could have made anyway ...

So ... now I have gone about applying what I had learned to creating an advance layout. Which I think I have done decently at ... but in the process I have sort of pasted a few too many snipets of code that I really don't understand.

So, what I need help with is the collapsable menus. I really need them to save their states. Basically, if I understand correctly, the code I pasted in would close all of the other menus except for the "active" one ... I went in and took out the part where it closes all of the other menues, and I like the way that works, but I want it to save the state of the menus from session to session. I would also like new users, or people without cookies for my site to see all of the menus in their open state.

Any suggestions on how I should go about doing that?

I'll attach my layout file :

Thanks,
Dj

--
http://www.dkpsystem.com/viewthread.php?threadid=3212&p=1

The above thread has a file I created called ActionScriptGeneric.js.

There's also instructions on how to implement it. It should have all the code you need to do exactly what you want. Be sure to read the whole thread, as I have 2 versions of the file linked... the 2nd one being the one you'd like.
hey dj... not sure if you got it figured out... but anyway, I was reviewing your code, and while you aren't using the script I provided, I was able to determine a problem in yours.

The savemenustate() function is actually working apparently. You can test this by testing the state of your Guild Rules menu box.

The problem is that it will only save the state of 1 menu option based on the way you wrote it. here's your current code:


function savemenustate(){
var inc=1, blockid=""
while (document.getElementById("sub"+inc)){
if (document.getElementById("sub"+inc).style.display=="block"){
blockid="sub"+inc
break
}
inc++
}
var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
var cookievalue=(persisttype=="sitewide")? blockid+";path=/" : blockid
document.cookie=cookiename+"="+cookievalue
}



If you change it to the following, it will loop through ALL menus and create an comma-delimited string of them, which can later be turned into an array.


function savemenustate(){
var inc=1, blockid=""
while (document.getElementById("sub"+inc)){
if (document.getElementById("sub"+inc).style.display=="block"){
if (blockid != "") {
blockid+=","
}
blockid+="sub"+inc;
var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
var cookievalue=(persisttype=="sitewide")? blockid+";path=/" : blockid
document.cookie=cookiename+"="+cookievalue
}
inc++
}
}



Now blockid is your comma-delimited string, and your cookie will save this way.

Next, we'll need to change your onload function. Here's what it currently is:

function onloadfunction(){
if (persistmenu=="yes"){
var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
var cookievalue=get_cookie(cookiename)
if (cookievalue!="")
document.getElementById(cookievalue).style.display="block"
}
}



Here's what it should be:

function onloadfunction(){
if (persistmenu=="yes"){
var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
var cookievalue=get_cookie(cookiename)
if (cookievalue!=""){
var aCookieArray = cookievalue.split(",");
for (i=0; i<aCookieArray.length; i++) {
document.getElementById(aCookieArray[i]).style.display="block"
}
}
}
}



Note that this is untested, so if I fudged something, I apologize. However, you should be able to figure out the basics from this.


Thanks so much! I will look into this soon, I hope >.> lol my ... been spending too much time getting my warrior ready to tank it up in outlands ^_^

EDIT : Awesome, it worked I think!

So if in the future, I redo the menubar on the right, this will automatically pick those up? It looks like you accomplished this by checking for the existence of the variables somehow? ( java is like french to me ( Where as html is like ghetto in that I can pick through it at this point because I lived there for a while (no, I've never actually lived in a ghetto, but I have been staring at html for years ... just usually glossed over any java I saw))).

EDIT2 : The main reason I never got around to the code you initially suggested is ... I wouldn't have known where to begin with ripping out the code I had already started with ^_^

I remember the first piece of Java I looked at .. was from the eqdkp pages, and how they had a column of player names in the database that you clicked and they moved over to the "in the raid" column ... I never did figure that one out :{

Anyway, thanks again!

--
I think I have 1 final problem with this thing, and that is that when I close the browser, and reopen the browser, the menu states aren't saved.

function onloadfunction(){
if (persistmenu=="yes"){
var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
var cookievalue=get_cookie(cookiename)
if (cookievalue!=""){
var aCookieArray = cookievalue.split(",");
for (i=0; i<aCookieArray.length; i++) {
document.getElementById(aCookieArray[i]).style.display="block"
}
}
}
}


Im guessing the problem is in here :

for (i=0; i<aCookieArray.length; i++) {
document.getElementById(aCookieArray[i]).style.display="block"
}


Where it looks to me like it is assigning "block" to everything ... I'm just not sure how to change it to read from the cookie data?

--
I'm pretty busy this weekend. I'll take a look at it next week. Sorry for the delay.
Bump again as this has me totaly befuddled.

--
WTT Broken I.W.I.N. ButtonRefresh This Item for help with this code!! PST....

--
Quote by dj
WTT Broken I.W.I.N. ButtonRefresh This Item for help with this code!! PST....


And... I'm back. Hey DJ. It's be a LONG while since I've been to the main DKPSystem forums. But I'm back. I'll see if I can get you help you soon.
Quote
And... I'm back. Hey DJ. It's be a LONG while since I've been to the main DKPSystem forums. But I'm back. I'll see if I can get you help you soon.


I was wondering where the hell you went.


And I forgot about this thread, I'm sorry DJ. I'll be having a look at it today.

--
It's all in the reflexes.
The problem is that you're not setting an expire date on the cookie. The default behavior when you set a cookie is to create a "session cookie" (i.e. it's deleted when you close the browser)

when you've got a line like:

var cookievalue=(persisttype=="sitewide")? blockid+";path=/" : blockid


stick these lines directly after it:

var now = new Date()
now.setYear(now.getYear() + 5) // expire the cookie in 5 years
cookievalue += "; expires=" + now.toGMTString()



i.e., so you've got something like the following:

var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
var cookievalue=(persisttype=="sitewide")? blockid+";path=/" : blockid
var now = new Date()
now.setYear(now.getYear() + 5) // expire the cookie in 5 years
cookievalue += "; expires=" + now.toGMTString()
document.cookie=cookiename+"="+cookievalue



Heehee yeah Chops... things got a little crazy. I ended up selling my company, and now I'm working for a new company. Kinda wierd not being my own boss... but refreshing at the same time.

Also, I'm getting quite a hands-on education with .NET web coding... something I hadn't had the opportunity to really focus on while I was busy running my own company. It's a lot of C# stuff, and I'm really enjoying it.

Any-whoodle... yeah I'm back.
Quote
Any-whoodle... yeah I'm back.

Glad to hear it.

Check a private thread I sent you a while back.

I know we're getting way off topic, but you'll be excited to see that those Advanced Layout changes are in motion (fixing the CSS everywhere, to allow content to be controlled to a degree), as well as the news and forums are getting their own Advanced Layout options.

--
It's all in the reflexes.
Chops ... I am having problems with my layout.htm updating. I have tried for 3 days now, uploading what Nevir suggested, but the changes don't seem to save, or at least show up in the source. What is odd is when I "save as" the current layout file from the Admin page, the changes are there.

--
Check it out. Does it look right to you now?

--
It's all in the reflexes.
Yea the source looks right. I'll test the menu functions. Why wasn't it updating?


--
Anyway, Thanks a ton Nevir! That is what I was looking for. There is still something a little odd about it's functionality ... basically if I open a frame, then close it, then open another one, the second frame opens, but the first frame opens as well. That is probably something I can figure out myself though ... just need to find some time to sit down and look back over it all.

Thanks again!
Dj

--
Quote
Yea the source looks right. I'll test the menu functions. Why wasn't it updating?


Were you clicking "Test It" first? That's the button that actually does the compilation.

--
It's all in the reflexes.
I wasn't, no. I didn't know we had to test it ^_^ ... I didn't think that particular change was really testeable with the test page.

--
The "Test It" is forced for one major reason, that it prevent someone from deploying completely broken code.

Say you modify the page, and just before saving it, accidentally delete an important line of code that completely throws off the code and disables the content of the page by hiding it in a broken div.

Forcing "Test It" generally ensures* that someone isn't going to deploy that broken code, because the results from the "Test It" page are obvious.



*You'd be surprised how many people deploy completely broken layouts (even after clicking "Test It"), at which point the only fix is for me to disable the Advanced Layout.

--
It's all in the reflexes.


[Back to Index]  [Top of Thread]