This is the second feature I've added to ZWiki. Again it has no effect on existing ZWikis?, its just an option.

The header menu with contents, FrontPage, etc is a list of lists. This menu is is created in standard_wiki_header with this line:

If you add the horizontal_only parameter, you get horizontal menus:

One thing that was kind of weird about doing this, removed a couple useless parameters from "present_nesting" function: ida and indent - at least these were useless as far as I could tell. Also, moved all the html stuff out of "present_nesting" so it is much simpler than it used to be. This should make it much easier to create other display options for the header menu.

Here's the code changes for this, which looks like alot, but really isn't much because it includes a rewrite of a method (it was easier this way)... --JJ (who doesn't know the correct way to post code changes):

 85c85
 <     def context(self, REQUEST=None, with_siblings=0, enlarge_current=0, horizontal_only=0, anchor_title=""):
 ---
 >     def context(self, REQUEST=None, with_siblings=0, enlarge_current=0):
 115,116c115
 <                                     suppress_hyperlink=suppress_hyperlink,
 <                                     horizontal_only=horizontal_only)
 ---
 >                                     suppress_hyperlink=suppress_hyperlink)
 121,122c120
 <                                         suppress_hyperlink=suppress_hyperlink,
 <                                         horizontal_only=horizontal_only)
 ---
 >                                         suppress_hyperlink=suppress_hyperlink)
 124,130c122,123
 <         if horizontal_only:
 <             return '<small><a class=header href="%s/map#%s" title="%s">%s contents</a>' % \
 <                (self.page_url(), quote(self.id()), anchor_title, titletxt) + \
 <                hierarchy + '</small>'
 <         else:
 <             return '<small><ul><a class=header href="%s/map#%s" title="%s">%s contents</a>\n' % \
 <                (self.page_url(), quote(self.id()), anchor_title, titletxt) + \
 ---
 >         return '<small><ul><a href="%s/map#%s">%s contents</a>\n' % \
 >                (self.page_url(), quote(self.id()), titletxt) + \
 307,349d299
 < class NestingLink:
 <     def __init__(self, myid, enlarge_current, suppress_hyperlink, horizontal_only):
 <         self.myid = myid
 <         self.enlarge_current = enlarge_current
 <         self.suppress_hyperlink = suppress_hyperlink
 <         self.horizontal_only = horizontal_only
 <         self.result = []
 <         if horizontal_only:
 <             self.list_entry = '.. '
 <         else:
 <             self.list_entry = '<li>'
 < 
 <     def beginlist(self):
 <         if not self.horizontal_only:
 <             self.result.append("<ul>")
 < 
 <     def endlist(self):
 <         if not self.horizontal_only:
 <             self.result.append("</ul>")
 < 
 <     def showOmittedParents(self):
 <         self.result[-1] = self.result[-1] + " ..."
 < 
 <     def append(self, node, rel):
 <         if node == self.myid:
 <             # The entry is the current node - distinguish it.
 <             if self.enlarge_current:
 <                 nodenm = '<big><big><big><big><strong>%s</strong></big></big></big></big>' % node
 <                 if self.suppress_hyperlink:
 <                     self.result.append('%s%s' % (self.list_entry, nodenm))
 <                 else:
 <                     self.result.append('%s<a class=header href="%s/%s/backlinks" title="Set parent links for the current page">%s</a>'
 <                                     % (self.list_entry, rel, quote(node), nodenm))
 <             else:
 <                 nodenm = "<strong>%s</strong>" % node
 <                 self.appendLinkToList(node, rel, nodenm)
 <         else:
 <             self.appendLinkToList(node, rel, node)
 < 
 <     def appendLinkToList(self, node, rel, nodenm):
 <         self.result.append('%s<a class=header href="%s/%s" name="%s" title="Jump to this page">%s</a>'
 <                % (self.list_entry, rel, quote(node), quote(node), nodenm))
 < 
 351,356c301,302
 < #
 < # JJ - got rid of two useless parameters "did" (unused) and "indent" (inserted spaces 
 < #  ignored by browser), put display logic in NestingLink class
 < #
 < def present_nesting(myid, nesting, rel, _got=None, \
 <                     enlarge_current=0, suppress_hyperlink=0, horizontal_only=0): #SKWM 
 ---
 > def present_nesting(myid, nesting, rel, did=None, _got=None, indent="", \
 >                     enlarge_current=0, suppress_hyperlink=0): #SKWM 
 363a310
 >     if did is None: did = []
 365,366c312
 <         _got = NestingLink(myid, enlarge_current, suppress_hyperlink, horizontal_only)
 <         _got.beginlist()
 ---
 >         _got = ["<ul>"]
 374c320,336
 <             _got.append(n[0], rel)
 ---
 >             if n[0] == myid:
 >                 # The entry is the current node - distinguish it.
 >                 if enlarge_current:
 >                     nodenm = '<big><big><big><big><strong>%s</strong></big></big></big></big>' % n[0]
 >                     if suppress_hyperlink:
 >                         _got.append('%s <li>%s' % (indent, nodenm))
 >                     else:
 >                         _got.append('%s <li><a href="%s/%s/backlinks">%s</a>'
 >                                     % (indent, rel, quote(n[0]), nodenm))
 >                 else:
 >                     nodenm = "<strong>%s</strong>" % n[0]
 >                     _got.append('%s <li><a href="%s/%s" name="%s">%s</a>'
 >                                 % (indent, rel, quote(n[0]), quote(n[0]), nodenm))
 >             else:
 >                 nodenm = n[0]
 >                 _got.append('%s <li><a href="%s/%s" name="%s">%s</a>'
 >                             % (indent, rel, quote(n[0]), quote(n[0]), nodenm))
 376c338
 <                 _got.beginlist()
 ---
 >                 _got.append("<ul>")
 379c341,344
 <                         _got = present_nesting(myid, [i], rel, _got=_got)
 ---
 >                         _got = present_nesting(myid, [i], rel, did=did,
 >                                                _got=_got, indent=indent+'  ',
 >                                                enlarge_current=enlarge_current,
 >                                                suppress_hyperlink=suppress_hyperlink)
 381,382c346,360
 <                         _got.append(i, rel)
 <                 _got.endlist()
 ---
 >                         if i == myid:
 >                             # Distinguish that entry is for current node.
 >                             if enlarge_current:
 >                                 inm = '<big><big><big><big><strong>' + i + '</strong></big></big></big></big>'
 >                                 if suppress_hyperlink:
 >                                     _got.append('%s <li>%s' % (indent, inm))
 >                                 else:
 >                                     _got.append('%s <li><a href="%s/%s/backlinks">%s</a>' % (indent, rel, quote(i), inm))
 >                             else:
 >                                 inm = "<strong>" + i + "</strong>"
 >                                 _got.append('%s <li><a href="%s/%s" name="%s">%s</a>' % (indent, rel, quote(i), quote(i), inm))
 >                         else:
 >                             inm = i
 >                             _got.append('%s <li><a href="%s/%s" name="%s">%s</a>' % (indent, rel, quote(i), quote(i), inm))
 >                 _got.append("</ul>")
 385c363
 <                 _got.showOmittedParents()
 ---
 >                 _got[-1] = _got[-1] + " ..."
 387c365,378
 <             _got.append(n, rel)
 ---
 >             if n == myid:
 >                 # The entry is for the current node - distinguish.
 >                 if enlarge_current:
 >                     inm = '<big><big><big><big><strong>' + n + '</strong></big></big></big></big>'
 >                     if suppress_hyperlink:
 >                         _got.append('%s <li>%s' % (indent, inm))
 >                     else:
 >                         _got.append('%s <li><a href="%s/%s/backlinks">%s</a>' % (indent, rel, quote(n), inm))
 >                 else:
 >                     inm = "<strong>" + n + "</strong>"
 >                     _got.append('%s <li><a href="%s/%s" name="%s">%s</a>' % (indent, rel, quote(n), quote(n), inm))
 >             else:
 >                 inm = n
 >                 _got.append('%s <li><a href="%s/%s" name="%s">%s</a>' % (indent, rel, quote(n), quote(n), inm))
 392,393c383,384
 <         _got.endlist()
 <         return join(_got.result, "\n")
 ---
 >         _got.append("</ul>")
 >         return join(_got, "\n")

a ZwikiModification


FlorianKonnertz, 2002/10/31 07:44 GMT (via web):
This sounds interesting. - Could you post an example URL or a screenshot please?! - I find it difficult to imagine how it looks like.


SimonMichael, 2002/10/31 23:18 GMT (via web):
Sounds nice. I created HowToPostPatches?. NB the parenting code has long been in need of a major cleanup (but on the other hand smaller changes might be the way to tackle this). If you post screenshot(s), please show us how it works out with longer page names & deeper parenting.

FlorianKonnertz, 2003/01/19 20:33 GMT (via web):
Please describe how this looks like! Is it something like: ZWiki > ZwikiDevelopment > ZwikiModifications > HorizontalHeaderMenu ?