View Full Version : DD Accordion Menu - Collapse when going to non-expanding item
markox
06-01-2009, 11:14 AM
http://www.dynamicdrive.com/dynamicindex17/ddaccordion.htm
I am trying to build an accordion menu that contains expanable items and non-expanding items. I want the expanable panels to persist but want the expanded items to close when I go to the homepage which is a non-expanding link.
Example: http://www.mkxdesign.co.uk/clients/elan/great-outdoors/index.php
Home, Contact us and Testimonials are non-expanding items, I want to close all open menus when a user goes to those pages.
Any help appreciated!
ddadmin
06-02-2009, 06:58 AM
The oninit() event (http://www.dynamicdrive.com/dynamicindex17/ddaccordion_suppliment2.htm) probably would work best here. Basically, inside it, you'd check the current page URL against a list of file names that should mean the menu should be collapsed, and if found, collapse the menu. Something like:
oninit:function(headers, expandedindices){ //custom code to run when headers have initalized
var currentpageurl=window.location.href
var closedpages=['index.html', 'about.html', 'test.html']
for (var i=0; i<closedpages.length; i++){
if (currentpageurl.indexOf(closedpages[i])!=-1){ //if current page matches one of the closed'
ddaccordion.collapseall(this.headerclass)
break
}
}
},
markox
06-02-2009, 08:02 AM
Thanks for your help, that works perfectly.
plankton
09-08-2009, 12:14 AM
The oninit() event (http://www.dynamicdrive.com/dynamicindex17/ddaccordion_suppliment2.htm) probably would work best here. Basically, inside it, you'd check the current page URL against a list of file names that should mean the menu should be collapsed, and if found, collapse the menu. Something like:
oninit:function(headers, expandedindices){ //custom code to run when headers have initalized
var currentpageurl=window.location.href
var closedpages=['index.html', 'about.html', 'test.html']
for (var i=0; i<closedpages.length; i++){
if (currentpageurl.indexOf(closedpages[i])!=-1){ //if current page matches one of the closed'
ddaccordion.collapseall(this.headerclass)
break
}
}
},
This solution works fine for any page, except home page like http://domain.com (without suffix). If I add 'domain.com' or '/' or '' into the list, collapseall start working at any page what is not acceptable.
Any ideas how to force collapsing to work correctly with the home page?
Thanks!
Solved by changing 1 string:
if (currentpageurl.indexOf(closedpages[i])!=-1 || currentpageurl=='http://domain.name/'){ //if current page matches one of the closed'
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.