Permalink
Browse files

An expandable menu element for nitrogen.

Signed-off-by: Andreas Stenius <git@astekk.se>
  • Loading branch information...
1 parent 6347ae7 commit e8f209640353b26489cfa4fb9f25d248873e2675 Kelly McLaughlin committed with kaos May 5, 2009
Showing with 27 additions and 0 deletions.
  1. +27 −0 element_menu.erl
View
27 element_menu.erl
@@ -0,0 +1,27 @@
+-module (element_menu).
+-compile(export_all).
+
+-include_lib("lib/nitrogen/include/wf.inc").
+-record(menu, {?ELEMENT_BASE(element_menu), text="", body=[]}).
+
+% desc: Provides a collapsable menu. The menu options are specified
+% as listitem elements in the body.
+
+reflect() -> record_info(fields, menu).
+
+render(ControlID, Record) ->
+ Script = wf:f("$('#~s ul').hide();~n$('#~s li a').click(~nfunction() {~n$(this).next().slideToggle('normal');~n}~n);", [ControlID, ControlID]),
+ wf:wire(Script),
+ Title = wf:render(Record#menu.text),
+ Content = wf:render(Record#menu.body),
+ wf_tags:emit_tag(ul,
+ wf_tags:emit_tag(li,
+ Title++wf_tags:emit_tag(ul, Content, []),
+ []),
+ [
+ {id, ControlID},
+ {class, Record#menu.class},
+ {style, Record#menu.style}
+ ]
+ ).
+

0 comments on commit e8f2096

Please sign in to comment.