Skip to content

Commit

Permalink
An expandable menu element for nitrogen.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kelly McLaughlin committed May 5, 2009
1 parent 6347ae7 commit cd08e06
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions 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 cd08e06

Please sign in to comment.