Topic: New version of Wayfinder  (Read 4833 times)

Pages: [1]   Go Down

#1: 6-Jan-2009, 05:37 PM


dflock
Posts: 77

WWW
Good news everyone! During my development travails, I've created an updated version of Wayfinder that fixes two issues and adds two handy new featuresCheesy

Fixes

I've incorporated this fix which makes the hereClass work properly with weblinks in the menu and I've fixed the SQL query to work around the MySQL 5.0.51 sorting bug.

New Features

lastRowTpl

I've also added a new parameter called lastRowTpl which allows you specify a chunk to be used for the last menu item output. It works the same way as all the other wayfinder tpl's and defaults to using rowTpl is it isn't specified.

It's very useful for little menu's that currently look like this if you do them with Wayfinder:

item1 | item2 | item3 | lastitem |

and should look like this:

item1 | item2 | item3 | lastitem

Odd & Even classes

Finally, I've added support for even & odd classes on rows. These work like all the other wayfinder classes - you specify a class name in the parameter and this will be added to the wf.classes placeholder. These ones are only output on the appropriate rows, though - and you don't have to specify both if you don't want to - it'll still work with just one.

These are really useful for menu's which are supposed to be stripey, with every other item a different colour.

To implement this, I've modified both Wayfinder files. You can download the new versions from here (.zip) or here (.tar.gz). I've included the patches here, as they're shorter and let you see what's changed.
Here's the patch for the snippet file, wayfinder.snippet.php.patch:

Code:
--- Downloads/web_dev/MODx/Add-ons/wayfinder/wayfinder.snippet.php
+++ www/dev/modx/wayfinder.snippet.php
@@ -3,11 +3,13 @@
 ::::::::::::::::::::::::::::::::::::::::
  Snippet name: Wayfinder
  Short Desc: builds site navigation
- Version: 2.0
+ Version: 2.0.1
  Authors:
  Kyle Jaebker (muddydogpaws.com)
  Ryan Thrash (vertexworks.com)
  Date: February 27, 2006
+ 06 January 2009 - Modified by dunc@codeistry.com : added lastRowTpl and weblinks here patch.
+ 15 July 2008 - Modified by dunc@codeistry.com - added odd & even classes
 ::::::::::::::::::::::::::::::::::::::::
 Description:
     Totally refactored from original DropMenu nav builder to make it easier to
@@ -72,12 +74,15 @@
  'level' => isset($levelClass) ? $levelClass: '',
  'self' => isset($selfClass) ? $selfClass : '',
  'weblink' => isset($webLinkClass) ? $webLinkClass : '',
