PDA

View Full Version : Bullet List Accordion Menu[Verify Code]+[Category+Submenu to be Expanded on load]



poly5
01-14-2010, 05:44 PM
1) Script Title:
Bullet List Accordion Menu with nested levels
2) Script URL (on DD):
http://www.dynamicdrive.com/dynamicindex17/ddaccordionmenu-bullet.htm
3) Describe problem:
1.
I have absolutely no programming knowledge and before i posted i searched the forums and tried to figure it out on my own. If someone can verify that the below code is correct, or do you see any mistakes? [I havent published the site yet, but everything seems to work fine]

i have 3 main categories. The second category has multiple subcategories, and one of them has its own sub:

Our Company
-Home
-The Center

Our Services
-Services Catalogue

-Success Skills [Subcategory1]
-- Success Without Hard Work
-- Building Blocks of success

-Health & Welness [Subcategory1]
--Extend Your Life
--The Body I Want

-Money & Carreer[Subcategory1]
--Money[subcategory2]
---Achieve Financial Independence
---Deal with the recession
--Carreer[subcategory2]
---Speak Like A Pro
---Manage Your Time


======================================================


<br>
<br>

<div class="arrowlistmenu">

<h3 class="menuheader expandable">Our Company</h3>
<ul class="categoryitems">
<li><a href="index.html">Home</a></li>
<li><a href="the_center.html"> The Center</a></li>
<li><a href="what_do_we_do.html">What do we do</a></li>
<li><a href="our_philosophy.html">Our Philosophy</a></li>
</ul>

<h3 class="menuheader expandable">Our Services</h3>
<ul class="categoryitems">
<li><a href="services.html">Services - Catalogue</a></li>
<li><a href="success_skills.html" class="subexpandable">Success Skills</a>
<ul class="subcategoryitems" style="margin-left: 15px">
<li><a href="success_without_hard_work.html">Success Without Hard Work</a></li>
<li><a href="Bright_Future.html">Bright Future</a></li>
<li><a href="Building Blocks of Success.html">Building Blocks of Success</a></li>
</ul>




<li><a href="health_fitness.html" class="subexpandable">Health & Welness</a>
<ul class="subcategoryitems" style="margin-left: 15px">
<li><a href="health_fitness.html">Health & Welness catalogue</a></li>
<li><a href="extend_your_life.html">Extend Your Life</a></li>
<li><a href="the body i want.html">The Body I Want</a></li>
<li><a href="quit_now.html">Quit Now</a></li>
</ul>


<li><a href="money_carreer.html" class="subexpandable">ΧMoney & Carreer</a>
<ul class="subcategoryitems" style="margin-left: 15px">
<li><a href="money_carreer.html">Money & Carreer Catalogue</a></li>

<li><a href="wealth.html" class="sub2expandable">Money</a>
<ul class="subcategory2items" style="margin-left: 15px">
<li><a href="wealth.html">ΧMoney Catalogue</a></li>
<li><a href="financial_Independencea.html">Achieve Financial Independence</a></li>
<li><a href="deal_with_the_recession.html">Deal with the recession</a></li>
</ul>


<li><a href="carreer.html" class="sub2expandable">Carreer</a>
<ul class="subcategory2items" style="margin-left: 15px">
<li><a href="carreer.html">Carreer Catalogueς</a></li>
<li><a href="speak_like_a_pro.html">Speak Like A Pro</a></li>
<li><a href="manage_your_time.html">Manage Your Time</a></li>
</ul>
</ul>



<li><a href="school_education.html" class="subexpandable">School & Education</a>
<ul class="subcategoryitems" style="margin-left: 15px">
<li><a href="school_education.html">School & Education Catalogue</a></li>
<li><a href="genius_mind.html">Genius Mind</a></li>
<li><a href="good_grades.html">Good Grades</a></li>
</ul>




<li><a href="love_relationships.html" class="subexpandable">Love & Relationships</a>
<ul class="subcategoryitems" style="margin-left: 15px">
<li><a href="love_relationships.html">ove & Relationships</a></li>
<li><a href="transform_your_relationships.html">Transform Your Relationship/a></li>
</ul>


</li>
</ul>

<h3 class="menuheader expandable">Resources</h3>
<ul class="categoryitems">
<li><a href="articles.html">Articles</a></li>
</ul>
</div>

=========================================================

2. when the page laods i would like the following to be expanded:

Our Company
Our Services
==> Money & Carreer
==========>Carreer


I have tried the following: [at the]

