Results 1 to 6 of 6

Thread: Auto display specific Switch Menu subs upon opening

  1. #1
    Join Date
    Aug 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Auto display specific Switch Menu subs upon opening

    Switch Menu

    Here is what I am trying to do. Here is my tree...

    a
    ...1
    ...2
    ...3
    b
    ...1
    ...2
    ...3
    c
    ...1
    ...2
    ...3

    When "a1" loads for the first time, I want the "a" submenu to automatically display. When "b1" loads for the first time, I want the "b" submenu to automatically display. When "c1" loads for the first time, I want the "c" submenu to automatically display.

    Right now my opening page has links to a1, b1, and c1. So, when I click on those links, I want the corresponding submenus to automatically display.

    I want to continue using persistance sitewide.

    What modification can you suggest?

    Thanks!
    Last edited by mdivrx; 02-27-2006 at 07:48 PM.

  2. #2
    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

    Find this function in the script:

    Code:
    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"
    else
    document.getElementById('sub1').style.display="block"
    }
    }
    Add the part in red. Use the desired id (in green) for each page.
    - John
    ________________________

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

  3. #3
    Join Date
    Mar 2006
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    By using your proposed solution jscheuer1, sub1 is always open even if you close it and browse to another page (eliminates sitewide persistence for sub1). Is it possible to make it so that if you close sub1, it also has persistence and keeps it closed/open with sitewide persistence? Anyone got a solution?
    Last edited by Crimsonbat; 03-20-2006 at 09:32 PM.

  4. #4
    Join Date
    Mar 2006
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    please help!!

  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

    That's how my modification does function, are you sure you have persistence turned on? The only exception being that if all items are closed, sub1 again becomes the default. Additionally, with this setup, you need not use sub1 on each page that has the script, then only the sub# on each page would have precedence if none were selected previously.
    - John
    ________________________

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

  6. #6
    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

    If you want to go to the point where once the menu is run, all bets are off as it were with persistence overriding all previous script settings in a sitewide install, use this script (set the sub# you want initially in the two spots highlighted red in onloadfunction() ):

    Code:
    <script type="text/javascript">
    
    /***********************************************
    * Switch Menu script- by Martial B of http://getElementById.com/
    * Modified by Dynamic Drive for format & NS4/IE4 compatibility
    * Visit http://www.dynamicdrive.com/ for full source code
    * Modified here to have a default menu open if first time
    * run by jscheuer1 in http://www.dynamicdrive.com/forums
    ***********************************************/
    
    var persistmenu="yes" //"yes" or "no". Make sure each SPAN content contains an incrementing ID starting at 1 (id="sub1", id="sub2", etc)
    var persisttype="sitewide" //enter "sitewide" for menu to persist across site, "local" for this page only
    
    if (document.getElementById){ //DynamicDrive.com change
    document.write('<style type="text/css">\n')
    document.write('.submenu{display: none;}\n')
    document.write('</style>\n')
    }
    
    function SwitchMenu(obj){
    	if(document.getElementById){
    	var el = document.getElementById(obj);
    	var ar = document.getElementById("masterdiv").getElementsByTagName("span"); //DynamicDrive.com change
    		if(el.style.display != "block"){ //DynamicDrive.com change
    			for (var i=0; i<ar.length; i++){
    				if (ar[i].className=="submenu") //DynamicDrive.com change
    				ar[i].style.display = "none";
    			}
    			el.style.display = "block";
    		}else{
    			el.style.display = "none";
    		}
    	}
    }
    
    function get_cookie(Name) { 
    var search = Name + "="
    var returnvalue = "";
    if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    if (offset != -1) { 
    offset += search.length
    end = document.cookie.indexOf(";", offset);
    if (end == -1) end = document.cookie.length;
    returnvalue=unescape(document.cookie.substring(offset, end))
    }
    }
    return returnvalue;
    }
    
    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"
    else if (get_cookie(cookiename+'2')!=='run'){
    document.getElementById('sub1').style.display="block"
    }
    }
    else
    document.getElementById('sub1').style.display="block"
    }
    
    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
    document.cookie=cookiename+"2=run"+(persisttype=="sitewide"?";path=/":"")
    }
    
    if (window.addEventListener)
    window.addEventListener("load", onloadfunction, false)
    else if (window.attachEvent)
    window.attachEvent("onload", onloadfunction)
    else if (document.getElementById)
    window.onload=onloadfunction
    
    if (persistmenu=="yes" && document.getElementById)
    window.onunload=savemenustate
    
    </script>
    - John
    ________________________

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

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
  •