[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 5583 Revision 5594
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.2 2007/11/05 16:45:33 gage Exp $ 4# $CVSHeader: pg/lib/Applet.pm,v 1.3 2007/11/06 16:47:19 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 );
92package FlashApplet; 93package FlashApplet;
93 94
94 95
95use MIME::Base64 qw( encode_base64 decode_base64); 96use MIME::Base64 qw( encode_base64 decode_base64);
96 97
98
99=head2 Default javaScript functions placed in header
100
101These functions are automatically defined for use for
102any javaScript placed in the text of a PG question.
103
104 getFlashMovie(appletName) -- finds the applet path in the DOM
105
106 submitAction() -- calls the submit action of the applet
107 -- the submitAction is defined
108
109 initialize() -- calls the initialize action of the applet
110
111 getQE(name) -- gets an HTML element of the question by name
112 or by id. Be sure to keep all names and ids
113 unique within a given PG question.
114
115 getQuestionElement(name) -- long form of getQE(name)
116
117 listQuestionElements() -- for discovering the names of inputs in the
118 PG question. An alert dialog will list all
119 of the elements.
120 Usage: Place this at the END of the question,
121 just before END_DOCUMENT():
122
123 TEXT(qq!<script> listQuestionElements() </script>!);
124 ENDDOCUMENT();
125
126
127=cut
128
129
97use constant DEFAULT_HEADER_TEXT =><<'END_HEADER_SCRIPT'; 130use constant DEFAULT_HEADER_TEXT =><<'END_HEADER_SCRIPT';
98 <script language="javascript">AC_FL_RunContent = 0;</script> 131 <script language="javascript">AC_FL_RunContent = 0;</script>
99 <script src="http://hosted2.webwork.rochester.edu/webwork2_files/applets/AC_RunActiveContent.js" language="javascript"> 132 <script src="http://hosted2.webwork.rochester.edu/webwork2_files/applets/AC_RunActiveContent.js" language="javascript">
100 </script> 133 </script>
101 134
102 135
103 <script language="JavaScript"> 136 <script language="JavaScript">
104 137
105 var flash; 138 var flash;
106 function getFlashMovie(movieName) { 139 function getFlashMovie(appletName) {
107 var isIE = navigator.appName.indexOf("Microsoft") != -1; 140 var isIE = navigator.appName.indexOf("Microsoft") != -1;
108 return (isIE) ? window[movieName] : window.document[movieName]; 141 var obj = (isIE) ? window[appletName] : window.document[appletName];
109 //return window.document[movieName]; 142 //return window.document[appletName];
143 if (obj.name = appletName) {
144 return( obj );
145 } else {
146 alert ("can't find applet " + appletName);
147 }
110 } 148 }
111 149
112 150 function submitAction() {
151 getQE("$returnFieldName").value = getFlashMovie("$appletId").$submitAction();
152 }
113 function initialize() { 153 function initialize() {
114 getFlashMovie("$appletId").$initializeAction("$base64_xmlString"); 154 getFlashMovie("$appletId").$initializeAction("$base64_xmlString");
115 } 155 }
116 function submitAction() { 156 function getQE(name1) { // get Question Element in problemMainForm by name
117 document.problemMainForm.$returnFieldName.value = getFlashMovie("$appletId").$submitAction(); 157 var isIE = navigator.appName.indexOf("Microsoft") != -1;
118 } 158 var obj = (isIE) ? document.getElementById(name1)
159 :document.problemMainForm[name1];
160 // needed for IE -- searches id and name space so it can be unreliable if names are not unique
161 if (obj.name = name1 ) {
162 return( obj );
163 } else {
164 alert("Can't find " + name1);
165 listQuestionElements();
166 }
167
168 }
169 function getQuestionElement(name1) {
170 return getQE(name1);
171 }
172
173 function listQuestionElements() { // list all HTML elements in main problem form
174 var isIE = navigator.appName.indexOf("Microsoft") != -1;
175 var mainForm = (isIE) ? document.getElementsByTagName("input") : document.getElementsByTagName("input");
176 var str=mainForm.length +" Question Elements\n type | name = value < id > \n";
177 for( var i=0; i< mainForm.length; i++) {
178 str = str + " "+i+" " + mainForm[i].type
179 + " | " + mainForm[i].name
180 + "= " + mainForm[i].value +
181 " <" + mainForm[i].id + ">\n";
182 }
183 alert(str +"\n Place listQuestionElements() at end of document in order to get all form elements!");
184 }
185
119 186
120 </script> 187 </script>
121 188
122END_HEADER_SCRIPT 189END_HEADER_SCRIPT
123 190
149This follows method2 of the advice given in url(http://kb.adobe.com/selfservice/viewContent.do?externalId=kb400730&sliceId=2) 216This follows method2 of the advice given in url(http://kb.adobe.com/selfservice/viewContent.do?externalId=kb400730&sliceId=2)
150Method1 and methods involving SWFObject(Geoff Stearns) and SWFFormFix (Steve Kamerman) have yet to be fully investigated: 217Method1 and methods involving SWFObject(Geoff Stearns) and SWFFormFix (Steve Kamerman) have yet to be fully investigated:
151http://devel.teratechnologies.net/swfformfix/swfobject_swfformfix_source.js 218http://devel.teratechnologies.net/swfformfix/swfobject_swfformfix_source.js
152http://www.teratechnologies.net/stevekamerman/index.php?m=01&y=07&entry=entry070101-033933 219http://www.teratechnologies.net/stevekamerman/index.php?m=01&y=07&entry=entry070101-033933
153 220
221 use constant DEFAULT_OBJECT_TEXT =><<'END_OBJECT_TEXT';
222 <form></form>
223 <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
224 id="$appletName" width="500" height="375"
225 codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">
226 <param name="movie" value="$codebase/$appletName.swf" />
227 <param name="quality" value="high" />
228 <param name="bgcolor" value="#869ca7" />
229 <param name="allowScriptAccess" value="sameDomain" />
230 <embed src="$codebase/$appletName.swf" quality="high" bgcolor="#869ca7"
231 width="550" height="400" name="$appletName" align="middle" id="$appletID"
232 play="true" loop="false" quality="high" allowScriptAccess="sameDomain"
233 type="application/x-shockwave-flash"
234 pluginspage="http://www.macromedia.com/go/getflashplayer">
235 </embed>
236
237 </object>
238 END_OBJECT_TEXT
239
154=cut 240=cut
155 241
156use constant DEFAULT_OBJECT_TEXT =><<'END_OBJECT_TEXT'; 242use constant DEFAULT_OBJECT_TEXT =><<'END_OBJECT_TEXT';
157 <form></form> 243 <form></form>
158 <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" 244 <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
159 id="ExternalInterface" width="500" height="375" 245 id="$appletName" width="500" height="375"
160 codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab"> 246 codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">
161 <param name="movie" value="$codebase/$appletName.swf" /> 247 <param name="movie" value="$codebase/$appletName.swf" />
162 <param name="quality" value="high" /> 248 <param name="quality" value="high" />
163 <param name="bgcolor" value="#869ca7" /> 249 <param name="bgcolor" value="#869ca7" />
164 <param name="allowScriptAccess" value="sameDomain" /> 250 <param name="allowScriptAccess" value="sameDomain" />

Legend:
Removed from v.5583  
changed lines
  Added in v.5594

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9