[Jifty-commit] r1125 - in jifty/trunk: lib/Jifty/Web

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Mon May 29 21:46:35 EDT 2006


Author: jesse
Date: Mon May 29 21:46:34 2006
New Revision: 1125

Modified:
   jifty/trunk/   (props changed)
   jifty/trunk/lib/Jifty/Web/Menu.pm

Log:
 r9893 at pinglin:  jesse | 2006-05-29 21:06:50 -0400
 * Initial support for page nav as dropdowns


Modified: jifty/trunk/lib/Jifty/Web/Menu.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Web/Menu.pm	(original)
+++ jifty/trunk/lib/Jifty/Web/Menu.pm	Mon May 29 21:46:34 2006
@@ -163,6 +163,26 @@
 }
 
 
+=head2 render_as_menu
+
+Render this menu with HTML markup as multiple dropdowns, suitable for
+an application's menu
+
+=cut
+
+sub render_as_menu {
+    my $self = shift;
+    my @kids = $self->children;
+    Jifty->web->out(qq{<ul class="menu">});
+
+    for (@kids) {
+	$_->render_as_hierarchical_menu_item();
+    }
+    Jifty->web->out(qq{</ul>});
+    '';
+}
+
+
 =head2 render_as_context_menu
 
 Render this menu with html markup as an inline dropdown menu.
@@ -170,32 +190,55 @@
 
 =cut
 
+
 sub render_as_context_menu {
+	my $self = shift;
+    	Jifty->web->out( qq{<ul class="context_menu">});
+	$self->render_as_hierarchical_menu_item();
+	Jifty->web->out(qq{</ul>});
+	'';
+}
+
+=head2 render_as_hierarchical_menu_item
+
+Render an <li> for this item. suitable for use in a regular or contextual
+menu. Currently renders one level of submenu, if it exists.
+
+=cut
+
+sub render_as_hierarchical_menu_item {
     my $self = shift;
-    my @kids = $self->children;
-    my $id = Jifty->web->serial;
-    Jifty->web->out(
-        qq{<ul class="context_menu">} .qq{<li class="closed toplevel">}.  qq{<span class="title">});
-     $self->as_link();
-     Jifty->web->out( qq{</span>}
-            . (
-            @kids
-            ? qq{<span class="expand"><a href="#" onClick="Jifty.ContextMenu.hideshow('}.$id.qq{'); return false;">+</a></span>}
-            : ''
-            )
-            . qq{<ul id="}.$id.  qq{">}
+    my %args = (
+        class => '',
+        @_
     );
-    for (@kids) {
-        Jifty->web->out("<li>");
-
-        # We should be able to get this as a string.
-        # Either stringify the link object or output the label
-        # This is really icky. XXX TODO 
-        Jifty->web->out($_->as_link);
-        Jifty->web->out("</li>");
+    my @kids = $self->children;
+    my $id   = Jifty->web->serial;
+    Jifty->web->out( qq{<li class="toplevel }
+            . ( $self->active ? 'open active' : 'closed' ) . qq{">}
+            . qq{<span class="title">} );
+    Jifty->web->out( $self->as_link() );
+    Jifty->web->out(qq{</span>});
+    if (@kids) {
+        Jifty->web->out(
+            qq{<span class="expand"><a href="#" onClick="Jifty.ContextMenu.hideshow('}
+                . $id
+                . qq{'); return false;">+</a></span>}
+                . qq{<ul id="}
+                . $id
+                . qq{">} );
+        for (@kids) {
+            Jifty->web->out(qq{<li class="submenu }.($_->active ? 'active' : '' ).qq{">});
+
+            # We should be able to get this as a string.
+            # Either stringify the link object or output the label
+            # This is really icky. XXX TODO
+            Jifty->web->out( $_->as_link );
+            Jifty->web->out("</li>");
+        }
+        Jifty->web->out(qq{</ul>});
     }
-
-    Jifty->web->out(qq{</ul></li></ul>});
+    Jifty->web->out(qq{</li>});
     '';
 
 }
@@ -213,8 +256,7 @@
     if ( $self->link ) {
         return $self->link;
     } elsif ( $self->url ) {
-        return Jifty->web->link( label => _( $self->label ),
-            url => $self->url );
+        return Jifty->web->link( label => _( $self->label ), url => $self->url );
 
     } else {
         return _( $self->label );


More information about the Jifty-commit mailing list