[LON-CAPA-cvs] cvs: loncom(version_2_11_X) /interface lonmenu.pm

raeburn raeburn at source.lon-capa.org
Thu May 24 19:36:17 EDT 2012


raeburn		Thu May 24 23:36:17 2012 EDT

  Modified files:              (Branch: version_2_11_X)
    /loncom/interface	lonmenu.pm 
  Log:
  - For 2.11
    - Backport 1.375.
    - Use &create_submenu() to generate XHTML for pure css dropdown list
      for secondary menu items.
  
  
-------------- next part --------------
Index: loncom/interface/lonmenu.pm
diff -u loncom/interface/lonmenu.pm:1.369.2.5 loncom/interface/lonmenu.pm:1.369.2.6
--- loncom/interface/lonmenu.pm:1.369.2.5	Wed May 23 00:29:22 2012
+++ loncom/interface/lonmenu.pm	Thu May 24 23:36:17 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines to control the menu
 #
-# $Id: lonmenu.pm,v 1.369.2.5 2012/05/23 00:29:22 raeburn Exp $
+# $Id: lonmenu.pm,v 1.369.2.6 2012/05/24 23:36:17 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
@@ -137,6 +149,9 @@
 
 =item utilityfunctions()
 
+Output from this routine is a number of javascript functions called by
+items in the inline menu, and in some cases items in the Main Menu page. 
+
 =item serverform()
 
 =item constspaceform()
@@ -221,51 +236,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">'.$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">'.
-                                 $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'};
@@ -371,17 +367,15 @@
 
         my $title = $menuitem->[3];
         if (defined($secondary_submenu{$title})) {
-            my ($link,$target,$numsub);
+            my ($link,$target);
             if ($menuitem->[0] ne '') {
                 $link = $menuitem->[0];
                 $target = '_top';
             } else {
                 $link = '#';
             }
-
             my @scndsub;   
             if (ref($secondary_submenu{$title}) eq 'ARRAY') {
-                $numsub = 0;
                 foreach my $item (@{$secondary_submenu{$title}}) {
                     if (ref($item) eq 'ARRAY') {
                         next if ($item->[2] eq 'vgr' && !$canvgr);
@@ -390,43 +384,14 @@
                         next if ($item->[2] eq 'mgr' && !$canmgr);
                         next if ($item->[2] eq 'vcg' && !$canviewgrps);
                         push(@scndsub,$item); 
-                        $numsub ++;
                     }
                 }
-                if ($numsub) {
-                    $title =
-                        '<span class="LC_nobreak">'.$title.
-                        '<span class="LC_fontsize_small" style="font-weight:normal">'.
-                        ' ▼</span></span>';
+                if (@scndsub > 0) {
+                    $menu .= &create_submenu($link,$target,$title,\@scndsub);
+                } elsif ($link) {
+                    $menu .= '<li><a href="'.$link.'" target="'.$target.'">'.$title.'</a></li>';
                 }
             }
-            $menu .= '<li class="LC_hoverable">'.
-                     '<a href="'.$link.'" target="'.$target.'">'.$title.'</a>';
-            if ($numsub) {
-                $menu .= '<ul>';
-                my $count = 0;
-                foreach my $item (@scndsub) {
-                    $count ++;
-                    if (ref($item) eq 'ARRAY') {
-                        my $borderbot;
-                        my ($padtop,$padbot) = (0,0);
-                        if ($count == 1)  {
-                            $padtop = '5px';
-                        }
-                        if ($count == $numsub) {
-                            $padbot = '5px';
-                            $borderbot = 'border-bottom:1px solid black;';
-                        }
-                        $menu .= '<li style="margin:0;padding-left:0;padding-right:0;'.
-                                 'padding-top:'.$padtop.';padding-bottom:'.$padbot.';'.
-                                 $borderbot.'"><a href="'.$item->[0].
-                                 '" style="padding: 0 5px 0 10px">'.
-                                 $item->[1].'</a></li>';
-                    }
-                }
-                $menu .= '</ul>';
-            }
-            $menu .= '</li>';
         } elsif ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) {
             # special treatment for role selector
             my $roles_selector = &roles_selector(
@@ -463,6 +428,34 @@
     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].'">'.
+                     '" style="padding: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