Collapsible Menus + Cookie settings

Discussion in 'Web Design & Coding' started by Electronic Punk, May 31, 2006.

  1. Electronic Punk

    Electronic Punk Administrator Staff Member Political User Folding Team

    Messages:
    18,590
    Location:
    Copenhagen, Denmark
    I have been looking for a script that will allow me to collapse and expand menus easily and save that data across sessions using cookies.

    Thought I had one...

    (rename to .html and .js)
     

    Attached Files:

  2. Electronic Punk

    Electronic Punk Administrator Staff Member Political User Folding Team

    Messages:
    18,590
    Location:
    Copenhagen, Denmark
    Was very pleased and was looking at a way of integrating it into our headline block having told Neobond and Redmak that I loved it and was going to have to steal the idea. (gave em more to compensate)

    Put it in my makeshift test theme:
    http://www.osnn.net/index.php?&themeid=3

    (also had some other work done it on, been cleaning up the menus and changing a few things before I push it out to the other themes - clearing things up for some reason)

    You can see the script in action at the top, but sadly for some reason it is
    a) collapsed by default (bad)
    b) doesn't save across sessions so remains collapsed.

    This is the most suitable script I could find and I have been looking for a while.

    Any cookie pro's why is this not working?

    Collapse bit isn't final by the way, I just wanted to get it working.
     
  3. SPeedY_B

    SPeedY_B I may actually be insane.

    Messages:
    15,800
    Location:
    Midlands, England
    It's not remaining open/closed because no cookie is being set. ;)

    And it's default to closed because of this
    Code:
    if (document.getElementById){
    document.write('<style type="text/css">')
    document.write('.switchcontent{[b]display:none;[/b]}')
    document.write('</style>')
    }
    which, to me at least, seems a nasty way of doing it anyway.
     
  4. Electronic Punk

    Electronic Punk Administrator Staff Member Political User Folding Team

    Messages:
    18,590
    Location:
    Copenhagen, Denmark
    Well I am of course open to new scripts :D
    Also why is it not setting a cookie? Because one exists?

    Works offline ? :s
     
  5. Electronic Punk

    Electronic Punk Administrator Staff Member Political User Folding Team

    Messages:
    18,590
    Location:
    Copenhagen, Denmark
    Hmm, cookie doesn't seem to be working now, must have cut too much out! :eek:
     
  6. SPeedY_B

    SPeedY_B I may actually be insane.

    Messages:
    15,800
    Location:
    Midlands, England
  7. Electronic Punk

    Electronic Punk Administrator Staff Member Political User Folding Team

    Messages:
    18,590
    Location:
    Copenhagen, Denmark
    Can't wait :)

    Was thinking it was because I didn't give the div an id, cos the source script works fine, but it erm, wasn't.
     

    Attached Files:

  8. LordOfLA

    LordOfLA Godlike!

    Messages:
    7,027
    Location:
    Maidenhead, Berkshire, UK
    Except it dont work in firefox 1.5.0.1 (dont ask - i keep asking for .3 to be rolled out across active directory...)
     
  9. Electronic Punk

    Electronic Punk Administrator Staff Member Political User Folding Team

    Messages:
    18,590
    Location:
    Copenhagen, Denmark
    worst that can happen if it doesn't work in an old version of firefox is that they will just see everything.
     
  10. SPeedY_B

    SPeedY_B I may actually be insane.

    Messages:
    15,800
    Location:
    Midlands, England
    Works fine in 1.5.0.3, and I doubt there were any major changes in the javascript engine between the two versions.

    You sure you have JS enabled?
     
  11. Electronic Punk

    Electronic Punk Administrator Staff Member Political User Folding Team

    Messages:
    18,590
    Location:
    Copenhagen, Denmark
    Don't get sidetracked speedy, we can do this!
     
  12. SPeedY_B

    SPeedY_B I may actually be insane.

    Messages:
    15,800
    Location:
    Midlands, England
    cookified :p

    Works for me in WebKit, Gecko and Opera (Can't test IE ;P).

    The cookie could be a bit more refined, rather than setting it to a date in May 2100, but for simplicities sake, that's how I've done it in the example :D
     
  13. Electronic Punk

    Electronic Punk Administrator Staff Member Political User Folding Team

    Messages:
    18,590
    Location:
    Copenhagen, Denmark
  14. SPeedY_B

    SPeedY_B I may actually be insane.

    Messages:
    15,800
    Location:
    Midlands, England
    That seems to be a rather large script for such simple functionality.

    Have changed it to only one link is showing now. Niff. :)
     
  15. Electronic Punk

    Electronic Punk Administrator Staff Member Political User Folding Team

    Messages:
    18,590
    Location:
    Copenhagen, Denmark
    Oooh spangley.
    Any idea why its not working on the frontpage?

    Trying to put them in a .js if I can which is called in the header tag, could be the problem.
     
  16. SPeedY_B

    SPeedY_B I may actually be insane.

    Messages:
    15,800
    Location:
    Midlands, England
    Yup, due to the way it interacts, the JS needs to be in the body, below the div/item we're collapsing. You can still call it via a .js, but it just needs to be below. :)
     
  17. Electronic Punk

    Electronic Punk Administrator Staff Member Political User Folding Team

    Messages:
    18,590
    Location:
    Copenhagen, Denmark
    righty hoe.
     
  18. Electronic Punk

    Electronic Punk Administrator Staff Member Political User Folding Team

    Messages:
    18,590
    Location:
    Copenhagen, Denmark
    put it right at the bottom, must have overlooked something else.
     
  19. SPeedY_B

    SPeedY_B I may actually be insane.

    Messages:
    15,800
    Location:
    Midlands, England
    Just had a quick look,

    <div class="content" ... >

    should be

    <div id="content" ... >

    :)
     
  20. Electronic Punk

    Electronic Punk Administrator Staff Member Political User Folding Team

    Messages:
    18,590
    Location:
    Copenhagen, Denmark
    <-- numpty.

    gonna go check it.