We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6408
    • 58 Posts
    Hi, Im having a bit of trouble trying to get the jquery wayfinder accordion menu working in Revolution.
    Basically, if the user is in a submenu and clicks a menu item (with no sub-menu) then the submenu from the previous page remains open on the new page.
    Im using jQuery with the ddAccordion script as outlined here: http://wiki.modxcms.com/index.php/Accordion_menu_with_Wayfinder_using_JQuery

    Here is my snippet call and chunks:

    the snippet call:
    [[!Wayfinder? &startId=`0` &outerTpl=`wfOuter` &parentRowTpl=`wfParentRow` &activeParentRowTpl=`wfActiveParentRow` &innerTpl=`wfInner` &rowTpl=`wfRow` &innerRowTpl=`wfInnerRow` &cssTpl=`wfStyle` &jsTpl=`wfJs` &hereTpl=`wfHere`]]


    wfOuter:
    <div class="accordion-menu">
      <ul>
       [[+wf.wrapper]]
      </ul>
    </div>


    wfParentRow:
    <li><a class="menuitem submenuheader" href="[[+wf.link]]" title="[[+wf.title]]">[[+wf.linktext]]</a>
    [[+wf.wrapper]]</li>


    wfActiveParentRow:
    <li><a class="menuitem submenuheader" id="active-submenuheader" href="[[+wf.link]]" title="[[+wf.title]]">[[+wf.linktext]]</a>
    [[+wf.wrapper]]</li>


    wfInner:
    <ul class="submenu">
     [[+wf.wrapper]]
    </ul>


    wfRow:
    <li><a class="menuitem" href="[[+wf.link]]" title="[[+wf.title]]">[[+wf.linktext]]</a></li>


    wfInnerRow:
    <li><a href="[[+wf.link]]" title="[[+wf.title]]">[[+wf.linktext]]</a></li>


    wfStyle:
    .mainNav ul li {list-style-type:none;}
    .mainNav ul li a { color:#F1F1F1;text-decoration:none; font-size:0.8em;}
    .accordion-menu ul {margin-bottom:0px; padding:0px; font-family: 'MyUnderwoodRegular', Courier New, Courier, monospace;}
    .accordion-menu {padding:0px}
    
    .accordion-menu a.menuitem{/*background:#010101;*/display:block;width:auto;padding:2px 0 2px 2px;}
    .accordion-menu li{list-style-type:none; margin:0px; padding:0px; display:block;    }
    .accordion-menu .menuitem:active{}
    .accordion-menu a.menuitem:visited {color:#F1F1F1;padding:3px 0 3px 5px;}
    .accordion-menu a.menuitem:hover{background:#999999; color:#000000;}
    .accordion-menu ul.submenu{list-style-type:none;}
    .accordion-menu ul.submenu li{/*background:#FFFFFF;*/border:none;}
    .accordion-menu ul.submenu li a{text-indent:8px;/*background:#010101;*/display:block;color:#CCCCCC;
    list-style-type:square;padding:2px 0 2px 0px;}
    .accordion-menu ul.submenu li a:hover{background-color:#F1F1F1; color:#000000;}
    .mainNav ul li a.activemenu{color:#FA0000;padding:3px 0 3px 0px;}
    .accordion-menu ul.submenu li a.activemenu{color:#FA0000;padding:3px 0 3px 0px;}
    .accordion-menu ul.submenu li a:hover.activemenu{#active-submenuheader{/*background:#010101;*/color:#F1F1F1;padding:3px 0 3px 5px;
    background-image:url(assets/template/images/nav-arrow-highlight.gif);background-repeat:no-repeat;}


    wfJs:
    <script type="text/javascript">
    ddaccordion.init({
    	headerclass: "submenuheader", //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" or "mouseover
    	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: ["", ""], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
    	togglehtml: ["suffix", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
    	animatespeed: "fast", //speed of animation: "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>
    


    Any help would be gratefully received.
      • 6408
      • 58 Posts
      OK - I didnt get this to work using ddaccordion, but there is a better JQuery accordion script which seems to do exactly what I need.

      1)

      I left the code outlined above almost exactly as it is, however I changed wfOuter to the following - basically putting an id of accordion on the <ul> element:

      <div class="accordion-menu">
        <ul id="accordion">
         [[+wf.wrapper]]
        </ul>
      </div>
      
      


      2)

      I downloaded the following from Jquery: http://jqueryui.com/download

      Jquery core, the Jquery UI pack (with the accordion script, and widgets). You will find the jquery core and jquery ui scripts in a gfolder marked ’js’. The widget and accordian scripts are in a folder marked ’development bundle’

      I then added the following lines into my templates, but these will need to point to wherever you store your javascript: (note I have edited the filanames of script files to shorten them down. These arent the original filenames, but should give you an idea of the scripts you need.)

      <script type="text/javascript" src="assets/template/js/jquery.js"></script>
      <script type="text/javascript" src="assets/template/js/jquery-ui.js"></script>
      <script type="text/javascript" src="assets/template/js/jquery.ui.widget.js"></script>
      <script type="text/javascript" src="assets/template/js/jquery.ui.accordion.js"></script>


      3)

      I then have a jquery function call in my <head> section that looks like this. Its important to make the header ’submenuheader’ (assuming you using the chunks from the wayfinder accordian code as outlined in my post above) as this ensures the widget knows what are sections with submenus and those that are standard links - :

      <script>
      	$(function() {
      	$( "#accordion" ).accordion({ header: '.submenuheader' });
      	});
      	</script>



      4)

      I then adjusted jquery.ui.accordion.js settings to the following - the settings below tell the widget you are using a navigation accordion (as opposed to expanding / collapsing content areas, for example). You might like to check these settings and make sure they are suitable for what you need:

      $.widget( "ui.accordion", {
      	options: {
      		active: 0,
      		animated: "slide",
      		autoHeight: false,
      		clearStyle: false,
      		collapsible: true,
      		event: "click",
      		fillSpace: false,
      		header: "> li > :first-child,> :not(li):even",
      		icons: {
      			header: "ui-icon-triangle-1-e",
      			headerSelected: "ui-icon-triangle-1-s"
      		},
      		navigation: true,
      		navigationFilter: function() {
      			return this.href.toLowerCase() === location.href.toLowerCase();
      		}
      	},
      
      


      5)

      Finally, I adjuested my snippet call to the following, removing the call to wfJs:
      [[!Wayfinder? &startId=`0` &outerTpl=`wfOuter` &parentRowTpl=`wfParentRow` &activeParentRowTpl=`wfActiveParentRow` &innerTpl=`wfInner` &rowTpl=`wfRow` &innerRowTpl=`wfInnerRow` &cssTpl=`wfStyle`  &hereTpl=`wfHere`]]


      Thats it! Obviously some of the chunks could be edited down as this jquery script seems a little leaner than ddaccordion, but because I wanted to keep my styles intact from using the previous script I kept it as it is. You should find yourself with a much more flexible accordion menu using the latest jquery.

      If you find this useful, but are stuck, post a note and I will try to expand on how I got it to work.
      Good luck!

      Dan.




        • 27834
        • 1 Posts
        Hi Dan,

        thank you for your help. It’s working. But what should I do to present content in the parent nodes?
        Now they are only used for the accordion.

        Thanks!!
          • 6408
          • 58 Posts
          Hi Sorry for the late reply - unfortunately you *cannot* have content in the parent nodes - in other words the parents are non-clickable. They act as containers with no content. You might find a way of doing what you want to do with an alternative javascript.
            • 6408
            • 58 Posts
            Just realised, if you changge the default behaviour from mouse ’click’ to ’mouseover’ in the jquery accordion widget script, the links become clickable.... but it doesnt work as well.