Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Switch Content State memory with php templates

  1. #1
    Join Date
    Jul 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Switch Content State memory with php templates

    Hello everyone,

    Been using dynamic drive scripts for years, love them - best resource on the net...

    Anyways, I've recently decided to use the 'switch content' state script for a new site in development.

    I'm basically using the switch content script as a sidebar outlook style menu across the entire site...works great on all browsers etc...

    However what I would like to do is get the script to remember whether the user has visited the site previously...

    (script url: http://www.dynamicdrive.com/dynamici...tchcontent.htm)

    Yes the script already does this via a cookie, however my site management system is php driven, and as a result the path's for each page end up being unique, in the form http://www.mysite.com/?page=mypage.php

    What I am looking to do is have the state remembered across ALL of the sub-pages of the domain, however the script, by default, only remembers the state for the current page that you are visiting.

    so if the user visits mysite.com/?page=page1.php and opens/expands any of the side menu options - the second they click on a second link in the menu, it doesn't remember the state any more and contracts the entire side menu...

    so the user can open/close any of the submenu options when they are visiting mysite.com/?page=page1.php, but then when they click a link (potentially to mysite.com/?page=page2.php) the menu closes and they end up having to reopen the menu options etc...

    I've tried tweaking the javascript for the cookie handler so that it doesn't save or use the pathname when saving the cookie, but this hasn't fixed it...

    eg:
    Code:
    function getselectedItem(){
    //if (get_cookie(window.location.pathname) != ""){
    //selectedItem=get_cookie(window.location.pathname)
    if (get_cookie(window.location) != ""){
    selectedItem=get_cookie(window.location)
    return selectedItem
    }
    else
    return ""
    }
    
    function saveswitchstate(){
    var inc=0, selectedItem=""
    while (ccollect[inc]){
    if (ccollect[inc].style.display=="block")
    selectedItem+=ccollect[inc].id+"|"
    inc++
    }
    
    //document.cookie=window.location.pathname+"="+selectedItem
    document.cookie=window.location+"="+selectedItem
    }
    
    function do_onload(){
    //uniqueidn=window.location.pathname+"firsttimeload"
    uniqueidn=window.location+"firsttimeload"
    var alltags=document.all? document.all : document.getElementsByTagName("*")
    ccollect=getElementbyClass(alltags, "switchcontent")
    statecollect=getElementbyClass(alltags, "showstate")
    if (enablepersist=="on" && ccollect.length>0){
    document.cookie=(get_cookie(uniqueidn)=="")? uniqueidn+"=1" : uniqueidn+"=0" 
    firsttimeload=(get_cookie(uniqueidn)==1)? 1 : 0 //check if this is 1st page load
    if (!firsttimeload)
    revivecontent()
    }
    if (ccollect.length>0 && statecollect.length>0)
    revivestatus()
    }
    note that this isn't the entire javascript, but you can see where i've commented the changed lines to remove the .pathname entries...

    anyone know how i would get this script to save the expanded/contracted states for ALL of the pages on the single domain/site? basically the entire site system is template driven and essentially 'includes' the content for each individual page within the template.

    simple, but it works. if i can get the cookies to save the state across all of the pages, it would be ideal...

    thanx in advance,
    mike w
    gdgi

  2. #2
    Join Date
    Jul 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    brief followup - yes i know i could use a side-frame to do the same thing, via the 'outlook' type script on dd, but i'd rather have it all in a single page - the graphic design layout wouldn't look as nice with a sideframe...

    thanx

  3. #3
    Join Date
    Jul 2005
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Gekido,

    did you solve this as I'm trying to do the same.

    Also when you quit your browser the cookie is deleted so when you go back to your site all the items are minimized again!

    Would appreciate any help.

    Thanks

  4. #4
    Join Date
    Jul 2005
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Gekido,

    I found from using your updated script that if you also remove.location then it works across all pages served, however when you quit your browser the cookie is still deleted and therefore all items are minimized when you open it again.

    this is my altered part of the script:

    function getselectedItem(){
    //if (get_cookie(window.location.pathname) != ""){
    //selectedItem=get_cookie(window.location.pathname)
    if (get_cookie(window) != ""){
    selectedItem=get_cookie(window)
    return selectedItem
    }
    else
    return ""
    }

    function saveswitchstate(){
    var inc=0, selectedItem=""
    while (ccollect[inc]){
    if (ccollect[inc].style.display=="block")
    selectedItem+=ccollect[inc].id+"|"
    inc++
    }

    //document.cookie=window.location.pathname+"="+selectedItem
    document.cookie=window+"="+selectedItem
    }

    function do_onload(){
    //uniqueidn=window.location.pathname+"firsttimeload"
    uniqueidn=window+"firsttimeload"
    var alltags=document.all? document.all : document.getElementsByTagName("*")
    ccollect=getElementbyClass(alltags, "switchcontent")
    statecollect=getElementbyClass(alltags, "showstate")
    if (enablepersist=="on" && ccollect.length>0){
    document.cookie=(get_cookie(uniqueidn)=="")? uniqueidn+"=1" : uniqueidn+"=0"
    firsttimeload=(get_cookie(uniqueidn)==1)? 1 : 0 //check if this is 1st page load
    if (!firsttimeload)
    revivecontent()
    }
    if (ccollect.length>0 && statecollect.length>0)
    revivestatus()
    }

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Cookie deletion on browser close is an option that can be set in the browser.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #6
    Join Date
    Jul 2005
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Yes I know, but thats not the problem the browser is set right, the cookie still gets deleted.

    The same happends for the example on this site, try it. Open item 3, quit your broweser, reopen and then look at the page again, item 3 will be closed.
    Last edited by matg; 07-18-2005 at 12:40 PM.

  7. #7
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Whoa, isn't that a good thing? Why would you want the switch state to last across browser sessions?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  8. #8
    Join Date
    Jul 2005
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Im implementing this script as a way of customising a left hand side bar.

    The idea is a user chooses from the 7 sections which ones they want minimized or maximized. I need the cookie to be retained as once they have set this once when they return to the site the sections they have chosen to have minimized or maximized are remembered. Think of it as away of having selected portlets but based on a cookie rather than a user ID and login.

    Hope that makes sense.

  9. #9
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Well, I'm new to this but, I'd try changing:
    Code:
    document.cookie=window.location.pathname+"="+selectedItem
    to:
    Code:
    var expdate = new Date("January 1, 3000");
    document.cookie=window.location.pathname+"="+selectedItem+";expires="+expdate.toGMTString();
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  10. #10
    Join Date
    Jul 2005
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks for the help, but thats not doing much at all.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •