[LON-CAPA-cvs] cvs: loncom /interface lonhtmlcommon.pm
droeschl
droeschl@source.lon-capa.org
Mon, 10 Aug 2009 12:32:34 -0000
droeschl Mon Aug 10 12:32:34 2009 EDT
Modified files:
/loncom/interface lonhtmlcommon.pm
Log:
Introduced a new sub that wraps javascript code in proper tags (which should reduce
some clutter within the code). See usage comment for further information.
Index: loncom/interface/lonhtmlcommon.pm
diff -u loncom/interface/lonhtmlcommon.pm:1.228 loncom/interface/lonhtmlcommon.pm:1.229
--- loncom/interface/lonhtmlcommon.pm:1.228 Mon Aug 3 16:34:16 2009
+++ loncom/interface/lonhtmlcommon.pm Mon Aug 10 12:32:34 2009
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common html routines
#
-# $Id: lonhtmlcommon.pm,v 1.228 2009/08/03 16:34:16 bisitz Exp $
+# $Id: lonhtmlcommon.pm,v 1.229 2009/08/10 12:32:34 droeschl Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -2117,6 +2117,25 @@
}
+# USAGE: scripttag(scriptcode, true/false);
+#
+# EXAMPLES:
+# - scripttag("alert('Hello World!')")
+#
+# 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)
+sub scripttag {
+ my ($content, $internal) = @_;
+ $content = "// BEGIN LON-CAPA Internal\n$content\n// END LON-CAPA Internal" if $internal;
+ $content = "\n// <![CDATA[\n$content\n// ]]>\n";
+ htmltag("script", $content, {type => "text/javascript"});
+ return htmltag("script", $content, {type => "text/javascript"});
+};
+
+
##############################################
##############################################