[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm lonmenu.pm

raeburn raeburn at source.lon-capa.org
Thu May 24 18:56:30 EDT 2012


raeburn		Thu May 24 22:56:30 2012 EDT

  Modified files:              
    /loncom/interface	loncommon.pm lonmenu.pm 
  Log:
  - Sub-menu dropdown list from pure css.
    - Move code used to generate dropdown list of submenu items to
      subroutine -- &create_submenu() to facilitate re-use.
    - Added borders (left and right) to dropdown to improve readability.
    - Documentation for &create_submenu().
  
  
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1078 loncom/interface/loncommon.pm:1.1079
--- loncom/interface/loncommon.pm:1.1078	Thu May 24 14:20:53 2012
+++ loncom/interface/loncommon.pm	Thu May 24 22:56:30 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.1078 2012/05/24 14:20:53 raeburn Exp $
+# $Id: loncommon.pm,v 1.1079 2012/05/24 22:56:30 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -6487,6 +6487,8 @@
   font-size: 90%;
   vertical-align: top;
   float: none;
+  border-left: 1px solid black;
+  border-right: 1px solid black;
 }
 
 ol.LC_primary_menu li:hover li a, ol.LC_primary_menu li.hover li a {
Index: loncom/interface/lonmenu.pm
diff -u loncom/interface/lonmenu.pm:1.374 loncom/interface/lonmenu.pm:1.375
--- loncom/interface/lonmenu.pm:1.374	Tue May 22 16:44:06 2012
+++ loncom/interface/lonmenu.pm	Thu May 24 22:56:30 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines to control the menu
 #
-# $Id: lonmenu.pm,v 1.374 2012/05/22 16:44:06 bisitz Exp $
+# $Id: lonmenu.pm,v 1.375 2012/05/24 22:56:30 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -115,6 +115,18 @@
 
 Same as primary_menu() but operates on @secondary_menu.
 
+=item create_submenu()
+
+Creates XHTML for unordered list of sub-menu items which belong to a 
+particular top-level menu item. Uses hover pseudo class in css to display
+dropdown list when mouse hovers over top-level item. Support for IE6 
+(no hover psuedo class) via LC_hoverable class for <li> tag for top-
+level item, which employs jQuery to handle behavior on mouseover.
+
+Inputs: 4 - (a) link and (b) target for anchor href in top level item,
+            (c) title for text wrapped by anchor tag in top level item.
+            (d) reference to array of arrays of sub-menu items.
+
 =item innerregister()
 
 This gets called in order to register a URL in the body of the document
@@ -225,51 +237,32 @@
         
         my $title = $menuitem->[3];
         if (defined($primary_submenu{$title})) {
-            my ($link,$target,$numsub);
+            my ($link,$target);
             if ($menuitem->[0] ne '') {
                 $link = $menuitem->[0];
                 $target = '_top';
             } else {
                 $link = '#';
             }
+            my @primsub;
             if (ref($primary_submenu{$title}) eq 'ARRAY') {
-                $numsub = @{$primary_submenu{$title}};
-                if ($numsub) {
-                    $title =
-                        '<span class="LC_nobreak">'.&mt($title).
-                        '<span class="LC_fontsize_small">'.
-                        '▼</span></span>';
-                }
-            }
-            $menu .= '<li class="LC_hoverable">'.
-                     '<a href="'.$link.'" target="'.$target.'">'.$title.'</a>';
-            if ($numsub) {
-                $menu .= '<ul>';
-                foreach my $item (@{$primary_submenu{$menuitem->[3]}}) {
-                    if (ref($item) eq 'ARRAY') {
-                        if ($item->[2] eq 'wishlist') {
-                            next unless ((&Apache::lonnet::allowed('bre',"/res/$env{'user.domain'}/")) ||
-                                         (&Apache::lonnet::allowed('bro',"/res/$env{'user.domain'}/")));
-                        } elsif ($item->[2] eq 'reqcrs') {
-                            next unless(&check_for_rcrs());
-                        } elsif (($item->[2] eq 'portfolio') ||
-                                 ($item->[2] eq 'blog')) {
-                            if (!&Apache::lonnet::usertools_access(
-                                    $env{'user.name'},
-                                    $env{'user.domain'},
-                                    $item->[2],undef,'tools')) {
-                                next;
-                            }
-                        }
-                        $menu .= '<li style="margin:0;padding:0">'.
-                                 '<a href="'.$item->[0].
-                                 '" style="padding:0 0 0 10px">'.
-                                 &mt($item->[1]).'</a></li>';
-                    }
+                foreach my $item (@{$primary_submenu{$title}}) {
+                    next if (($item->[2] eq 'wishlist') &&
+                             ((!&Apache::lonnet::allowed('bre',"/res/$env{'user.domain'}/")) &&
+                              (!&Apache::lonnet::allowed('bro',"/res/$env{'user.domain'}/"))));
+                    next if (($item->[2] eq 'reqcrs') && (!&check_for_rcrs()));
+                    next if ((($item->[2] eq 'portfolio') ||
+                             ($item->[2] eq 'blog')) &&
+                             (!&Apache::lonnet::usertools_access('','',$item->[2],
+                                                           undef,'tools')));
+                    push(@primsub,$item);
+                }
+                if (@primsub > 0) {
+                    $menu .= &create_submenu($link,$target,$title,\@primsub);
+                } elsif ($link) {
+                    $menu .= '<li><a href="'.$link.'" target="'.$target.'">'.$title.'</a></li>';
                 }
-                $menu .= '</ul>';
             }
-            $menu .= '</li>';
         } elsif ($$menuitem[3] eq 'Help') { # special treatment for helplink
             if ($public) {
                 my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
@@ -405,6 +398,33 @@
     return "<ul id=\"LC_secondary_menu\">$menu</ul>";
 }
 
+sub create_submenu {
+    my ($link,$target,$title,$submenu) = @_;
+    return unless (ref($submenu) eq 'ARRAY');
+    my $menu = '<li class="LC_hoverable">'.
+               '<a href="'.$link.'" target="'.$target.'">'.
+               '<span class="LC_nobreak">'.$title.
+               '<span class="LC_fontsize_small" style="font-weight:normal;">'.
+               ' ▼</span></span></a>'.
+               '<ul>';
+    my $count = 0;
+    my $numsub = scalar(@{$submenu});
+    foreach my $item (@{$submenu}) {
+        $count ++;
+        if (ref($item) eq 'ARRAY') {
+            my $borderbot;
+            if ($count == $numsub) {
+                $borderbot = 'border-bottom:1px solid black;';
+            }
+            $menu .= '<li style="margin:0;padding:0;'.
+                     $borderbot.'"><a href="'.$item->[0].'">'.
+                     $item->[1].'</a></li>';
+        }
+    }
+    $menu .= '</ul></li>';
+    return $menu;
+}
+
 sub innerregister {
     my ($forcereg,$bread_crumbs) = @_;
     my $const_space = ($env{'request.state'} eq 'construct');




More information about the LON-CAPA-cvs mailing list