[LON-CAPA-cvs] cvs: loncom /homework functionplotresponse.pm structuretags.pm
www
www@source.lon-capa.org
Thu, 28 Oct 2010 00:27:56 -0000
www Thu Oct 28 00:27:56 2010 EDT
Modified files:
/loncom/homework functionplotresponse.pm structuretags.pm
Log:
Need to wait till all applets on the page are loaded before starting to
initialize them.
Index: loncom/homework/functionplotresponse.pm
diff -u loncom/homework/functionplotresponse.pm:1.15 loncom/homework/functionplotresponse.pm:1.16
--- loncom/homework/functionplotresponse.pm:1.15 Tue Oct 19 02:04:27 2010
+++ loncom/homework/functionplotresponse.pm Thu Oct 28 00:27:56 2010
@@ -1,7 +1,7 @@
# LearningOnline Network with CAPA
# option list style responses
#
-# $Id: functionplotresponse.pm,v 1.15 2010/10/19 02:04:27 www Exp $
+# $Id: functionplotresponse.pm,v 1.16 2010/10/28 00:27:56 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -101,12 +101,25 @@
#
sub init_script {
- if ($Apache::functionplotresponse::callscripts) {
+ if ($#Apache::functionplotresponse::callscripts>=0) {
+ my $script='';
+ foreach my $id (@Apache::functionplotresponse::callscripts) {
+ $script.="if (param=='applet_$id') { loaded_$id=true; }\n";
+ }
+ $script.="if (".join(' && ',map { "loaded_$_" } (@Apache::functionplotresponse::callscripts)).
+ ") { setTimeout('ggbInitAll()',20) }\n";
+ my $calls=join("\n",map { "ggbInit_$_();" } (@Apache::functionplotresponse::callscripts));
return (<<ENDGGBINIT);
<script type="text/javascript">
// <![CDATA[
+// Function that each applet will call when loaded
+// It will pass "its" parameter
+// Set flags for when an applet is loaded, wait till all are loaded, and then some
function ggbOnInit(param) {
-$Apache::functionplotresponse::callscripts
+$script
+}
+function ggbInitAll() {
+$calls;
}
// ]]>
</script>
@@ -194,14 +207,16 @@
#
sub start_init_script {
my ($id)=@_;
-# Add a line to ggbOnInit-function which calls the right function based on parameter passed from GeoGebra
- $Apache::functionplotresponse::callscripts.="if (param=='applet_$id') { ggbInit_$id(); }\n";
+# Add id to the list of ggbInit_$id functions that need to be called
+ push(@Apache::functionplotresponse::callscripts,$id);
# ... and open this function
return (<<ENDSTARTINIT);
<script type="text/javascript">
// <![CDATA[
// variable that will eventually be passed back to the server
var coordinateMap_$id = [];
+// flag for not loaded yet
+var loaded_$id=false;
// Init-function for applet
function ggbInit_$id() {
ENDSTARTINIT
Index: loncom/homework/structuretags.pm
diff -u loncom/homework/structuretags.pm:1.476 loncom/homework/structuretags.pm:1.477
--- loncom/homework/structuretags.pm:1.476 Mon Oct 4 18:28:53 2010
+++ loncom/homework/structuretags.pm Thu Oct 28 00:27:56 2010
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# definition of tags that give a structure to a document
#
-# $Id: structuretags.pm,v 1.476 2010/10/04 18:28:53 www Exp $
+# $Id: structuretags.pm,v 1.477 2010/10/28 00:27:56 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -783,7 +783,7 @@
&Apache::lonhomework::reset_show_problem_status();
$Apache::lonhomework::ignore_response_errors=1;
}
- $Apache::functionplotresponse::callscripts='';
+ @Apache::functionplotresponse::callscripts=();
@Apache::inputtags::responselist = ();
@Apache::inputtags::importlist = ();
@Apache::inputtags::previous=();
@@ -811,7 +811,7 @@
undef($Apache::lonhomework::type);
undef($Apache::lonhomework::scantronmode);
undef($Apache::lonhomework::ignore_response_errors);
- undef($Apache::functionplotresponse::callscripts);
+ undef(@Apache::functionplotresponse::callscripts);
&Apache::lonhomework::reset_show_problem_status();
}