Topic: add javascript to top level links in wayfinder  (Read 1512 times)

Pages: [1]   Go Down

#1: 20-Feb-2007, 09:51 AM

jam
Posts: 7

Hi,

I'm trying to figure out how to go about adding javascript to top level links with children in wayfinder. In other words, some of the top level links with no children will just be regular links, but the ones with children will toggle the children below when clicked. In addition, I need to add a div surrounding the second level links. (This will be a two-level menu). This is what I'd like the end output code to be:

<li><a href="javascript:toggleDisplayById('expand')">Top Level Link</a>
            <div id="expand">
              <ul>
                <li><a href="tobeinserted">Second Level Link</a></li>
                <li><a href="tobeinserted">Second Level Link</a></li>
              </ul>
            </div>
          </li>

Can anyone point me in the right direction? I'm thinking I need to use the [+wf.link+] chunk? Any help is very much appreciated.

Thanks in advance!

#2: 20-Feb-2007, 10:01 AM

Moderator

kylej
Posts: 769

WWW
ok, for adding the div around the second level you will need to create a chunk for the template innerTpl like the following:

Code:
<div id="expand">
<ul[+wf.classes+]>
[+wf.wrapper+]
</ul>
</div>

for the javascript links you need to create a chunk for the template parentRowTpl like the following:

Code:
<li[+wf.classes+]>
<a href="javascript:toggleDisplayById('expand')" title="[+wf.title+]">[+wf.linktext+]»</a>
[+wf.wrapper+]
</li>

That should do it.  Now the only problem you will have with this is if there is more than one submenu, it will have the same id as the first and cause problems.  Also if a user has js disabled, the links will not function at all. 

#3: 20-Feb-2007, 11:35 AM

jam
Posts: 7

Thanks so much! I've got it working, but you were right, I do have more than one submenu and when you click any of the folders, they are all toggling the top submenu because they have the same id as the first.  Undecided  Any way to solve this? Should I use &rowIdPrefix? Instead of 'expand' below, what code would I place to pull in the right unique id?

javascript:toggleDisplayById('expand')

« Last Edit: 20-Feb-2007, 05:53 PM by jam »

#4: 20-Feb-2007, 05:14 PM

Coding Team

doze
Posts: 4,187

....Boom!

Could this work...

Have the default innerTpl and for parentRowTpl use:

Code:
<li[+wf.classes+]>
<a href="javascript:toggleDisplayById('expand[+wf.docid+]')" title="[+wf.title+]">[+wf.linktext+]»</a>
<div id="expand[+wf.docid+]">[+wf.wrapper+]</div>
</li>
New MODx wiki! Please help up with documentation efforts! || Old Wiki

"He can have a lollipop any time he wants to. That's what it means to be a programmer."

#5: 20-Feb-2007, 05:45 PM

Moderator

kylej
Posts: 769

WWW
doze, I think you nailed it.  Looks like that should work great.

#6: 21-Feb-2007, 09:31 AM

jam
Posts: 7

Thank you kylej and doze! I think I am very close, the menu shows only the top level, but the toggle doesn't function:

I tried moving the <div id="expand"> outside of the <div id="expand15"> but it didn't like that either. Any ideas? Thanks so much for your help!

<ul><li class="21">
   <a href="javascript:toggleDisplayById('expand15')" title="Search Test">Search Test»</a>
   <div id="expand15">
<div id="expand"><ul>
      <li class="22"><a href="/site/mainlevel/2ndinner.html" title="Test -- 2nd inner level page" >Test -- 2nd inner level page</a></li>

   </ul>
</div>
« Last Edit: 26-Feb-2007, 03:24 PM by jam »

#7: 21-Feb-2007, 09:49 AM

Moderator

kylej
Posts: 769

WWW
don't use the innerTpl anymore, that is no longer needed with the way doze has you templating it.  try removing that and see if it works
Pages: [1]   Go Up
0 Members and 1 Guest are viewing this topic.