[Jifty-commit] jifty branch, master, updated. fb69203dfba9a13704a7f13763be109b7063bc3c

Jifty commits jifty-commit at lists.jifty.org
Thu Dec 31 15:07:47 EST 2009


The branch, master has been updated
       via  fb69203dfba9a13704a7f13763be109b7063bc3c (commit)
      from  dcc395e59afebef5565d8452ca2fafb7dddd9f6c (commit)

Summary of changes:
 lib/Jifty/Web/Menu.pm |   69 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 68 insertions(+), 1 deletions(-)

- Log -----------------------------------------------------------------
commit fb69203dfba9a13704a7f13763be109b7063bc3c
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Thu Dec 31 15:06:42 2009 -0500

    Support rendering menus as straight up YUI menus
    
    We already support YUI's menu bars, but not just plain old menus.

diff --git a/lib/Jifty/Web/Menu.pm b/lib/Jifty/Web/Menu.pm
index 79c7725..d104f85 100644
--- a/lib/Jifty/Web/Menu.pm
+++ b/lib/Jifty/Web/Menu.pm
@@ -402,7 +402,74 @@ sub _render_as_classical_menu_item {
 
 }
 
-=head2 render_as_yui_menubar [PARAMHASH]
+=head2 render_as_yui_menu [PARAMHASH]
+
+Render menu with YUI menu.  It can support arbitrary levels of submenus.
+
+Valid options for the paramhash are as follows:
+
+=over
+
+=item id
+
+The HTML element ID to use for the menu
+
+=item show
+
+A boolean indicating whether to show the menu after rendering the HTML.
+Defaults to true.  If you don't set this to true, you should use the
+button option (see below) or show the menu with Javascript like:
+
+    YAHOO.widget.MenuManager.getMenu("menu-html-id").show();
+
+=item button
+
+The ID of an HTML element.  The element's onclick Javascript event is bound
+to a function which shows the menu.
+
+=item options
+
+A hashref of options passed directly to the Javascript constructor for
+the menu.  See L<http://developer.yahoo.com/yui/menu/#configreference> for
+a list of the options available.
+
+=back
+
+=cut
+
+sub render_as_yui_menu {
+    my $self = shift;
+    my %args = (
+        id      => Jifty->web->serial,
+        show    => 1,
+        options => {},
+        @_
+    );
+
+    my $showjs = $args{'show'} ? "menu.show();" : "";
+    my $json   = Jifty::JSON::objToJson( $args{'options'} );
+
+    # Bind to a button to show the menu
+    my $binding = $args{'button'}
+                    ? qq[YAHOO.util.Event.addListener("$args{button}", "click", menu.show, null, menu);]
+                    : '';
+
+    $self->_render_as_yui_menu_item( class => "yuimenu", id => $args{'id'} );
+    Jifty->web->out(<<"    END");
+        <script type="text/javascript">
+            YAHOO.util.Event.onContentReady("$args{id}", function() {
+                // set container?
+                var menu = new YAHOO.widget.Menu("$args{id}", $json);
+                menu.render();
+                $showjs
+                $binding
+            });
+        </script>
+    END
+    '';
+}
+
+=head2 render_as_yui_menubar
 
 Render menubar with YUI menu, suitable for an application's menu.
 It can support arbitary levels of submenu.

-----------------------------------------------------------------------


More information about the Jifty-commit mailing list