[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm
bowersj2
lon-capa-cvs@mail.lon-capa.org
Tue, 26 Aug 2003 17:20:45 -0000
bowersj2 Tue Aug 26 13:20:45 2003 EDT
Modified files:
/loncom/interface loncommon.pm
Log:
Changable line support added.
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.112 loncom/interface/loncommon.pm:1.113
--- loncom/interface/loncommon.pm:1.112 Wed Aug 20 14:18:45 2003
+++ loncom/interface/loncommon.pm Tue Aug 26 13:20:45 2003
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.112 2003/08/20 18:18:45 bowersj2 Exp $
+# $Id: loncommon.pm,v 1.113 2003/08/26 17:20:45 bowersj2 Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -624,8 +624,6 @@
Translate $text to allow it to be output as a 'comma seperated values'
format.
-=back
-
=cut
sub csv_translate {
@@ -634,6 +632,91 @@
$text =~ s/\n//g;
return $text;
}
+
+=pod
+
+=item * change_content_javascript():
+
+This and the next function allow you to create small sections of an
+otherwise static HTML page that you can update on the fly with
+Javascript, even in Netscape 4.
+
+The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
+must be written to the HTML page once. It will prove the Javascript
+function "change(name, content)". Calling the change function with the
+name of the section
+you want to update, matching the name passed to C<changable_area>, and
+the new content you want to put in there, will put the content into
+that area.
+
+B<Note>: Netscape 4 only reserves enough space for the changable area
+to contain room for the original contents. You need to "make space"
+for whatever changes you wish to make, and be B<sure> to check your
+code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
+it's adequate for updating a one-line status display, but little more.
+This script will set the space to 100% width, so you only need to
+worry about height in Netscape 4.
+
+Modern browsers are much less limiting, and if you can commit to the
+user not using Netscape 4, this feature may be used freely with
+pretty much any HTML.
+
+=cut
+
+sub change_content_javascript {
+ # If we're on Netscape 4, we need to use Layer-based code
+ if ($ENV{'browser.type'} eq 'netscape' &&
+ $ENV{'browser.version'} =~ /^4\./) {
+ return (<<NETSCAPE4);
+ function change(name, content) {
+ doc = document.layers[name+"___escape"].layers[0].document;
+ doc.open();
+ doc.write(content);
+ doc.close();
+ }
+NETSCAPE4
+ } else {
+ # Otherwise, we need to use semi-standards-compliant code
+ # (technically, "innerHTML" isn't standard but the equivalent
+ # is really scary, and every useful browser supports it
+ return (<<DOMBASED);
+ function change(name, content) {
+ element = document.getElementById(name);
+ element.innerHTML = content;
+ }
+DOMBASED
+ }
+}
+
+=pod
+
+=item * changable_area($name, $origContent):
+
+This provides a "changable area" that can be modified on the fly via
+the Javascript code provided in C<change_content_javascript>. $name is
+the name you will use to reference the area later; do not repeat the
+same name on a given HTML page more then once. $origContent is what
+the area will originally contain, which can be left blank.
+
+=cut
+
+sub changable_area {
+ my ($name, $origContent) = @_;
+
+ if ($ENV{'browser.type'} eq 'netscape' &&
+ $ENV{'browser.version'} =~ /^4\./) {
+ # If this is netscape 4, we need to use the Layer tag
+ return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
+ } else {
+ return "<span id='$name'>$origContent</span>";
+ }
+}
+
+=pod
+
+=back
+
+=cut
###############################################################
## Home server <option> list generating code ##