[PATCH] Add titlehints support for the navbar

Shlomi Fish <[email protected]>
Newsgroups gmane.comp.web.wml
Message-ID <[email protected]>
Hi!

This patch adds support for the titlehints directive that causes the
navbar to render the hint using a title="" attribute instead of the
JavaScript code that exists now.

Regards,

	Shlomi Fish


----------------------------------------------------------------------
Shlomi Fish        [email protected]
Home Page:         http://t2.technion.ac.il/~shlomif/

An apple a day will keep a doctor away. Two apples a day will keep two
doctors away.

	Falk Fish
wml-titlehints-patch.diff.txt (text/plain, 3.9 KB)
--- navbar.wml.orig	2003-07-03 14:57:17.000000000 +0300
+++ navbar.wml	2003-07-03 15:08:02.000000000 +0300
@@ -344,11 +344,12 @@
 #   navbar rendering
 #
 <define-tag navbar:render>
-<preserve name select subselected menumode txtonly nohints txtcol_normal txtcol_select />
+<preserve name select subselected menumode txtonly nohints txtcol_normal txtcol_select titlehints />
 <set-var subselected=* />
 <set-var menumode=inner />
 <set-var txtonly=* />
 <set-var nohints=* />
+<set-var titlehints=* />
 <navbar:index %attributes />
 <set-var %attributes />
 <subst-in-var select "[^a-zA-Z0-9]" "_" />
@@ -357,7 +358,7 @@
 <perl>
 sub navbar_render_<get-var __nbcount /><lang:current /> {
     my($name, $select, $subselected, $txtcol_n, $txtcol_s,
-       $menumode, $txtonly, $nohints, $nbcount) = @_;
+       $menumode, $txtonly, $nohints, $nbcount, $titlehints) = @_;
 
     #   select the correct navigation bar configuration
     my $CFG = $NAVBAR{$name};
@@ -483,6 +484,21 @@
         if ($alt eq '') {
             $alt = $txt;
         }
+        
+        my $hint_a_attributes = sub {
+            my $hint = shift;
+            if ($titlehints)
+            {
+                return qq{ title="$hint"};
+            }
+            else
+            {
+                return qq# onmouseover="self.status = '$hint'; return true"# .
+                      qq# onmouseout="self.status = ''; return true"# .
+                      qq# onfocus="self.status = '$hint'; return true"# .
+                      qq# onblur="self.status = ''; return true"#;
+            }
+        };
 
         #   output the button markup code
         if ($#img < 0 or $txtonly) {
@@ -505,10 +521,7 @@
             else {
                 $js = '';
                 if ($hint ne '') {
-                    $js = qq# onmouseover="self.status = '$hint'; return true"# .
-                          qq# onmouseout="self.status = ''; return true"# .
-                          qq# onfocus="self.status = '$hint'; return true"# .
-                          qq# onblur="self.status = ''; return true"#;
+                    $js = $hint_a_attributes->($hint);
                 }
                 $O .= '<*a href="'.$url.'"'.$target.$js.$extra_attr{'a'}.'>'.$txt.'<*/a>';
             }
@@ -532,10 +545,7 @@
                     push(@preload, [ $id, "s:$img[1]", "o:$img[2]" ]);
                 }
                 elsif ($hint ne '') {
-                    $js = qq# onmouseover="self.status = '$hint'; return true"# .
-                          qq# onmouseout="self.status = ''; return true"# .
-                          qq# onfocus="self.status = '$hint'; return true"# .
-                          qq# onblur="self.status = ''; return true"#;
+                    $js = $hint_a_attributes->($hint);
                 }
                 $O .= '<*a href="'.$url.'"'.$target.$js.$extra_attr{'a'}.'>' .
                       '<img name="'.$nb.'_'.$id.'" src="'.$img[1].'" alt="'.$alt.'" border=0'.$extra_attr{'img'}.' />' .
@@ -642,15 +652,16 @@
     my $menumode    =  qq|<get-var menumode />|;
     my $txtonly     = (qq|<get-var txtonly />|     eq '' ? 1 : 0);
     my $nohints     = (qq|<get-var nohints />|     eq '' ? 1 : 0);
+    my $titlehints  = (qq|<get-var titlehints />|     eq '' ? 1 : 0);
 
     <perl:print: \
        "&navbar_render_<get-var __nbcount /><lang:current />('<get-var name />',
              $select, $subselected,
              '<get-var txtcol_normal />', '<get-var txtcol_select />', 
-             $menumode, $txtonly, $nohints, <get-var __nbcount />)" />
+             $menumode, $txtonly, $nohints, <get-var __nbcount />, $titlehints)" />
 }
 </perl>
-<restore  name select subselected menumode txtonly nohints txtcol_normal txtcol_select />
+<restore  name select subselected menumode txtonly nohints txtcol_normal txtcol_select titlehints />
 </define-tag>
 
 <define-tag navbar:jsfuncs>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.