Hi,

[FYI, my problem is SOLVED -- But I still wonder about this...]

I have been using a menu with web2py since v1.8x (currently 1.98.2). I now 
have 3 different versions running on three different servers. 

PRODUCTION -- 1.98.2 -- menu is OK
TEST - 1.99.3 -- menu is screwy
DEV - 1.99.4 -- menu is screwy

Now the problem is that when I created a menu, it didn't load properly 
unless I had subitems in it -- I have dividing images that load between the 
top level menu items, and if the top level item doesn't contain children, 
then the dividing images wouldn't load.

Ok, so I managed to get past that by adding an "empty" menu row:

empty = (T(''), False, URL(), [])

Now, on web2py<=1.98.2 this is fine -- the menu class decides not to create 
a dropdown and all is well.

However, on 1.99.{3,4} the menu is "screwy": it creates an empty dropdown 
with a computed height of 4px, which contains an li and anchor, but no text 
nodes. Now, removing the "empty" and just using an empty list gives me the 
image issue (so maybe that's my fault and I should relook at that and 
choose different css selectors). 

So I guess I'm wondering if anyone else had a problem with Top-Level Menu 
items with NO children not getting the proper class they need to style 
their menus appropriately? Anyone have an inkling as to what I'm doing 
wrong from what I've described? I'm wondering if it has anything to do with 
the new "mobile" code for menus?


If not, then I guess this whole post is moot, and I'm doing something 
stupid somewhere, but if so, lemme know!

Thanks!



PS:
here's my solution that allows you to use "None" or an empty tuple "()" 
inside of the list arg:

In web2py/gluon/html.py, COPY (don't modify in place!!) the entire MENU 
class into your models file (or modules and import in models, but it really 
doesn't matter), and add these lines inside of the "serialize" function:

            if not item or len(item)<3:
              continue

right after the "for item in data" loop, so serialize would look like so:

 def serialize(self, data, level=0):
        if level == 0:
            ul = UL(**self.attributes)
        else:
            ul = UL(_class=self['ul_class'])
        for item in data:
            if not item or len(item) < 3:
              continue
            (name, active, link) = item[:3]
            if isinstance(link,DIV):
                li = LI(link)
            elif 'no_link_url' in self.attributes and self['no_link_url']==
link:
                li = LI(DIV(name))
            elif link:
                li = LI(A(name, _href=link, _title=name))
            else:
                li = LI(A(name, _title=name, _href='#',
                          _onclick='javascript:void(0):return false'))
            if len(item) > 3 and item[3]:
                li['_class'] = self['li_class']
                li.append(self.serialize(item[3], level+1))
            if active or ('active_url' in self.attributes and self[
'active_url']==link):
                if li['_class']:
                    li['_class'] = li['_class']+' '+self['li_active']
                else:
                    li['_class'] = self['li_active']
            ul.append(li)
        return ul


Then in your Menu do:


empty = None # or empty = () 
response.menu = [
  (T('Whatever'), False, URL(...wherever...), [empty]),
  ...
]




Reply via email to