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

droeschl droeschl@source.lon-capa.org
Tue, 11 Aug 2009 13:01:10 -0000


droeschl		Tue Aug 11 13:01:10 2009 EDT

  Modified files:              
    /loncom/interface	lonhtmlcommon.pm 
  Log:
  scripttag can now be called such that it only includes BEGIN or END LON-CAPA Internal markers within a script.
  See usage comment for further information.
  
  
Index: loncom/interface/lonhtmlcommon.pm
diff -u loncom/interface/lonhtmlcommon.pm:1.230 loncom/interface/lonhtmlcommon.pm:1.231
--- loncom/interface/lonhtmlcommon.pm:1.230	Mon Aug 10 16:27:39 2009
+++ loncom/interface/lonhtmlcommon.pm	Tue Aug 11 13:01:10 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common html routines
 #
-# $Id: lonhtmlcommon.pm,v 1.230 2009/08/10 16:27:39 bisitz Exp $
+# $Id: lonhtmlcommon.pm,v 1.231 2009/08/11 13:01:10 droeschl Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2109,22 +2109,38 @@
 }
 
 
-# USAGE: scripttag(scriptcode, true/false);
+# USAGE: scripttag(scriptcode, [start|end|both]);
 #
 # EXAMPLES: 
-#  - scripttag("alert('Hello World!')") 
+#  - scripttag("alert('Hello World!')", 'both') 
+#    returns:
+#    <script type="text/javascript">
+#    // BEGIN LON-CAPA Internal
+#    alert(Hello World!')
+#    // END LON-CAPA Internal
+#    </script>
 #
 # NOTES:
 # - works currently only for javascripts
 #
-# OUTPUT: Scriptcode properly enclosed in <script> and CDATA tags (and LC
-# Internal markers if 2nd argument evaluates to true)
+# OUTPUT: 
+# Scriptcode properly enclosed in <script> and CDATA tags (and LC
+# Internal markers if 2nd argument is given)
 sub scripttag {
-    my ($content, $internal) = @_;
-    $content = "// BEGIN LON-CAPA Internal\n$content\n// END LON-CAPA Internal" if $internal;
+    my ( $content, $marker ) = @_;
+    return unless defined $content;
+
+    my $begin = "\n// BEGIN LON-CAPA Internal\n";
+    my $end   = "\n// END LON-CAPA Internal\n";
+
+    if ($marker) {
+        $content  = $begin . $content if $marker eq 'start' or $marker eq 'both';
+        $content .= $end              if $marker eq 'end'   or $marker eq 'both';
+    }
+
     $content = "\n// <![CDATA[\n$content\n// ]]>\n";
-    htmltag("script", $content, {type => "text/javascript"});
-    return htmltag("script", $content, {type => "text/javascript"});
+
+    return htmltag('script', $content, {type => 'text/javascript'});
 };