[system] / trunk / pg / lib / Applet.pm Repository:
ViewVC logotype

Diff of /trunk/pg/lib/Applet.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 5578 Revision 6023
1################################################################################ 1################################################################################
2# WeBWorK Online Homework Delivery System 2# WeBWorK Online Homework Delivery System
3# Copyright 2000-2007 The WeBWorK Project, http://openwebwork.sf.net/ 3# Copyright 2000-2007 The WeBWorK Project, http://openwebwork.sf.net/
4# $CVSHeader: pg/lib/Applet.pm,v 1.1 2007/10/30 15:57:04 gage Exp $ 4# $CVSHeader: pg/lib/Applet.pm,v 1.18 2009/03/10 12:10:36 gage Exp $
5# 5#
6# This program is free software; you can redistribute it and/or modify it under 6# This program is free software; you can redistribute it and/or modify it under
7# the terms of either: (a) the GNU General Public License as published by the 7# the terms of either: (a) the GNU General Public License as published by the
8# Free Software Foundation; either version 2, or (at your option) any later 8# Free Software Foundation; either version 2, or (at your option) any later
9# version, or (b) the "Artistic License" which comes with this package. 9# version, or (b) the "Artistic License" which comes with this package.
22 22
23 ################################### 23 ###################################
24 # Create link to applet 24 # Create link to applet
25 ################################### 25 ###################################
26 my $appletName = "LineThruPointsWW"; 26 my $appletName = "LineThruPointsWW";
27 $applet = new FlashApplet( 27 $applet = new FlashApplet(
28 # can be replaced by $applet =FlashApplet() when using AppletObjects.pl
28 codebase => findAppletCodebase("$appletName.swf"), 29 codebase => findAppletCodebase("$appletName.swf"),
29 appletName => $appletName, 30 appletName => $appletName,
30 appletId => $appletName, 31 appletId => $appletName,
31 submitActionAlias => 'checkAnswer', 32 submitActionAlias => 'checkAnswer',
32 ); 33 );
34 ################################### 35 ###################################
35 # Configure applet 36 # Configure applet
36 ################################### 37 ###################################
37 38
38 #xml data to set up the problem-rac 39 #xml data to set up the problem-rac
39 $applet->xmlString(qq{<XML> 40 $applet->config(qq{<XML>
40 <point xval='$xval_1' yval='$yval_1' /> 41 <point xval='$xval_1' yval='$yval_1' />
41 <point xval='$xval_2' yval='$yval_2' /> 42 <point xval='$xval_2' yval='$yval_2' />
42 </XML>}); 43 </XML>});
43 44
44 45
74 75
75(not yet completed) 76(not yet completed)
76 77
77The module JavaApplet has defaults for inserting java applets. 78The module JavaApplet has defaults for inserting java applets.
78 79
79The module Applet will store common code for the two types of applet. 80The module Applet stores common code for the two types of applet.
80 81
81=head1 USAGE 82=head1 USAGE
82 83
83This file is included by listing it in the modules section of global.conf. 84These modules are activate by listing it in the modules section of global.conf and rebooting the server.
85The companion file to this one is macros/AppletObjects.pl
86
87qw(Applet FlashApplet JavaApplet)
84 88
85=cut 89=cut
86 90
87 91
88 92
89package Applet; 93package Applet;
90 94
95use URI::Escape;
91 96
92package FlashApplet;
93 97
94 98
95use MIME::Base64 qw( encode_base64 decode_base64); 99use MIME::Base64 qw( encode_base64 decode_base64);
96 100
97use constant DEFAULT_HEADER_TEXT =><<'END_HEADER_SCRIPT';
98 <script language="javascript">AC_FL_RunContent = 0;</script>
99 <script src="http://hosted2.webwork.rochester.edu/webwork2_files/applets/AC_RunActiveContent.js" language="javascript">
100 </script>
101 101
102 102=head2 Default javaScript functions placed in header
103 <script language="JavaScript">
104
105 var flash;
106 function getFlashMovie(movieName) {
107 var isIE = navigator.appName.indexOf("Microsoft") != -1;
108 return (isIE) ? window[movieName] : window.document[movieName];
109 //return window.document[movieName];
110 }
111
112
113 function initialize() {
114 getFlashMovie("$appletId").$initializeAction("$base64_xmlString");
115 }
116 function submitAction() {
117 document.problemMainForm.$returnFieldName.value = getFlashMovie("$appletId").$submitAction();
118 }
119 103
120 </script> 104=pod
121
122END_HEADER_SCRIPT
123 105
106These functions are automatically defined for use for
107any javaScript placed in the text of a PG question.
124 108
125# <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" 109 getApplet(appletName) -- finds the applet path in the DOM
126# width="550" height="400" id="$appletId" align="middle">
127# <param name="allowScriptAccess" value="sameDomain" />
128# <param name="allowFullScreen" value="false" />
129# <param name="movie" value="$appletName.swf" />
130# <param name="quality" value="high" />
131# <param name="bgcolor" value="#ffffcc" />
132# <embed src="$codebase/$appletName.swf" quality="high" bgcolor="#ffffcc" width="550" height="400" name="$appletName"
133# align="middle" id="$appletId",
134# align="middle" allowScriptAccess="sameDomain"
135# allowFullScreen="false"
136# type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
137# <param name="quality" value="high" /><param name="bgcolor" value="#ffffcc" />
138# </object>
139 110
140use constant DEFAULT_OBJECT_TEXT =><<'END_OBJECT_TEXT'; 111 submitAction() -- calls the submit action of the applets
141 <form></form>
142 <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
143 id="ExternalInterface" width="500" height="375"
144 codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">
145 <param name="movie" value="$codebase/$appletName.swf" />
146 <param name="quality" value="high" />
147 <param name="bgcolor" value="#869ca7" />
148 <param name="allowScriptAccess" value="sameDomain" />
149 <embed src="$codebase/$appletName.swf" quality="high" bgcolor="#869ca7"
150 width="550" height="400" name="$appletName" align="middle" id="$appletID"
151 play="true" loop="false" quality="high" allowScriptAccess="sameDomain"
152 type="application/x-shockwave-flash"
153 pluginspage="http://www.macromedia.com/go/getflashplayer">
154 </embed>
155 112
156 </object> 113 initializeWWquestion() -- calls the initialize action of the applets
157END_OBJECT_TEXT
158 114
115 getQE(name) -- gets an HTML element of the question by name
116 or by id. Be sure to keep all names and ids
117 unique within a given PG question.
118
119 getQuestionElement(name) -- long form of getQE(name)
120
121 listQuestionElements() -- for discovering the names of inputs in the
122 PG question. An alert dialog will list all
123 of the elements.
124 Usage: Place this at the END of the question, just before END_DOCUMENT():
125
126 TEXT(qq!<script> listQuestionElements() </script>!);
127 ENDDOCUMENT();
128 to obtain a list of all of the HTML elements in the question
129
130 ----------------------------------------------------------------------------
131
132
133 List of accessor methods made available by the FlashApplet class:
134 Usage: $current_value = $applet->method(new_value or empty)
135 These can also be set when creating the class -- for exampe:
136 $applet = new FlashApplet(
137 # can be replaced by $applet =FlashApplet() when using AppletObjects.pl
138 codebase => findAppletCodebase("$appletName.swf"),
139 appletName => $appletName,
140 appletId => $appletName,
141 submitActionAlias => 'checkAnswer',
142 );
143
144
145 appletId for simplicity and reliability appletId and appletName are always the same
146 appletName
147 archive the name of the .jar file containing the applet code
148 code the name of the applet code in the .jar archive
149 codebase a prefix url used to find the archive and the applet itself
150
151 height rectangle alloted in the html page for displaying the applet
152
153 params an anonymous array containing name/value pairs
154 to configure the applet [name =>'value, ...]
155
156 header stores the text to be added to the header section of the html page
157 object stores the text which places the applet on the html page
158
159 debug in debug mode several alerts mark progress through the procedure of calling the applet
160
161 config configuration are those customizable attributes of the applet which don't
162 change as it is used. When stored in hidden answer fields
163 it is usually stored in base64 encoded format.
164 base64_config base64 encode version of the contents of config
165
166 configAlias (default: setConfig ) names the applet command called with the contents of $self->config
167 to configure the applet. The parameters are passed to the applet in plain text using <xml>
168 The outer tags must be <xml> ..... </xml>
169 setConfigAlias (default: setConfig) -- a synonym for configAlias
170 getConfigAlias (default: getConfig) -- retrieves the configuration from the applet. This is used
171 mainly for debugging. In principal the configuration remains the same for a given instance
172 of the applet -- i.e. for the homework question for a single student. The state however
173 will change depending on the interactions between the student and the applet.
174 initialState the state consists of those customizable attributes of the applet which change
175 as the applet is used by the student. It is stored by the calling .pg question so that
176 when revisiting the question the applet will be restored to the same state it was left in when the question was last
177 viewed.
178
179 getStateAlias (default: getState) alias for command called to read the current state of the applet.
180 The state is passed in plain text xml format with outer tags: <xml>....</xml>
181 setStateAlias (default: setState) alias for the command called to reset the state of the applet.
182 The state is passed in plain text in xml format with outer tags: <xml>....</xml>
183
184 base64_state returns the base64 encoded version of the state stored in the applet object.
185
186 initializeActionAlias -- (default: initializeAction) the name of the javaScript subroutine called to initialize the applet (some overlap with config/ and setState
187 submitActionAlias -- (default: submitAction)the name of the javaScript subroutine called when the submit button of the
188 .pg question is pressed.
189 answerBox -- name of answer box to return answer to: default defaultAnswerBox
190 getAnswer -- (formerly sendData) get student answer from applet and place in answerBox
191 returnFieldName -- (deprecated) synonmym for answerBox
192
193
194=cut
195
196=head4 More details
197
198There are three different "images" of the applet. The first is the java or flash applet itself. The object that actually does the work.
199The second is a perl image of the applet -- henceforth the perlApplet -- which is configured in the .pg file and allows a WeBWorK question
200to communicate with the applet. The third image is a javaScript image of the applet -- henceforth the jsApplet which is a mirror of the perlApplet
201but is available to the javaScript code setup and executed in the virtual HTML page defined by the .pg file of the WeBWorK question. One can think of
202the jsApplet as a runtime version of the perlApplet since it can be accessed and modified after the virtual HTML page has been created by
203the PG rendering process.
204
205The perlApplet is initialized by $newApplet = new flashApplet( appletName=>'myApplet',..... ); The jsApplet is automatically defined in
206ww_applet_list["myApplet"] by copying the instance variables of $newApplet to a corresponding javaScript object. So $newApplet->{appletName}
207corresponds to ww_applet_list["myApplet"].appletName. (This paragraph is not yet fully implemented :-().
208
209Currently all messages read by the applet are xml text. If some of the code needs to be printed in the HTML header than it is converted
210to a base64 constant and then converted back to text form when it is read by an javaScript subroutine.
211
212=cut
213
214=head4 Requirements for applets
215
216The following methods are desirable in an applet that preserves state in a WW question. None of them are required.
217
218 setState(str) (default: setXML)
219 -- set the current state of the applet from an xml string
220 -- should be able to accept an empty string or a string of
221 the form <XML>.....</XML> without creating errors
222 -- can be designed to receive other forms of input if it is
223 coordinated with the WW question.
224 getState() (default: getXML)
225 -- return the current state of the applet in an xml string.
226 -- an empty string or a string of the form <XML>.....</XML>
227 are the standard responses.
228 -- can be designed to return other strings if it is
229 coordinated with the WW question.
230 setConfig(str) (default: setConfig)
231 -- If the applet allows configuration this configures the applet
232 from an xml string
233 -- should be able to accept an empty string or a string of the
234 form <XML>.....</XML> without creating errors
235 -- can be designed to receive other forms of input if it is
236 coordinated with the WW question.
237 getConfig (default: getConfig)
238 -- This returns a string defining the configuration of the
239 applet in an xml string
240 -- an empty string or a string of the form <XML>.....</XML>
241 are the standard responses.
242 -- can be designed to return other strings if it is
243 coordinated with the WW question.
244 -- this method is used for debugging to ensure that
245 the configuration was set as expected.
246 getAnswer (default: getAnswer)
247 -- Returns a string (usually NOT xml) which is the
248 response that the student is submitting to answer
249 the WW question.
250
251
252=cut
159 253
160sub new { 254sub new {
161 my $class = shift; 255 my $class = shift;
162 my $self = { 256 my $self = {
163 host =>'',
164 port => '',
165 path => '',
166 appletName =>'', 257 appletName =>'',
258 code=>'',
167 codebase=>'', 259 codebase=>'',
168 appletId =>'', 260# appletId =>'', #always use identical applet Id's and applet Names
169 params =>undef, 261 params =>undef,
170 base64_xmlString => 'foobar', 262 width => 550,
263 height => 400,
264 bgcolor => "#869ca7",
265 base64_state => undef, # this is a state to use for initializing the first occurence of the question.
266 base64_config => undef, # this is the initial (and final?) configuration
267# configuration => '', # configuration defining the applet
268 initialState => '', # initial state. (I'm considering storing everything as ascii and converting on the fly to base64 when needed.)
269 getStateAlias => 'getXML',
270 setStateAlias => 'setXML',
271 configAlias => '', # deprecated
272 getConfigAlias => 'getConfig',
273 setConfigAlias => 'setConfig',
171 initializeActionAlias => 'setupProblem', 274 initializeActionAlias => 'setXML',
172 submitActionAlias => 'checkAnswer', 275 submitActionAlias => 'getXML',
173 returnFieldName => 'receivedField', 276 submitActionScript => '', # script executed on submitting the WW question
277 answerBoxAlias => 'answerBox',
278 answerBox => '', # deprecated
279 returnFieldName => '', # deprecated
174 headerText => DEFAULT_HEADER_TEXT(), 280 headerText => DEFAULT_HEADER_TEXT(),
175 objectText => DEFAULT_OBJECT_TEXT(), 281 objectText => '',
282 debug => 0,
176 @_, 283 @_,
177 }; 284 };
178 bless $self, $class; 285 bless $self, $class;
179 #$self -> _initialize(@_); 286 $self->initialState('<xml></xml>');
287 if ($self->{returnFieldName}) or $self->{answerBox} ) { # backward compatibility
288 warn "use answerBoxAlias instead of returnFieldName or answerBox";
289 $self->{answerBox}='';
290 $self->{returnFieldName}='';
291 }
292 if ($self->{configAlias}) { # backward compatibility
293 warn "use setConfigAlias instead of configAlias";
294 $self->{configAlias}='';
295 }
296 $self->config('<xml></xml>');
180 return $self; 297 return $self;
181} 298}
182 299
183sub header { 300sub header {
184 my $self = shift; 301 my $self = shift;
200} 317}
201sub params { 318sub params {
202 my $self = shift; 319 my $self = shift;
203 if (ref($_[0]) =~/HASH/) { 320 if (ref($_[0]) =~/HASH/) {
204 $self->{params} = shift; 321 $self->{params} = shift;
205 } elsif ( $_[0] =~ '') { 322 } elsif ( !defined($_[0]) or $_[0] =~ '') {
206 # do nothing (read) 323 # do nothing (read)
207 } else { 324 } else {
208 warn "You must enter a reference to a hash for the parameter list"; 325 warn "You must enter a reference to a hash for the parameter list";
209 } 326 }
210 $self->{params}; 327 $self->{params};
219sub submitActionAlias { 336sub submitActionAlias {
220 my $self = shift; 337 my $self = shift;
221 $self->{submitActionAlias} = shift ||$self->{submitActionAlias}; # replace the current contents if non-empty 338 $self->{submitActionAlias} = shift ||$self->{submitActionAlias}; # replace the current contents if non-empty
222 $self->{submitActionAlias}; 339 $self->{submitActionAlias};
223} 340}
224sub returnFieldName { 341sub submitActionScript {
225 my $self = shift; 342 my $self = shift;
343 $self->{submitActionScript} = shift ||$self->{submitActionScript}; # replace the current contents if non-empty
344 $self->{submitActionScript};
345}
346sub getStateAlias {
347 my $self = shift;
348 $self->{getStateAlias} = shift ||$self->{getStateAlias}; # replace the current contents if non-empty
349 $self->{getStateAlias};
350}
351
352sub setStateAlias {
353 my $self = shift;
354 $self->{setStateAlias} = shift ||$self->{setStateAlias}; # replace the current contents if non-empty
355 $self->{setStateAlias};
356}
357sub configAlias {
358 my $self = shift;
226 $self->{returnFieldName} = shift ||$self->{returnFieldName}; # replace the current contents if non-empty 359 $self->{setConfigAlias} = shift ||$self->{setConfigAlias}; # replace the current contents if non-empty
227 $self->{returnFieldName}; 360 $self->{setConfigAlias};
361}
362sub setConfigAlias {
363 my $self = shift;
364 $self->{setConfigAlias} = shift ||$self->{setConfigAlias}; # replace the current contents if non-empty
365 $self->{setConfigAlias};
366}
367sub getConfigAlias {
368 my $self = shift;
369 $self->{getConfigAlias} = shift ||$self->{getConfigAlias}; # replace the current contents if non-empty
370 $self->{getConfigAlias};
371}
372
373sub answerBoxName {
374 my $self = shift;
375 $self->{answerBox} = shift ||$self->{answerBox}; # replace the current contents if non-empty
376 $self->{answerBox};
228} 377}
229sub codebase { 378sub codebase {
230 my $self = shift; 379 my $self = shift;
231 $self->{codebase} = shift ||$self->{codebase}; # replace the current codebase if non-empty 380 $self->{codebase} = shift ||$self->{codebase}; # replace the current codebase if non-empty
232 $self->{codebase}; 381 $self->{codebase};
233} 382}
383sub code {
384 my $self = shift;
385 $self->{code} = shift ||$self->{code}; # replace the current code if non-empty
386 $self->{code};
387}
388sub height {
389 my $self = shift;
390 $self->{height} = shift ||$self->{height}; # replace the current height if non-empty
391 $self->{height};
392}
393sub width {
394 my $self = shift;
395 $self->{width} = shift ||$self->{width}; # replace the current width if non-empty
396 $self->{width};
397}
398sub bgcolor {
399 my $self = shift;
400 $self->{bgcolor} = shift ||$self->{bgcolor}; # replace the current background color if non-empty
401 $self->{bgcolor};
402}
403sub archive {
404 my $self = shift;
405 $self->{archive} = shift ||$self->{archive}; # replace the current archive if non-empty
406 $self->{archive};
407}
234sub appletName { 408sub appletName {
235 my $self = shift; 409 my $self = shift;
236 $self->{appletName} = shift ||$self->{appletName}; # replace the current appletName if non-empty 410 $self->{appletName} = shift ||$self->{appletName}; # replace the current appletName if non-empty
237 $self->{appletName}; 411 $self->{appletName};
238} 412}
413sub debug {
414 my $self = shift;
415 my $new_flag = shift;
416 $self->{debug} = $new_flag if defined($new_flag);
417 $self->{debug};
418}
239sub appletId { 419sub appletId {
240 my $self = shift; 420 appletName(@_);
241 $self->{appletId} = shift ||$self->{appletId}; # replace the current appletName if non-empty
242 $self->{appletId};
243} 421}
244sub xmlString { 422
423sub initialState {
245 my $self = shift; 424 my $self = shift;
246 my $str = shift; 425 my $str = shift;
426 $self->{initialState} = $str ||$self->{initialState}; # replace the current string if non-empty
427 $self->{initialState};
428}
429
430sub config {
431 my $self = shift;
432 my $str = shift;
247 $self->{base64_xmlString} = encode_base64($str) ||$self->{base64_xmlString}; # replace the current string if non-empty 433 $self->{base64_config} = encode_base64($str) || $self->{base64_config}; # replace the current string if non-empty
248 $self->{base64_xmlString} =~ s/\n//g; 434 $self->{base64_config} =~ s/\n//g;
249 decode_base64($self->{base64_xmlString}); 435 decode_base64($self->{base64_config});
250} 436}
251 437#######################
252sub base64_xmlString{ 438# soon to be deprecated?
439#######################
440sub state {
441 my $self = shift;
253 my $self = shift; 442 my $str = shift;
443 $self->{base64_state} = encode_base64($str) ||$self->{base64_state}; # replace the current string if non-empty
444 $self->{base64_state} =~ s/\n//g;
445 decode_base64($self->{base64_state});
446}
447sub base64_state{
448 my $self = shift;
449 $self->{base64_state} = shift ||$self->{base64_state}; # replace the current string if non-empty
450 $self->{base64_state};
451}
452
453sub base64_config {
454 my $self = shift;
254 $self->{base64_xmlString} = shift ||$self->{base64_xmlString}; # replace the current string if non-empty 455 $self->{base64_config} = shift ||$self->{base64_config}; # replace the current string if non-empty
456 $self->{base64_config} =$self->{base64_config};
255 $self->{base64_xmlString}; 457 $self->{base64_config};
256} 458}
257 459
460sub returnFieldName {
461 my $self = shift;
462 warn "use answerBoxName instead of returnFieldName";
463}
464sub answerBox {
465 my $self = shift;
466 warn "use answerBoxName instead of AnswerBox";
467}
468#########################
258#FIXME 469#FIXME
259# need to be able to adjust header material 470# need to be able to adjust header material
260 471
261sub insertHeader { 472sub insertHeader {
262 my $self = shift; 473 my $self = shift;
474
263 my $codebase = $self->{codebase}; 475 my $codebase = $self->codebase;
264 my $appletId = $self->{appletId}; 476 my $appletId = $self->appletId;
265 my $appletName = $self->{appletName}; 477 my $appletName = $self->appletName;
266 my $base64_xmlString = $self->{base64_xmlString}; 478 my $base64_initialState = $self->base64_state;
267 my $initializeAction = $self->{initializeActionAlias}; 479 my $initializeAction = $self->initializeActionAlias;
480 my $submitActionAlias = $self->submitActionAlias;
268 my $submitAction = $self->{submitActionAlias}; 481 my $submitActionScript = $self->submitActionScript;
482 my $setStateAlias = $self->setStateAlias;
483 my $getStateAlias = $self->getStateAlias;
484
485 my $setConfigAlias = $self->setConfigAlias;
486 my $getConfigAlias = $self->getConfigAlias;
487 my $base64_config = $self->base64_config;
488 my $debugMode = ($self->debug) ? "1": "0";
269 my $returnFieldName= $self->{returnFieldName}; 489 my $returnFieldName = $self->{returnFieldName};
490 my $answerBox = $self->{answerBox};
270 my $headerText = $self->header(); 491 my $headerText = $self->header();
492
493
494 $submitActionScript =~ s/"/\\"/g; # escape quotes for ActionScript
495 # other variables should not have quotes.
496
497 $submitActionScript =~ s/\n/ /g; # replace returns with spaces -- returns in the wrong spot can cause trouble with javaScript
498 $submitActionScript =~ s/\r/ /g; # replace returns with spaces -- returns can cause trouble
499
271 $headerText =~ s/(\$\w+)/$1/gee; # interpolate variables p17 of Cookbook 500 $headerText =~ s/(\$\w+)/$1/gee; # interpolate variables p17 of Cookbook
272 501
273 return $headerText; 502 return $headerText;
274 503
275 504
276} 505}
277 506
278
279# <script language="javascript">
280# if (AC_FL_RunContent == 0) {
281# alert("This page requires AC_RunActiveContent.js.");
282# } else {
283# AC_FL_RunContent(
284# 'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
285# 'width', '100%',
286# 'height', '100%',
287# 'src', 'http://$codebase/$appletName',
288# 'quality', 'high',
289# 'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
290# 'align', 'middle',
291# 'play', 'true',
292# 'loop', 'true',
293# 'scale', 'showall',
294# 'wmode', 'window',
295# 'devicefont', 'false',
296# 'id', '$appletId',
297# 'bgcolor', '#ffffcc',
298# 'name', '$appletName',
299# 'menu', 'true',
300# 'allowFullScreen', 'false',
301# 'allowScriptAccess','sameDomain',
302# 'movie', '$appletName',
303# 'salign', ''
304# ); //end AC code
305# }
306# </script>
307sub insertObject { 507sub insertObject {
308 my $self = shift; 508 my $self = shift;
509 my $code = $self->{code};
309 my $codebase = $self->{codebase}; 510 my $codebase = $self->{codebase};
310 my $appletId = $self->{appletId}; 511 my $appletId = $self->{appletName};
311 my $appletName = $self->{appletName}; 512 my $appletName = $self->{appletName};
312 $codebase = findAppletCodebase("$appletName.swf") unless $codebase; 513 my $archive = $self->{archive};
514 my $width = $self->{width};
515 my $height = $self->{height};
516 my $applet_bgcolor = $self->{bgcolor};
517 my $javaParameters = '';
518 my $flashParameters = '';
519 my %param_hash = %{$self->params()};
520 foreach my $key (keys %param_hash) {
521 $javaParameters .= qq!<param name ="$key" value = "$param_hash{$key}">\n!;
522 $flashParameters .= uri_escape($key).'='.uri_escape($param_hash{$key}).'&';
523 }
524 $flashParameters =~ s/\&$//; # trim last &
525
526
313 $objectText = $self->{objectText}; 527 $objectText = $self->{objectText};
314 $objectText =~ s/(\$\w+)/$1/gee; 528 $objectText =~ s/(\$\w+)/$1/gee;
315 return $objectText; 529 return $objectText;
316} 530}
317
318sub initialize { 531# sub initialize {
319 my $self = shift; 532# my $self = shift;
320 return q{ 533# return q{
321 <script> 534# <script>
322 initialize(); 535# initializeAllApplets();
323 // this should really be done in the <body> tag 536# // this should really be done in the <body> tag
324 </script> 537# </script>
325 }; 538# };
539#
540# }
541########################################################
542# HEADER material for one flash or java applet
543########################################################
326 544
545use constant DEFAULT_HEADER_TEXT =><<'END_HEADER_SCRIPT';
546 <script src="/webwork2_files/js/Base64.js" language="javascript">
547 </script>
548 <script src="/webwork2_files/js/ww_applet_support.js" language="javascript">
549 //upload functions stored in /opt/webwork/webwork2/htdocs/js ...
550
551 </script>
552 <script language="JavaScript">
553
554 // set debug mode for this applet
555 set_debug($debugMode);
556
557 //////////////////////////////////////////////////////////
558 //TEST code
559 //
560 //
561 //////////////////////////////////////////////////////////
562
563 ww_applet_list["$appletName"] = new ww_applet("$appletName");
564
565
566 ww_applet_list["$appletName"].code = "$code";
567 ww_applet_list["$appletName"].codebase = "$codebase";
568 ww_applet_list["$appletName"].appletID = "$appletID";
569 ww_applet_list["$appletName"].base64_state = "$base64_initializationState";
570 ww_applet_list["$appletName"].base64_config = "$base64_config";
571 ww_applet_list["$appletName"].getStateAlias = "$getStateAlias";
572 ww_applet_list["$appletName"].setStateAlias = "$setStateAlias";
573 ww_applet_list["$appletName"].setConfigAlias = "$setConfigAlias";
574 ww_applet_list["$appletName"].getConfigAlias = "$getConfigAlias";
575 ww_applet_list["$appletName"].initializeActionAlias = "$initializeAction";
576 ww_applet_list["$appletName"].submitActionAlias = "$submitActionAlias";
577 ww_applet_list["$appletName"].submitActionScript = "$submitActionScript";
578 ww_applet_list["$appletName"].answerBox = "$answerBox";
579 ww_applet_list["$appletName"].debug = "$debugMode";
580
581 </script>
582
583END_HEADER_SCRIPT
584
585package FlashApplet;
586@ISA = qw(Applet);
587
588
589=head2 Insertion HTML code for FlashApplet
590
591=pod
592
593The secret to making this applet work with IE in addition to normal browsers
594is the addition of the C(<form></form>) construct just before the object.
595
596For some reason IE has trouble locating a flash object which is contained
597within a form. Adding this second blank form with the larger problemMainForm
598seems to solve the problem.
599
600This follows method2 of the advice given in url(http://kb.adobe.com/selfservice/viewContent.do?externalId=kb400730&sliceId=2)
601Method1 and methods involving SWFObject(Geoff Stearns) and SWFFormFix (Steve Kamerman) have yet to be fully investigated:
602http://devel.teratechnologies.net/swfformfix/swfobject_swfformfix_source.js
603http://www.teratechnologies.net/stevekamerman/index.php?m=01&y=07&entry=entry070101-033933
604
605 use constant DEFAULT_OBJECT_TEXT =><<'END_OBJECT_TEXT';
606 <form></form>
607 <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
608 id="$appletName" width="500" height="375"
609 codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">
610 <param name="movie" value="$codebase/$appletName.swf" />
611 <param name="quality" value="high" />
612 <param name="bgcolor" value="$applet_bgcolor" />
613 <param name="allowScriptAccess" value="sameDomain" />
614 <embed src="$codebase/$appletName.swf" quality="high" bgcolor="$applet_bgcolor"
615 width="$width" height="$height" name="$appletName" align="middle" id="$appletName"
616 play="true" loop="false" quality="high" allowScriptAccess="sameDomain"
617 type="application/x-shockwave-flash"
618 pluginspage="http://www.macromedia.com/go/getflashplayer">
619 </embed>
620
621 </object>
622 END_OBJECT_TEXT
623
624
625=cut
626
627use constant DEFAULT_OBJECT_TEXT =><<'END_OBJECT_TEXT';
628 <form></form>
629 <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
630 id="$appletName" width="500" height="375"
631 codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">
632 <param name="movie" value="$codebase/$appletName.swf" />
633 <param name="quality" value="high" />
634 <param name="bgcolor" value="$applet_bgcolor" />
635 <param name="allowScriptAccess" value="sameDomain" />
636 <param name="FlashVars" value="$flashParameters"/>
637 <embed src="$codebase/$appletName.swf" quality="high" bgcolor="$applet_bgcolor"
638 width="$width" height="$height" name="$appletName" align="middle" id="$appletName"
639 play="true" loop="false" quality="high" allowScriptAccess="sameDomain"
640 type="application/x-shockwave-flash"
641 pluginspage="http://www.macromedia.com/go/getflashplayer"
642 FlashVars="$flashParameters">
643 </embed>
644
645 </object>
646END_OBJECT_TEXT
647
648sub new {
649 my $class = shift;
650 $class -> SUPER::new( objectText => DEFAULT_OBJECT_TEXT(),
651 @_
652 );
653
327} 654}
655
656
657package JavaApplet;
658@ISA = qw(Applet);
659
660=head2 Insertion HTML code for JavaApplet
661
662=pod
663
664The secret to making this applet work with IE in addition to normal browsers
665is the addition of the C(<form></form>) construct just before the object.
666
667For some reason IE has trouble locating a flash object which is contained
668within a form. Adding this second blank form with the larger problemMainForm
669seems to solve the problem.
670
671This follows method2 of the advice given in url(http://kb.adobe.com/selfservice/viewContent.do?externalId=kb400730&sliceId=2)
672Method1 and methods involving SWFObject(Geoff Stearns) and SWFFormFix (Steve Kamerman) have yet to be fully investigated:
673http://devel.teratechnologies.net/swfformfix/swfobject_swfformfix_source.js
674http://www.teratechnologies.net/stevekamerman/index.php?m=01&y=07&entry=entry070101-033933
675
676 use constant DEFAULT_OBJECT_TEXT =><<'END_OBJECT_TEXT';
677 <form></form>
678 <applet
679 code = "$code"
680 codebase = "$codebase"
681 archive = "$archive"
682 name = "$appletName"
683 id = "$appletName"
684 width = "$width"
685 height = "$height"
686 MAYSCRIPT
687 >
688 $javaParameters
689 </applet>
690 END_OBJECT_TEXT
691
692=cut
693
694use constant DEFAULT_OBJECT_TEXT =><<'END_OBJECT_TEXT';
695 <form></form>
696 <applet
697 code = "$code"
698 codebase = "$codebase"
699 archive = "$archive"
700 name = "$appletName"
701 id = "$appletName"
702 width = "$width"
703 height = "$height"
704 bgcolor = "$applet_bgcolor"
705 MAYSCRIPT
706 >
707 $javaParameters
708
709 Sorry, the Applet could not be started. Please make sure that
710Java 1.4.2 (or later) is installed and activated.
711(<a href="http://java.sun.com/getjava">click here to install Java now</a>)
712 </applet>
713END_OBJECT_TEXT
714
715sub new {
716 my $class = shift;
717 $class -> SUPER::new( objectText => DEFAULT_OBJECT_TEXT(),
718 @_
719 );
720
721}
722
723
328 724
3291; 7251;

Legend:
Removed from v.5578  
changed lines
  Added in v.6023

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9