ddaccordion.init({ //top level headers initialization
defaultexpanded: [index1, index2] OR [1,2] OR [index.html,services.html]

ddaccordion.init({ //2nd level headers initialization
defaultexpanded: [index3]OR [2] OR [money_carreer.html]

ddaccordion.init({ //3rd level headers initialization
defaultexpanded: [index2]OR [2] OR [carreer.html]

Nothing has worked. To most of you this is really easy, but i have no clue how to do it.

Thanks guys

poly5
01-14-2010, 05:45 PM
And this is the first part of the script:




<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.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({ //top level headers initialization
headerclass: "expandable", //Shared CSS class name of headers group that are expandable
contentclass: "categoryitems", //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: [], //index of content(s) open by default [index1, index2, etc]. [] denotes no content
onemustopen: false, //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: ["", "openheader"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
togglehtml: ["prefix", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively ["position", "html1", "html2"] (see docs)
animatespeed: "fast", //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({ //2nd level headers initialization
headerclass: "subexpandable", //Shared CSS class name of sub headers group that are expandable
contentclass: "subcategoryitems", //Shared CSS class name of sub contents group
revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click" 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: [], //index of content(s) open by default [index1, index2, etc]. [] denotes no content
onemustopen: false, //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: ["opensubheader", "closedsubheader"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
togglehtml: ["none", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively ["position", "html1", "html2"] (see docs)
animatespeed: "fast", //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({ //3rd level headers initialization
headerclass: "sub2expandable", //Shared CSS class name of sub headers group that are expandable
contentclass: "subcategory2items", //Shared CSS class name of sub contents group
revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click" 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: [], //index of content(s) open by default [index1, index2, etc]. [] denotes no content --was 0
onemustopen: false, //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: ["opensub2header", "closedsub2header"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
togglehtml: ["none", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively ["position", "html1", "html2"] (see docs)
animatespeed: "fast", //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">

.arrowlistmenu{
width: 180px; /*width of accordion menu*/
}

.arrowlistmenu .menuheader{ /*CSS class for menu headers in general (expanding or not!)*/
font: bold 14px Arial;
color: white;
background: black url(titlebar.png) repeat-x center left;
margin-bottom: 10px; /*bottom spacing between header and rest of content*/
text-transform: uppercase;
padding: 4px 0 4px 10px; /*header text is indented 10px*/
cursor: hand;
cursor: pointer;
}

.arrowlistmenu .openheader{ /*CSS class to apply to expandable header when it's expanded*/
background-image: url(titlebar-active.png);
}

.arrowlistmenu ul{ /*CSS for UL of each sub menu*/
list-style-type: none;
margin: 0;
padding: 0;
margin-bottom: 8px; /*bottom spacing between each UL and rest of content*/
}

.arrowlistmenu ul li{
padding-bottom: 2px; /*bottom spacing between menu items*/
}

.arrowlistmenu ul li .opensubheader{ /*Open state CSS for sub menu header*/
background: lightblue !important;
}

.arrowlistmenu ul li .closedsub2header{ /*Closed state CSS for sub menu header*/
background: lightgreen !important;
}

.arrowlistmenu ul li .opensub2header{ /*Open state CSS for sub menu header*/
background: lightblue !important;
}

.arrowlistmenu ul li .closedsubheader{ /*Closed state CSS for sub menu header*/
background: lightgreen !important;
}


.arrowlistmenu ul li a{
color: #A70303;
background: url(arrowbullet.png) no-repeat center left; /*custom bullet list image*/
display: block;
padding: 2px 0;
padding-left: 19px; /*link text is indented 19px*/
text-decoration: none;
font-weight: bold;
border-bottom: 1px solid #dadada;
font-size: 90%;
}

.arrowlistmenu ul li a:visited{
color: #A70303;
}

.arrowlistmenu ul li a:hover{ /*hover state CSS*/
background-color: #F3F3F3;
}

.arrowlistmenu ul li a.subexpandable:hover{ /*hover state CSS for sub menu header*/
background: lightblue;
}

.arrowlistmenu ul li a.sub2expandable:hover{ /*hover state CSS for sub menu header*/
background: lightblue;
}

</style>

poly5
02-10-2010, 01:50 PM
Guys can someone PLEASE let me know how to have the following to be expanded:

Our Company
Our Services
==> Money & Carreer
==========>Carreer


I have tried the following: [at the]

ddaccordion.init({ //top level headers initialization
defaultexpanded: [index1, index2] OR [1,2] OR [index.html,services.html]

ddaccordion.init({ //2nd level headers initialization
defaultexpanded: [index3]OR [2] OR [money_carreer.html]

ddaccordion.init({ //3rd level headers initialization
defaultexpanded: [index2]OR [2] OR [carreer.html]


I would greatly appreciate if someone helped me out with this

ddadmin
02-11-2010, 11:50 AM
I'll try and take a look at this thread later today. It's really late at the moment.

ddadmin
02-12-2010, 12:35 AM
Inside your configuration code, you can make use of the defaultexpanded[] option to set a particular header to be expanded by default. You will also want to turn of persiststate, at least while you're testing things out. So for example:


<script type="text/javascript">

ddaccordion.init({ //top level headers initialization
headerclass: "expandable", //Shared CSS class name of headers group that are expandable
contentclass: "categoryitems", //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: [1], //index of content(s) open by default [index1, index2, etc]. [] denotes no content
onemustopen: false, //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: false, //persist state of opened contents within browser session?
toggleclass: ["", "openheader"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
togglehtml: ["prefix", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively ["position", "html1", "html2"] (see docs)
animatespeed: "fast", //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({ //2nd level headers initialization
headerclass: "subexpandable", //Shared CSS class name of sub headers group that are expandable
contentclass: "subcategoryitems", //Shared CSS class name of sub contents group
revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click" 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: false, //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: false, //persist state of opened contents within browser session?
toggleclass: ["opensubheader", "closedsubheader"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
togglehtml: ["none", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively ["position", "html1", "html2"] (see docs)
animatespeed: "fast", //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({ //3rd level headers initialization
headerclass: "sub2expandable", //Shared CSS class name of sub headers group that are expandable
contentclass: "subcategory2items", //Shared CSS class name of sub contents group
revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click" 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 --was 0
onemustopen: false, //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: false, //persist state of opened contents within browser session?
toggleclass: ["opensub2header", "closedsub2header"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
togglehtml: ["none", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively ["position", "html1", "html2"] (see docs)
animatespeed: "fast", //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>

With the above, the 2nd main header->1st sub header->1st sub sub header should be expanded by default. I may have gotten the order of the "Category" header relative to your other headers wrong though, so adjust "1" accordingly above.

poly5
02-12-2010, 03:01 PM
DD Admin,

thanks it worked.

2 More things:

1. Can i have 2 indexes expanded at the same time? i have tried this but it doesnt seem to work for some reason:





<script type="text/javascript">

ddaccordion.init({ //top level headers initialization
headerclass: "expandable", //Shared CSS class name of headers group that are expandable
contentclass: "categoryitems", //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,1], //index of content(s) open by default [index1, index2, etc]. [] denotes no content
onemustopen: false, //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: false, //persist state of opened contents within browser session?
toggleclass: ["", "openheader"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
togglehtml: ["prefix", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively ["position", "html1", "html2"] (see docs)
animatespeed: "fast", //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({ //2nd level headers initialization
headerclass: "subexpandable", //Shared CSS class name of sub headers group that are expandable
contentclass: "subcategoryitems", //Shared CSS class name of sub contents group
revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click" 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: [1,3], //index of content(s) open by default [index1, index2, etc]. [] denotes no content
onemustopen: false, //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: false, //persist state of opened contents within browser session?
toggleclass: ["opensubheader", "closedsubheader"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
togglehtml: ["none", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively ["position", "html1", "html2"] (see docs)
animatespeed: "fast", //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({ //3rd level headers initialization
headerclass: "sub2expandable", //Shared CSS class name of sub headers group that are expandable
contentclass: "subcategory2items", //Shared CSS class name of sub contents group
revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click" 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 --was 0
onemustopen: false, //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: false, //persist state of opened contents within browser session?
toggleclass: ["opensub2header", "closedsub2header"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
togglehtml: ["none", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively ["position", "html1", "html2"] (see docs)
animatespeed: "fast", //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>




2. According to this thread: http://www.dynamicdrive.com/forums/showthread.php?p=208058

The structure for multi-level unordered list menus is generally as follows:


<ul>
<li>Parents
<ul>
<li>Child 1</li>
<li>Child 2
<ul>
<li>Grandchild 1</li>
<li>Grandchild 2</li>
</ul>
</li>
</ul>
</li>
</ul>

The structure that i have is kind of different (posted on the 1st post of this thread) and i dont have any troubles. Would you recommend that i change it to the above, or should i leave it as it is?


Thanks