[LON-CAPA-cvs] cvs: loncom /xml lonplot.pm

foxr lon-capa-cvs@mail.lon-capa.org
Tue, 31 May 2005 22:15:34 -0000


foxr		Tue May 31 18:15:34 2005 EDT

  Modified files:              
    /loncom/xml	lonplot.pm 
  Log:
  Support registration of a callback by upper level tags to take tag dependent 
  action when a gnuplot image is created.  Note that callback nesting is not
  supported at this time.
  
  
Index: loncom/xml/lonplot.pm
diff -u loncom/xml/lonplot.pm:1.107 loncom/xml/lonplot.pm:1.108
--- loncom/xml/lonplot.pm:1.107	Mon May 16 17:58:41 2005
+++ loncom/xml/lonplot.pm	Tue May 31 18:15:32 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Dynamic plot
 #
-# $Id: lonplot.pm,v 1.107 2005/05/16 21:58:41 foxr Exp $
+# $Id: lonplot.pm,v 1.108 2005/05/31 22:15:32 foxr Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -39,6 +39,12 @@
 
 use vars qw/$weboutputformat $versionstring/;
 
+#
+#   This variable allows a callback to be registered
+#   if a gnuplot tag block is performed.
+#
+my $notify_callback;
+
 BEGIN {
     &Apache::lonxml::register('Apache::lonplot',('gnuplot'));
     #
@@ -48,6 +54,30 @@
     if ($versionstring =~ /^gnuplot 4/) {
         $weboutputformat = 'png';
     }
+    $notify_callback = undef;
+    
+}
+
+# register_callback(\&callback)
+#    Arranges for callback to be invoked on the </gnuplot>
+#    tag.
+# 
+sub register_callback {
+    $notify_callback = shift;
+}
+# clear_callback();
+#     Undefs the callback.
+#
+sub clear_callback {
+    $notify_callback = undef;
+}
+# invoke_callback()
+#     Invokes the callback if defined
+#
+sub invoke_callback {
+    if (defined $notify_callback) {
+	&$notify_callback();
+    }
 }
 
 ## 
@@ -540,6 +570,7 @@
     } elsif ($target eq 'edit') {
 	$result.=&Apache::edit::tag_end($target,$token);
     }
+    &invoke_callback();
     return $result;
 }