Results 1 to 3 of 3

Thread: Need help with accordion menu script on dynamic drive

  1. #1
    Join Date
    Apr 2012
    Posts
    7
    Thanks
    1
    Thanked 2 Times in 2 Posts

    Default Need help with accordion menu script on dynamic drive

    I want to use the following script but I have an issue while setting it up...

    Here is the script: http://www.dynamicdrive.com/dynamici...menu-urban.htm

    The javascript included has an option to remember the open state of the menu with a cookie... The cookie is passing values such as c0, c1, c2 where c0 is header one, c1 is header 2 and so on...

    I want to have multiple menus on the website remember their own open states and the remember open state cookie is universal so if header one in menu one is open, then menu two header one will also open on load! Is there a way I can have unique cookies for each menu? Example: menu1.c0 menu2.c3 and so on... I am new to javascript and jquery and cannot figure out how to code this.

    I also noticed the querystring option but it is not ideal for me.

    Thanks for your help.

  2. #2
    Join Date
    Apr 2012
    Posts
    7
    Thanks
    1
    Thanked 2 Times in 2 Posts

    Default

    Am I asking for something really hard? I put the same question on three different websites and no one seems to know an answer to this issue? Can someone at least guide me to what I need to do to make the cookies unique with every menu? I read that javascript can read anchor names... how about if add unique anchors to the menus and append the cookie with an anchor name?!

  3. #3
    Join Date
    Aug 2004
    Posts
    10,140
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    That's how the DD Accordion works already actually- each instance of the menu on the page has its own separate persistence setting. The reason it's not working for you most likely is because you're giving the menus shared header and content CSS class names when they should be different for each instance. The below shows how to two separate instances of the accordion menu on a page should be defined, and how each persistence setting is separate from the other:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml2/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    
    <script type="text/javascript" src="ddaccordion.js">
    
    /***********************************************
    * Accordion Content script- (c) Dynamic Drive DHTML code library (www.dynamicdrive.com)
    * Visit http://www.dynamicDrive.com for hundreds of DHTML scripts
    * This notice must stay intact for legal use
    ***********************************************/
    
    </script>
    
    <script type="text/javascript">
    
    ddaccordion.init({
    	headerclass: "headerbar", //Shared CSS class name of headers group
    	contentclass: "submenu", //Shared CSS class name of contents group
    	revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click", "clickgo", or "mouseover"
    	mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
    	collapseprev: true, //Collapse previous content (so only one open at any time)? true/false
    	defaultexpanded: [0], //index of content(s) open by default [index1, index2, etc] [] denotes no content
    	onemustopen: true, //Specify whether at least one header should be open always (so never all headers closed)
    	animatedefault: false, //Should contents open by default be animated into view?
    	persiststate: true, //persist state of opened contents within browser session?
    	toggleclass: ["", "selected"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
    	togglehtml: ["", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
    	animatespeed: "normal", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
    	oninit:function(headers, expandedindices){ //custom code to run when headers have initalized
    		//do nothing
    	},
    	onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
    		//do nothing
    	}
    })
    
    ddaccordion.init({
    	headerclass: "headerbar2", //Shared CSS class name of headers group
    	contentclass: "submenu2", //Shared CSS class name of contents group
    	revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click", "clickgo", or "mouseover"
    	mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
    	collapseprev: true, //Collapse previous content (so only one open at any time)? true/false
    	defaultexpanded: [0], //index of content(s) open by default [index1, index2, etc] [] denotes no content
    	onemustopen: true, //Specify whether at least one header should be open always (so never all headers closed)
    	animatedefault: false, //Should contents open by default be animated into view?
    	persiststate: true, //persist state of opened contents within browser session?
    	toggleclass: ["", "selected"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
    	togglehtml: ["", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
    	animatespeed: "normal", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
    	oninit:function(headers, expandedindices){ //custom code to run when headers have initalized
    		//do nothing
    	},
    	onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
    		//do nothing
    	}
    })
    
    </script>
    
    <style type="text/css">
    
    .urbangreymenu{
    width: 190px; /*width of menu*/
    }
    
    .urbangreymenu .commonbarstyle{
    font: bold 13px Verdana;
    color: white;
    background: #606060 url(arrowstop.gif) no-repeat 8px 6px; /*last 2 values are the x and y coordinates of bullet image*/
    margin-bottom: 0; /*bottom spacing between header and rest of content*/
    text-transform: uppercase;
    padding: 7px 0 7px 31px; /*31px is left indentation of header text*/
    }
    
    .urbangreymenu .commonbarstyle a{
    text-decoration: none;
    color: white;
    display: block;
    }
    
    .urbangreymenu ul{
    list-style-type: none;
    margin: 0;
    padding: 0;
    margin-bottom: 0; /*bottom spacing between each UL and rest of content*/
    }
    
    .urbangreymenu ul li{
    padding-bottom: 2px; /*bottom spacing between menu items*/
    }
    
    .urbangreymenu ul li a{
    font: normal 12px Arial;
    color: black;
    background: #E9E9E9;
    display: block;
    padding: 5px 0;
    line-height: 17px;
    padding-left: 8px; /*link text is indented 8px*/
    text-decoration: none;
    }
    
    .urbangreymenu ul li a:visited{
    color: black;
    }
    
    .urbangreymenu ul li a:hover{ /*hover state CSS*/
    color: white;
    background: black;
    }
    
    </style>
    
    <body>
    
    <div class="urbangreymenu">
    
    <h3 class="headerbar commonbarstyle"><a href="http://www.dynamicdrive.com/style/">CSS Library</a></h3>
    <ul class="submenu">
    <li><a href="http://www.dynamicdrive.com/style/csslibrary/category/C1/">Horizontal CSS Menus</a></li>
    <li><a href="http://www.dynamicdrive.com/style/csslibrary/category/C2/">Vertical CSS Menus</a></li>
    <li><a href="http://www.dynamicdrive.com/style/csslibrary/category/C4/">Image CSS</a></li>
    <li><a href="http://www.dynamicdrive.com/style/csslibrary/category/C6/">Form CSS</a></li>
    <li><a href="http://www.dynamicdrive.com/style/csslibrary/category/C5/">DIVs and containers</a></li>
    <li><a href="http://www.dynamicdrive.com/style/csslibrary/category/C7/">Links & Buttons</a></li>
    <li><a href="http://www.dynamicdrive.com/style/csslibrary/category/C8/">Other</a></li>
    <li><a href="http://www.dynamicdrive.com/style/csslibrary/all/">Browse All</a></li>
    </ul>
    
    <h3 class="headerbar commonbarstyle"><a href="http://www.javascriptkit.com">JavaScript Kit</a></h3>
    <ul class="submenu">
    <li><a href="http://www.javascriptkit.com/cutpastejava.shtml" >Free JavaScripts</a></li>
    <li><a href="http://www.javascriptkit.com/javatutors/">JavaScript tutorials</a></li>
    <li><a href="http://www.javascriptkit.com/jsref/">JavaScript Reference</a></li>
    <li><a href="http://www.javascriptkit.com/dhtmltutors/">DHTML & CSS</a></li>
    <li><a href="http://www.javascriptkit.com/howto/">Web Design</a></li>
    <li><a href="http://www.javascriptkit.com/java/">Free Java Applets</a></li>		
    </ul>
    
    </div>
    
    <br /><br /><br />
    
    <div class="urbangreymenu">
    
    <h3 class="headerbar2 commonbarstyle"><a href="http://www.dynamicdrive.com/style/">CSS Library</a></h3>
    <ul class="submenu2">
    <li><a href="http://www.dynamicdrive.com/style/csslibrary/category/C1/">Horizontal CSS Menus</a></li>
    <li><a href="http://www.dynamicdrive.com/style/csslibrary/category/C2/">Vertical CSS Menus</a></li>
    <li><a href="http://www.dynamicdrive.com/style/csslibrary/category/C4/">Image CSS</a></li>
    <li><a href="http://www.dynamicdrive.com/style/csslibrary/category/C6/">Form CSS</a></li>
    <li><a href="http://www.dynamicdrive.com/style/csslibrary/category/C5/">DIVs and containers</a></li>
    <li><a href="http://www.dynamicdrive.com/style/csslibrary/category/C7/">Links & Buttons</a></li>
    <li><a href="http://www.dynamicdrive.com/style/csslibrary/category/C8/">Other</a></li>
    <li><a href="http://www.dynamicdrive.com/style/csslibrary/all/">Browse All</a></li>
    </ul>
    
    <h3 class="headerbar2 commonbarstyle"><a href="http://www.javascriptkit.com">JavaScript Kit</a></h3>
    <ul class="submenu2">
    <li><a href="http://www.javascriptkit.com/cutpastejava.shtml" >Free JavaScripts</a></li>
    <li><a href="http://www.javascriptkit.com/javatutors/">JavaScript tutorials</a></li>
    <li><a href="http://www.javascriptkit.com/jsref/">JavaScript Reference</a></li>
    <li><a href="http://www.javascriptkit.com/dhtmltutors/">DHTML & CSS</a></li>
    <li><a href="http://www.javascriptkit.com/howto/">Web Design</a></li>
    <li><a href="http://www.javascriptkit.com/java/">Free Java Applets</a></li>		
    </ul>
    
    </div>
    
    </body>
    
    </html>
    Notice how each menu's header and sub content class names need to be unique from the other's (so headerbar verus headerbar2, submenu versus submenu2). That's not to say you can't style all the menus using the same CSS. Just change the target class name to style to an arbitrary name (in this case commonbarstyle), then take advantage of CSS's ability for an element to carry multiple CSS classes and assign this class to both menus to style them the same.
    DD Admin

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
  •