+ 'odd' => isset($oddClass) ? $oddClass : '',
+ 'even' => isset($evenClass) ? $evenClass : '',
 );
 
 //get user templates
 $wf->_templates = array(
  'outerTpl' => isset($outerTpl) ? $outerTpl : '',
  'rowTpl' => isset($rowTpl) ? $rowTpl : '',
+ 'lastRowTpl' => isset($lastRowTpl) ? $lastRowTpl : '',
  'parentRowTpl' => isset($parentRowTpl) ? $parentRowTpl : '',
  'parentRowHereTpl' => isset($parentRowHereTpl) ? $parentRowHereTpl : '',
  'hereTpl' => isset($hereTpl) ? $hereTpl : '',

and here's the include file, wayfinder.inc.php.patch:

Code:
--- Downloads/web_dev/MODx/Add-ons/wayfinder/wayfinder.inc.php
+++ www/dev/modx/wayfinder.inc.php
@@ -3,11 +3,14 @@
 ::::::::::::::::::::::::::::::::::::::::
  Snippet name: Wayfinder
  Short Desc: builds site navigation
- Version: 2.0
+ Version: 2.0.1
  Authors:
  Kyle Jaebker (muddydogpaws.com)
  Ryan Thrash (vertexworks.com)
- Date: March 03, 2007
+ Date: February 27, 2006
+
+ 06 January 2009 - Modified by dunc@codeistry.com : added lastRowTpl and weblinks here patch.
+ 15 July 2008 - Modified by dunc@codeistry.com - added odd & even classes
 ::::::::::::::::::::::::::::::::::::::::
 */
 
@@ -88,6 +91,7 @@
  foreach ($menuDocs as $docId => $docInfo) {
  $docInfo['level'] = $level;
  $docInfo['first'] = $firstItem;
+ $docInfo['counter'] = $counter;
  $firstItem = 0;
  //Determine if last item in group
  if ($counter == ($numSubItems) && $numSubItems > 1) {
@@ -163,13 +167,17 @@
         } elseif ($resource['level'] > 1 && $this->_templates['innerRowTpl']) {
             $usedTemplate = 'innerRowTpl';
         } else {
-            $usedTemplate = 'rowTpl';
+        if ($resource['last'] == '1' && $this->_templates['lastRowTpl']) {
+        $usedTemplate = 'lastRowTpl';
+        } else {
+            $usedTemplate = 'rowTpl';
+        }
         }
         //Get the template
         $useChunk = $this->_templates[$usedTemplate];
  //Setup the new wrapper name and get the class names
         $useSub = $resource['hasChildren'] ? "[+wf.wrapper.{$resource['id']}+]" : "";
-        $classNames = $this->setItemClass('rowcls',$resource['id'],$resource['first'],$resource['last'],$resource['level'],$resource['isfolder'],$resource['type']);
+        $classNames = $this->setItemClass('rowcls',$resource['id'],$resource['first'],$resource['last'],$resource['level'],$resource['isfolder'],$resource['type'],$resource['counter']);
         if ($classNames) $useClass = ' class="' . $classNames . '"';
         //Setup the row id if a prefix is specified
         if ($this->_config['rowIdPrefix']) {
@@ -205,7 +213,7 @@
     }
 
  //determine style class for current item being processed
-    function setItemClass($classType, $docId = 0, $first = 0, $last = 0, $level = 0, $isFolder = 0, $type = 'document') {
+    function setItemClass($classType, $docId = 0, $first = 0, $last = 0, $level = 0, $isFolder = 0, $type = 'document', $counter =  '') {
         global $modx;
         $returnClass = '';
         $hasClass = 0;
@@ -245,7 +253,7 @@
                 $hasClass = 1;
             }
             //Set here class if specified
-            if (!empty($this->_css['here']) && $this->isHere($docId)) {
+            if (!empty($this->_css['here']) && $this->isHere($docId, $type)) {
                 $returnClass .= $hasClass ? ' ' . $this->_css['here'] : $this->_css['here'];
                 $hasClass = 1;
             }
@@ -259,15 +267,36 @@
                 $returnClass .= $hasClass ? ' ' . $this->_css['weblink'] : $this->_css['weblink'];
                 $hasClass = 1;
             }
+ //Set class for even items
+ if (!empty($this->_css['even'])) {
+ if (($counter) && !($counter % 2)) {
+ $returnClass .= $hasClass ? ' ' . $this->_css['even'] : $this->_css['even'];
+ $hasClass = 1;
+ }
+ }
+ //Set class for odd items
+ if (!empty($this->_css['odd'])) {
+ if (($counter) && ($counter % 2)) {
+ $returnClass .= $hasClass ? ' ' . $this->_css['odd'] : $this->_css['odd'];
+ $hasClass = 1;
+ }
+ }
         }
 
         return $returnClass;
     }
 
  //determine "you are here"
-    function isHere($did) {
-        return in_array($did,$this->parentTree);
-    }
+ function isHere($did, $type='document') {
+ // begin weblink 'here' patch
+ if ($type == 'reference') {
+ global $modx;
+ $doc = $modx->getDocumentObject('id', $did);
+ $did = $doc['content'];
+ }
+ // end weblink 'here' patch
+ return in_array($did,$this->parentTree);
+ }
 
  //Add the specified css & javascript chunks to the page
     function regJsCss() {
@@ -348,7 +377,7 @@
          if($docgrp = $modx->getUserDocGroups()) $docgrp = implode(",",$docgrp);
          // build query
          $access = ($modx->isFrontend() ? "sc.privateweb=0" : "1='{$_SESSION['mgrRole']}' OR sc.privatemgr=0").(!$docgrp ? "" : " OR dg.document_group IN ({$docgrp})");
- $sql = "SELECT DISTINCT {$fields} FROM {$tblsc} sc LEFT JOIN {$tbldg} dg ON dg.document = sc.id WHERE sc.published=1 AND sc.deleted=0 AND ({$access}){$menuWhere} AND sc.id IN (".implode(',',$ids).") GROUP BY sc.id ORDER BY {$sort} {$this->_config['sortOrder']} {$sqlLimit};";
+ $sql = "SELECT DISTINCT {$fields} FROM {$tblsc} sc LEFT JOIN {$tbldg} dg ON dg.document = sc.id WHERE sc.published=1 AND sc.deleted=0 AND ({$access}){$menuWhere} AND sc.id IN (".implode(',',$ids).") ORDER BY {$sort} {$this->_config['sortOrder']} {$sqlLimit};";
  //run the query
  $result = $modx->dbQuery($sql);
          $resourceArray = array();
@@ -491,7 +520,7 @@
             if (empty($v) || !$templateCheck) {
                 if ($n === 'outerTpl') {
                     $this->_templates[$n] = '<ul[+wf.classes+]>[+wf.wrapper+]</ul>';
-                } elseif ($n === 'rowTpl') {
+                } elseif ($n === 'rowTpl' || $n === 'lastRowTpl') {
                     $this->_templates[$n] = '<li[+wf.id+][+wf.classes+]><a href="[+wf.link+]" title="[+wf.title+]" [+wf.attributes+]>[+wf.linktext+]</a>[+wf.wrapper+]</li>';
  } elseif ($n === 'startItemTpl') {
  $this->_templates[$n] = '<h2[+wf.id+][+wf.classes+]>[+wf.linktext+]</h2>[+wf.wrapper+]';

I'm using these on live sites, because I'm a crazy fool, but if we can get some more testing from everyone, maybe this can be added to the repository as a new version and maybe then into the main MODx distribution, so that everyone can share the love.

What do you think?

#2: 6-Jan-2009, 06:11 PM

Testers

dev_cw
Posts: 4,179

WWW
Looks like a good idea. I will test it sometime soon.

While you are at it I always thought that a way to assign an ID to the outerTpl would be cool. It seems that I am always needing to create an outerTpl simply to include an ID.

Something like &outerId=`navigation` would output <ul id="navigation> so you would not need a custom tpl.
I think you would also need to have a [+wf.outerId+] placeholder to use in the outerTpl.

Is there a way to have PHx in Wayfinder like it is in Ditto?
Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

Something is happening here, but you don't know what it is.
Do you, Mr. Jones?  -  [bob dylan]

#3: 6-Jan-2009, 06:20 PM


dflock
Posts: 77

WWW
No idea about PHx - I might see how ditto does this.

I can easily add the outerID thing at some point, maybe this weekend.

#4: 7-Jan-2009, 04:15 PM


bunk58
Posts: 1,751

David Bunker

WWW
Thanks Duncan  Smiley
Works a treat in overcoming the MySQL 5.0.51 sorting bug.

#5: 7-Jan-2009, 04:49 PM

Foundation

rthrash
Posts: 11,282

WWW
Good work Duncan. It'd be great to log these into JIRA so they can make it into the main distribution as well. Smiley

http://svn.modxcms.com/jira/secure/IssueNavigator.jspa?reset=true&mode=hide&pid=10033
MODx is a content managmeent framework that allows web professionals to turn over sites to end-users for daily maintenance without worrying. Please help us help you when asking for assistance and read the wiki. Searching the forums from the top level helps, too.
Ryan Thrash
MODx Co-Founder
Principal @ Collabpad
work productively.
work intelligently.
work together.

#6: 7-Jan-2009, 05:06 PM


ChuckTrukk
Posts: 849

WWW
cw,

I always use an empty outerTpl and just manually wrap my wayfinder calls with <ul id="whatever">. Makes it easier for me.
Chuck the Trukk
ProWebscape.com :: Nashville-WebDesign.com
- - - - - - - -
What are TV's? Here's some info below.
http://modxcms.com/forums/index.php/topic,21081.msg159009.html#msg1590091
http://modxcms.com/forums/index.php/topic,14957.msg97008.html#msg97008

#7: 7-Jan-2009, 05:11 PM

Testers

dev_cw
Posts: 4,179

WWW
Quote
No idea about PHx - I might see how ditto does this.
Need to weigh overhead vs function since menus can be everywhere. But if possible it would rock.

Quote
I always use an empty outerTpl and just manually wrap my wayfinder calls with <ul id="whatever">. Makes it easier for me.
But isn't a blank tpl a custom tpl? Or do you simply do &outerTpl=``? To overcome this I sometimes use a snippet to generate the ID based on parent or ultimate parent ID.

BTW - this works great dflock, thanks for this update.
« Last Edit: 7-Jan-2009, 05:13 PM by dev_cw »
Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

Something is happening here, but you don't know what it is.
Do you, Mr. Jones?  -  [bob dylan]

#8: 7-Jan-2009, 05:17 PM


dflock
Posts: 77

WWW
I'll have a go at getting these into Jira tomorrow - I haven't used it before, so I'll do my best.

I'll have a look at the OuterID thing too - it ought to be simple to implement and won't really complicate Wayfinder any, so why not?

You could then do stuff like:

[[Wayfinder? outerId=`[!SnippetCall? param=`id`!]` ...]]

or whatever.

#9: 8-Jan-2009, 08:25 AM

cipa
Posts: 874

here simple feature that I needed to code myself

'categoryTplId' => isset($categoryTplId) ? $categoryTplId : FALSE,

+

$resource['template']=="0" || $resource['template']==$this->_config['categoryTplId']

It adds a little more flexibility when a container has different template then blank and &categoryFoldersTpl is used

I guess 1 in 50 projects will need this Smiley
current goal: 66 posts on modxrules.com
plugin: Template Rules (updated version of automaticTpl)
snippet: ParentParent
manager hack: Custom Manager Tree
plugin [in progress]: templateManager

#10: 8-Jan-2009, 09:55 AM

Foundation

OpenGeek
MODx Co-Founder
Posts: 6,713

damn accurate caricatures...

WWW
I've fixed the SQL query to work around the MySQL 5.0.51 sorting bug.
Does this "workaround" for the MySQL bug work properly when a document is in multiple document groups since you removed the group by?
Jason Coward
MODx Co-Founder
xPDO Founder
CTO @ Collabpad
work productively.
work intelligently.
work together.
Light is just a vibration of a note too. Everything is. You've got to keep that in mind.
  Frank Zappa

#11: 8-Jan-2009, 11:51 AM


dflock
Posts: 77

WWW
Honestly, I really have no idea; I'll look into it.

It would be really helpful if someone more knowledgeable than me - i.e. practically anyone - could do some testing and let me know how they get on.

Thanks for the feedback!

#12: 8-Jan-2009, 12:35 PM


ChuckTrukk
Posts: 849

WWW
cw,

I create a chunk
called - {{Nav-Empty-Wrapper}}
the text is - [+wf.wrapper+]

then my wayfinder call might be

Code:
<ul id="main-menu">
[[Wayfinder? &startId=`1` &outerTpl=`Nav-Empty-Wrapper`]]
</ul>

then for the footer it may be
Code:
<ul id="footer-menu">
[[Wayfinder? &startId=`1` &outerTpl=`Nav-Empty-Wrapper`]]
</ul>
Chuck the Trukk
ProWebscape.com :: Nashville-WebDesign.com
- - - - - - - -
What are TV's? Here's some info below.
http://modxcms.com/forums/index.php/topic,21081.msg159009.html#msg1590091
http://modxcms.com/forums/index.php/topic,14957.msg97008.html#msg97008

#13: 7-May-2009, 02:32 AM

bvandorp
Posts: 9

can anyone help me with the odd & even function? i really dont get the implementation explained above.

#14: 7-May-2009, 03:28 AM

kongondo
Posts: 1,390

can anyone help me with the odd & even function? i really dont get the implementation explained above.

Hi,

First, you probably want to download the official beta, Wayfinder 2.5, since the above and other changes have now been included in it. You can find it here: http://modxcms.com/forums/index.php/topic,33904.0.html

As for your question, you implement the odd and even classes just like any other WF classes. The idea as explained above is to assign classes to every other row. Say, for instance, your menu items are as follows, the first item, "Home", is odd numbered (1) since, ah, it is the first item. "About" is even numbered since it is the second item, etc, etc

Home - (odd)
About - (even)
Store - (odd)
Location - (even)
Contact - (odd)

As an example, to assign these classes, you would add them to your WF call as follows by assigning specific names to them that you can later target using CSS

Code:
[[Wayfinder? &startId=`0` &outerTpl=`menuContainer` &oddClass=`name_of_the_class` &evenClass=`name_of_the_class` etc etc....]]

cheers/k

#15: 7-May-2009, 05:03 AM

bvandorp
Posts: 9

Quote
Hi,

First, you probably want to download the official beta, Wayfinder 2.5, since the above and other changes have now been included in it. You can find it here: http://modxcms.com/forums/index.php/topic,33904.0.html

As for your question, you implement the odd and even classes just like any other WF classes. The idea as explained above is to assign classes to every other row. Say, for instance, your menu items are as follows, the first item, "Home", is odd numbered (1) since, ah, it is the first item. "About" is even numbered since it is the second item, etc, etc

Home - (odd)
About - (even)
Store - (odd)
Location - (even)
Contact - (odd)

As an example, to assign these classes, you would add them to your WF call as follows by assigning specific names to them that you can later target using CSS

Code:
[[Wayfinder? &startId=`0` &outerTpl=`menuContainer` &oddClass=`name_of_the_class` &evenClass=`name_of_the_class` etc etc....]]

cheers/k


thank you very much!

got it working smoothly now.
Pages: [1]   Go Up
0 Members and 1 Guest are viewing this topic.