Parent Directory
|
Revision Log
This version of Applet.pm now works with IE. More documentation and features are forth coming but it is ready for some experimental use by those developing Applets.
1 ################################################################################ 2 # WeBWorK Online Homework Delivery System 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 $ 5 # 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 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. 10 # 11 # This program is distributed in the hope that it will be useful, but WITHOUT 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 # FOR A PARTICULAR PURPOSE. See either the GNU General Public License or the 14 # Artistic License for more details. 15 ################################################################################ 16 17 =head1 NAME 18 19 Applet.pl - Provides code for inserting FlashApplets and JavaApplets into webwork problems 20 21 =head1 SYNPOSIS 22 23 ################################### 24 # Create link to applet 25 ################################### 26 my $appletName = "LineThruPointsWW"; 27 $applet = new FlashApplet( 28 codebase => findAppletCodebase("$appletName.swf"), 29 appletName => $appletName, 30 appletId => $appletName, 31 submitActionAlias => 'checkAnswer', 32 ); 33 34 ################################### 35 # Configure applet 36 ################################### 37 38 #xml data to set up the problem-rac 39 $applet->xmlString(qq{<XML> 40 <point xval='$xval_1' yval='$yval_1' /> 41 <point xval='$xval_2' yval='$yval_2' /> 42 </XML>}); 43 44 45 ################################### 46 # insert applet header material 47 ################################### 48 HEADER_TEXT($applet->insertHeader ); 49 50 ################################### 51 # Text section 52 # 53 54 ################################### 55 #insert applet into body 56 ################################### 57 TEXT( MODES(TeX=>'object code', HTML=>$applet->insertObject)); 58 59 60 =head1 DESCRIPTION 61 62 This file provides an object to store in one place 63 all of the information needed to call an applet. 64 65 The object FlashApplet has defaults for inserting flash applets. 66 67 =over 68 69 =item * 70 71 =item * 72 73 =back 74 75 (not yet completed) 76 77 The module JavaApplet has defaults for inserting java applets. 78 79 The module Applet will store common code for the two types of applet. 80 81 =head1 USAGE 82 83 This file is included by listing it in the modules section of global.conf. 84 85 =cut 86 87 88 89 package Applet; 90 91 92 package FlashApplet; 93 94 95 use MIME::Base64 qw( encode_base64 decode_base64); 96 97 use 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 102 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 120 </script> 121 122 END_HEADER_SCRIPT 123 124 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" 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 140 use constant DEFAULT_OBJECT_TEXT =><<'END_OBJECT_TEXT'; 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 156 </object> 157 END_OBJECT_TEXT 158 159 160 sub new { 161 my $class = shift; 162 my $self = { 163 host =>'', 164 port => '', 165 path => '', 166 appletName =>'', 167 codebase=>'', 168 appletId =>'', 169 params =>undef, 170 base64_xmlString => 'foobar', 171 initializeActionAlias => 'setupProblem', 172 submitActionAlias => 'checkAnswer', 173 returnFieldName => 'receivedField', 174 headerText => DEFAULT_HEADER_TEXT(), 175 objectText => DEFAULT_OBJECT_TEXT(), 176 @_, 177 }; 178 bless $self, $class; 179 #$self -> _initialize(@_); 180 return $self; 181 } 182 183 sub header { 184 my $self = shift; 185 if ($_[0] eq "reset") { # $applet->header('reset'); erases default header text. 186 $self->{headerText}=''; 187 } else { 188 $self->{headerText} .= join("",@_); # $applet->header(new_text); concatenates new_text to existing header. 189 } 190 $self->{headerText}; 191 } 192 sub object { 193 my $self = shift; 194 if ($_[0] eq "reset") { 195 $self->{objectText}=''; 196 } else { 197 $self->{objectText} .= join("",@_); 198 } 199 $self->{objectText}; 200 } 201 sub params { 202 my $self = shift; 203 if (ref($_[0]) =~/HASH/) { 204 $self->{params} = shift; 205 } elsif ( $_[0] =~ '') { 206 # do nothing (read) 207 } else { 208 warn "You must enter a reference to a hash for the parameter list"; 209 } 210 $self->{params}; 211 } 212 213 sub initializeActionAlias { 214 my $self = shift; 215 $self->{initializeActionAlias} = shift ||$self->{initializeActionAlias}; # replace the current contents if non-empty 216 $self->{initializeActionAlias}; 217 } 218 219 sub submitActionAlias { 220 my $self = shift; 221 $self->{submitActionAlias} = shift ||$self->{submitActionAlias}; # replace the current contents if non-empty 222 $self->{submitActionAlias}; 223 } 224 sub returnFieldName { 225 my $self = shift; 226 $self->{returnFieldName} = shift ||$self->{returnFieldName}; # replace the current contents if non-empty 227 $self->{returnFieldName}; 228 } 229 sub codebase { 230 my $self = shift; 231 $self->{codebase} = shift ||$self->{codebase}; # replace the current codebase if non-empty 232 $self->{codebase}; 233 } 234 sub appletName { 235 my $self = shift; 236 $self->{appletName} = shift ||$self->{appletName}; # replace the current appletName if non-empty 237 $self->{appletName}; 238 } 239 sub appletId { 240 my $self = shift; 241 $self->{appletId} = shift ||$self->{appletId}; # replace the current appletName if non-empty 242 $self->{appletId}; 243 } 244 sub xmlString { 245 my $self = shift; 246 my $str = shift; 247 $self->{base64_xmlString} = encode_base64($str) ||$self->{base64_xmlString}; # replace the current string if non-empty 248 $self->{base64_xmlString} =~ s/\n//g; 249 decode_base64($self->{base64_xmlString}); 250 } 251 252 sub base64_xmlString{ 253 my $self = shift; 254 $self->{base64_xmlString} = shift ||$self->{base64_xmlString}; # replace the current string if non-empty 255 $self->{base64_xmlString}; 256 } 257 258 #FIXME 259 # need to be able to adjust header material 260 261 sub insertHeader { 262 my $self = shift; 263 my $codebase = $self->{codebase}; 264 my $appletId = $self->{appletId}; 265 my $appletName = $self->{appletName}; 266 my $base64_xmlString = $self->{base64_xmlString}; 267 my $initializeAction = $self->{initializeActionAlias}; 268 my $submitAction = $self->{submitActionAlias}; 269 my $returnFieldName= $self->{returnFieldName}; 270 my $headerText = $self->header(); 271 $headerText =~ s/(\$\w+)/$1/gee; # interpolate variables p17 of Cookbook 272 273 return $headerText; 274 275 276 } 277 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> 307 sub insertObject { 308 my $self = shift; 309 my $codebase = $self->{codebase}; 310 my $appletId = $self->{appletId}; 311 my $appletName = $self->{appletName}; 312 $codebase = findAppletCodebase("$appletName.swf") unless $codebase; 313 $objectText = $self->{objectText}; 314 $objectText =~ s/(\$\w+)/$1/gee; 315 return $objectText; 316 } 317 318 sub initialize { 319 my $self = shift; 320 return q{ 321 <script> 322 initialize(); 323 // this should really be done in the <body> tag 324 </script> 325 }; 326 327 } 328 329 1;
aubreyja at gmail dot com | ViewVC Help |
Powered by ViewVC 1.0.9 |