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

albertel lon-capa-cvs@mail.lon-capa.org
Tue, 12 Dec 2006 20:41:09 -0000


albertel		Tue Dec 12 15:41:09 2006 EDT

  Modified files:              
    /loncom/interface	lonhelper.pm 
  Log:
  - adding a <helpicon> tag to the helper
  
  
Index: loncom/interface/lonhelper.pm
diff -u loncom/interface/lonhelper.pm:1.158 loncom/interface/lonhelper.pm:1.159
--- loncom/interface/lonhelper.pm:1.158	Tue Aug  1 11:12:32 2006
+++ loncom/interface/lonhelper.pm	Tue Dec 12 15:41:08 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # .helper XML handler to implement the LON-CAPA helper
 #
-# $Id: lonhelper.pm,v 1.158 2006/08/01 15:12:32 albertel Exp $
+# $Id: lonhelper.pm,v 1.159 2006/12/12 20:41:08 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1023,6 +1023,91 @@
 }
 1;
 
+package Apache::lonhelper::helpicon;
+
+=pod
+
+=head1 Elements
+
+=head2 Element: helpiconX<helpicon, helper element>
+
+Helpicon elements add a help icon at the current location.
+Example:
+
+   <helpicon file="Help">
+     General Help
+   </helpicon>
+
+In this example will generate a help icon to the Help.hlp url with a
+description of 'General Help'. The description is not required and if
+left out (Example: <helpicon file="Help" /> only the icon will be
+added.)
+
+=head3 Localization
+
+The description text will be run through the normalize_string function
+and that will be used as a call to &mt.
+
+=cut
+
+no strict;
+@ISA = ("Apache::lonhelper::element");
+use strict;
+use Apache::lonlocal;
+
+BEGIN {
+    &Apache::lonhelper::register('Apache::lonhelper::helpicon',
+				 ('helpicon'));
+}
+
+sub new {
+    my $ref = Apache::lonhelper::element->new();
+    bless($ref);
+}
+
+# CONSTRUCTION: Construct the message element from the XML
+sub start_helpicon {
+    my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
+
+    if ($target ne 'helper') {
+        return '';
+    }
+
+    $paramHash->{HELP_TEXT} = &mtn(&Apache::lonxml::get_all_text('/helpicon',
+								 $parser));
+
+    $paramHash->{HELP_TEXT} =~s/^\s+//;
+    $paramHash->{HELP_TEXT} =~s/\s+$//;
+
+    if (defined($token->[2]{'file'})) {
+        $paramHash->{HELP_FILE} = $token->[2]{'file'};
+    }
+    return '';
+}
+
+sub end_helpicon {
+    my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
+
+    if ($target ne 'helper') {
+        return '';
+    }
+    Apache::lonhelper::helpicon->new();
+    return '';
+}
+
+sub render {
+    my $self = shift;
+
+    my $text;
+    if ( $self->{HELP_TEXT} ne '') {
+	$text=&mtn($text);
+    }
+
+    return &Apache::loncommon::help_open_topic($self->{HELP_FILE},
+					       $text);
+}
+1;
+
 package Apache::lonhelper::skip;
 
 =pod