Results 1 to 4 of 4

Thread: DD Accordion Menu - Collapse when going to non-expanding item

  1. #1
    Join Date
    Jun 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default DD Accordion Menu - Collapse when going to non-expanding item

    http://www.dynamicdrive.com/dynamici...daccordion.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/e...oors/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!

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

    Default

    The oninit() event 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:

    Code:
    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
    		}
    	}
    },
    DD Admin

  3. #3
    Join Date
    Jun 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Thanks you

    Thanks for your help, that works perfectly.

  4. #4
    Join Date
    Sep 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by ddadmin View Post
    The oninit() event 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:

    Code:
    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'
    Last edited by plankton; 09-09-2009 at 09:26 PM. Reason: Solved

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
  •