diff options
author | Sean O'Brien <diggity@diggmobile.(none)> | 2012-03-10 11:18:49 -0500 |
---|---|---|
committer | James Vasile <james@jamesvasile.com> | 2012-03-12 14:39:32 -0400 |
commit | 5685d3f387d60484b24769844488a866a08c6e6b (patch) | |
tree | c3d5a49b299f8713eb00f2f4d644e7c1c79b0736 /menu.py | |
parent | 2f5c98dd6f8ae91a3800a48a549325a4130acce9 (diff) |
fixes to boostrap, new icons, mobile view works
Diffstat (limited to 'menu.py')
-rw-r--r-- | menu.py | 21 |
1 files changed, 13 insertions, 8 deletions
@@ -5,11 +5,15 @@ import cfg class Menu(): """One menu item.""" - def __init__(self, label="", url="#", order=50): + def __init__(self, label="", icon="", url="#", order=50): """label is the text that is displayed on the menu. + icon is the icon to be displayed next to the label. + Choose from the Glyphicon set: + http://twitter.github.com/bootstrap/base-css.html#icons + url is the url location that will be activated when the menu - item is selected + item is selected. order is the numerical rank of this item within the menu. Lower order items appear closest to the top/left of the menu. @@ -20,14 +24,15 @@ class Menu(): """ self.label = label - self.order = order + self.icon = icon self.url = url + self.order = order self.items = [] def sort_items(self): """Sort the items in self.items by order.""" self.items = sorted(self.items, key=lambda x: x.order, reverse=False) - def add_item(self, label, url, order=50, basehref=True): + def add_item(self, label, icon, url, order=50, basehref=True): """This method creates a menu item with the parameters, adds that menu item to this menu, and returns the item. @@ -36,7 +41,7 @@ class Menu(): if basehref and url.startswith("/"): url = cfg.base_href + url - item = Menu(label=label, url=url, order=order) + item = Menu(label=label, icon=icon, url=url, order=order) self.items.append(item) self.sort_items() return item @@ -61,7 +66,7 @@ class Menu(): so = [] for item in self.items: - i = { 'label':item.label, 'url':item.url} + i = { 'label':item.label, 'icon':item.icon, 'url':item.url} if item.active_p(): i['active']=True if item.items and render_subs: @@ -74,7 +79,7 @@ class Menu(): if render_subs is True, we render submenus too""" - return ('<SCRIPT LANGUAGE="JavaScript">\n <!--\n var %s_items=' % name + return ('<script type="text/javascript">\n <!--\n var %s_items=' % name #+ json.dumps(self.serializable(render_subs=render_subs), separators=(',',':')) # compact + "\n"+ json.dumps(self.serializable(render_subs=render_subs), sort_keys=True, indent=4) # pretty print - + ';\n // -->\n </SCRIPT>') + + ';\n // -->\n </script>') |