Parent Directory
|
Revision Log
Revision 5667 -
(view)
(download)
(as text)
Original Path: trunk/pg/lib/Applet.pm
| 1 : | gage | 5574 | ################################################################################ |
| 2 : | # WeBWorK Online Homework Delivery System | ||
| 3 : | # Copyright © 2000-2007 The WeBWorK Project, http://openwebwork.sf.net/ | ||
| 4 : | gage | 5667 | # $CVSHeader: pg/lib/Applet.pm,v 1.10 2008/05/05 17:24:31 gage Exp $ |
| 5 : | gage | 5574 | # |
| 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 : | gage | 5594 | $applet = new FlashApplet( |
| 28 : | # can be replaced by $applet =FlashApplet() when using AppletObjects.pl | ||
| 29 : | gage | 5574 | codebase => findAppletCodebase("$appletName.swf"), |
| 30 : | appletName => $appletName, | ||
| 31 : | appletId => $appletName, | ||
| 32 : | submitActionAlias => 'checkAnswer', | ||
| 33 : | ); | ||
| 34 : | |||
| 35 : | ################################### | ||
| 36 : | # Configure applet | ||
| 37 : | ################################### | ||
| 38 : | |||
| 39 : | #xml data to set up the problem-rac | ||
| 40 : | gage | 5661 | $applet->config(qq{<XML> |
| 41 : | gage | 5574 | <point xval='$xval_1' yval='$yval_1' /> |
| 42 : | <point xval='$xval_2' yval='$yval_2' /> | ||
| 43 : | </XML>}); | ||
| 44 : | |||
| 45 : | |||
| 46 : | ################################### | ||
| 47 : | # insert applet header material | ||
| 48 : | ################################### | ||
| 49 : | HEADER_TEXT($applet->insertHeader ); | ||
| 50 : | |||
| 51 : | ################################### | ||
| 52 : | # Text section | ||
| 53 : | # | ||
| 54 : | |||
| 55 : | ################################### | ||
| 56 : | #insert applet into body | ||
| 57 : | ################################### | ||
| 58 : | TEXT( MODES(TeX=>'object code', HTML=>$applet->insertObject)); | ||
| 59 : | |||
| 60 : | |||
| 61 : | =head1 DESCRIPTION | ||
| 62 : | |||
| 63 : | This file provides an object to store in one place | ||
| 64 : | all of the information needed to call an applet. | ||
| 65 : | |||
| 66 : | The object FlashApplet has defaults for inserting flash applets. | ||
| 67 : | |||
| 68 : | =over | ||
| 69 : | |||
| 70 : | =item * | ||
| 71 : | |||
| 72 : | =item * | ||
| 73 : | |||
| 74 : | =back | ||
| 75 : | |||
| 76 : | (not yet completed) | ||
| 77 : | |||
| 78 : | The module JavaApplet has defaults for inserting java applets. | ||
| 79 : | |||
| 80 : | gage | 5619 | The module Applet stores common code for the two types of applet. |
| 81 : | gage | 5574 | |
| 82 : | =head1 USAGE | ||
| 83 : | |||
| 84 : | gage | 5619 | These modules are activate by listing it in the modules section of global.conf and rebooting the server. |
| 85 : | The companion file to this one is macros/AppletObjects.pl | ||
| 86 : | gage | 5574 | |
| 87 : | gage | 5619 | qw(Applet FlashApplet JavaApplet) |
| 88 : | |||
| 89 : | gage | 5574 | =cut |
| 90 : | |||
| 91 : | |||
| 92 : | |||
| 93 : | package Applet; | ||
| 94 : | |||
| 95 : | gage | 5624 | use URI::Escape; |
| 96 : | gage | 5574 | |
| 97 : | |||
| 98 : | |||
| 99 : | use MIME::Base64 qw( encode_base64 decode_base64); | ||
| 100 : | |||
| 101 : | gage | 5594 | |
| 102 : | =head2 Default javaScript functions placed in header | ||
| 103 : | |||
| 104 : | These functions are automatically defined for use for | ||
| 105 : | any javaScript placed in the text of a PG question. | ||
| 106 : | |||
| 107 : | gage | 5619 | getApplet(appletName) -- finds the applet path in the DOM |
| 108 : | gage | 5594 | |
| 109 : | gage | 5619 | submitAction() -- calls the submit action of the applets |
| 110 : | |||
| 111 : | gage | 5594 | |
| 112 : | gage | 5619 | initializeAction() -- calls the initialize action of the applets |
| 113 : | gage | 5594 | |
| 114 : | getQE(name) -- gets an HTML element of the question by name | ||
| 115 : | or by id. Be sure to keep all names and ids | ||
| 116 : | unique within a given PG question. | ||
| 117 : | |||
| 118 : | getQuestionElement(name) -- long form of getQE(name) | ||
| 119 : | |||
| 120 : | listQuestionElements() -- for discovering the names of inputs in the | ||
| 121 : | PG question. An alert dialog will list all | ||
| 122 : | of the elements. | ||
| 123 : | Usage: Place this at the END of the question, | ||
| 124 : | just before END_DOCUMENT(): | ||
| 125 : | |||
| 126 : | TEXT(qq!<script> listQuestionElements() </script>!); | ||
| 127 : | ENDDOCUMENT(); | ||
| 128 : | |||
| 129 : | gage | 5619 | list of accessor methods format: current_value = $self->method(new_value or empty) |
| 130 : | gage | 5594 | |
| 131 : | gage | 5619 | appletId for simplicity and reliability appletId and appletName are always the same |
| 132 : | appletName | ||
| 133 : | |||
| 134 : | archive the name of the .jar file containing the applet code | ||
| 135 : | code the name of the applet code in the .jar archive | ||
| 136 : | codebase a prefix url used to find the archive and the applet itself | ||
| 137 : | |||
| 138 : | height rectangle alloted in the html page for displaying the applet | ||
| 139 : | width | ||
| 140 : | |||
| 141 : | params an anonymous array containing name/value pairs | ||
| 142 : | to configure the applet [name =>'value, ...] | ||
| 143 : | |||
| 144 : | header stores the text to be added to the header section of the html page | ||
| 145 : | object stores the text which places the applet on the html page | ||
| 146 : | |||
| 147 : | debug in debug mode several alerts mark progress through the procedure of calling the applet | ||
| 148 : | |||
| 149 : | config configuration are those customizable attributes of the applet which don't | ||
| 150 : | change as it is used. When stored in hidden answer fields | ||
| 151 : | it is usually stored in base64 encoded format. | ||
| 152 : | base64_config base64 encode version of the contents of config | ||
| 153 : | |||
| 154 : | configAlias (default: config ) names the applet command called with the contents of $self->config | ||
| 155 : | to configure the applet. The parameters are passed to the applet in plain text using <xml> | ||
| 156 : | The outer tags must be <xml> ..... </xml> | ||
| 157 : | state state consists of those customizable attributes of the applet which change | ||
| 158 : | as the applet is used. It is stored by the calling .pg question so that | ||
| 159 : | when revisiting the question the applet | ||
| 160 : | will be restored to the same state it was left in when the question was last | ||
| 161 : | viewed. | ||
| 162 : | |||
| 163 : | getStateAlias (default: getState) alias for command called to read the current state of the applet. | ||
| 164 : | The state is passed in plain text xml format with outer tags: <xml>....</xml> | ||
| 165 : | setStateAlias (default: setState) alias for the command called to reset the state of the applet. | ||
| 166 : | The state is passed in plain text in xml format with outer tags: <xml>....</xml> | ||
| 167 : | gage | 5594 | |
| 168 : | gage | 5619 | base64_state returns the base64 encoded version of the state stored in the applet object. |
| 169 : | |||
| 170 : | initializeActionAlias -- (default: initializeAction) the name of the javaScript subroutine called to initialize the applet (some overlap with config/ and setState | ||
| 171 : | submitActionAlias -- (default: submitAction)the name of the javaScript subroutine called when the submit button of the | ||
| 172 : | .pg question is pressed. | ||
| 173 : | gage | 5594 | |
| 174 : | gage | 5619 | returnFieldName |
| 175 : | |||
| 176 : | |||
| 177 : | gage | 5578 | |
| 178 : | gage | 5594 | |
| 179 : | gage | 5574 | |
| 180 : | gage | 5583 | =cut |
| 181 : | |||
| 182 : | gage | 5574 | |
| 183 : | |||
| 184 : | |||
| 185 : | sub new { | ||
| 186 : | my $class = shift; | ||
| 187 : | my $self = { | ||
| 188 : | appletName =>'', | ||
| 189 : | gage | 5619 | code=>'', |
| 190 : | gage | 5574 | codebase=>'', |
| 191 : | gage | 5619 | # appletId =>'', #always use identical applet Id's and applet Names |
| 192 : | gage | 5574 | params =>undef, |
| 193 : | gage | 5619 | width => 550, |
| 194 : | height => 400, | ||
| 195 : | gage | 5661 | base64_state => undef, # this is an state to use for initializing the first occurence of the question. |
| 196 : | base64_config => undef, # this is the initial (and final?) configuration | ||
| 197 : | gage | 5619 | getStateAlias => 'getXML', |
| 198 : | gage | 5625 | setStateAlias => 'setXML', |
| 199 : | gage | 5619 | configAlias => 'config', |
| 200 : | initializeActionAlias => 'setXML', | ||
| 201 : | submitActionAlias => 'getXML', | ||
| 202 : | returnFieldName => 'receivedField', | ||
| 203 : | headerText => DEFAULT_HEADER_TEXT(), | ||
| 204 : | objectText => '', | ||
| 205 : | debug => 0, | ||
| 206 : | gage | 5574 | @_, |
| 207 : | }; | ||
| 208 : | bless $self, $class; | ||
| 209 : | gage | 5661 | $self->state('<xml></xml>'); |
| 210 : | $self->config('<xml></xml>'); | ||
| 211 : | gage | 5574 | return $self; |
| 212 : | } | ||
| 213 : | |||
| 214 : | sub header { | ||
| 215 : | my $self = shift; | ||
| 216 : | if ($_[0] eq "reset") { # $applet->header('reset'); erases default header text. | ||
| 217 : | $self->{headerText}=''; | ||
| 218 : | } else { | ||
| 219 : | $self->{headerText} .= join("",@_); # $applet->header(new_text); concatenates new_text to existing header. | ||
| 220 : | } | ||
| 221 : | $self->{headerText}; | ||
| 222 : | } | ||
| 223 : | sub object { | ||
| 224 : | my $self = shift; | ||
| 225 : | if ($_[0] eq "reset") { | ||
| 226 : | $self->{objectText}=''; | ||
| 227 : | } else { | ||
| 228 : | $self->{objectText} .= join("",@_); | ||
| 229 : | } | ||
| 230 : | $self->{objectText}; | ||
| 231 : | } | ||
| 232 : | sub params { | ||
| 233 : | my $self = shift; | ||
| 234 : | if (ref($_[0]) =~/HASH/) { | ||
| 235 : | $self->{params} = shift; | ||
| 236 : | gage | 5619 | } elsif ( !defined($_[0]) or $_[0] =~ '') { |
| 237 : | gage | 5574 | # do nothing (read) |
| 238 : | } else { | ||
| 239 : | warn "You must enter a reference to a hash for the parameter list"; | ||
| 240 : | } | ||
| 241 : | $self->{params}; | ||
| 242 : | } | ||
| 243 : | |||
| 244 : | sub initializeActionAlias { | ||
| 245 : | my $self = shift; | ||
| 246 : | $self->{initializeActionAlias} = shift ||$self->{initializeActionAlias}; # replace the current contents if non-empty | ||
| 247 : | $self->{initializeActionAlias}; | ||
| 248 : | } | ||
| 249 : | |||
| 250 : | sub submitActionAlias { | ||
| 251 : | my $self = shift; | ||
| 252 : | $self->{submitActionAlias} = shift ||$self->{submitActionAlias}; # replace the current contents if non-empty | ||
| 253 : | $self->{submitActionAlias}; | ||
| 254 : | } | ||
| 255 : | gage | 5619 | sub getStateAlias { |
| 256 : | my $self = shift; | ||
| 257 : | $self->{getStateAlias} = shift ||$self->{getStateAlias}; # replace the current contents if non-empty | ||
| 258 : | $self->{getStateAlias}; | ||
| 259 : | } | ||
| 260 : | |||
| 261 : | sub setStateAlias { | ||
| 262 : | my $self = shift; | ||
| 263 : | $self->{setStateAlias} = shift ||$self->{setStateAlias}; # replace the current contents if non-empty | ||
| 264 : | $self->{setStateAlias}; | ||
| 265 : | } | ||
| 266 : | sub configAlias { | ||
| 267 : | my $self = shift; | ||
| 268 : | $self->{configAlias} = shift ||$self->{configAlias}; # replace the current contents if non-empty | ||
| 269 : | $self->{configAlias}; | ||
| 270 : | } | ||
| 271 : | gage | 5574 | sub returnFieldName { |
| 272 : | my $self = shift; | ||
| 273 : | $self->{returnFieldName} = shift ||$self->{returnFieldName}; # replace the current contents if non-empty | ||
| 274 : | $self->{returnFieldName}; | ||
| 275 : | } | ||
| 276 : | sub codebase { | ||
| 277 : | my $self = shift; | ||
| 278 : | $self->{codebase} = shift ||$self->{codebase}; # replace the current codebase if non-empty | ||
| 279 : | $self->{codebase}; | ||
| 280 : | } | ||
| 281 : | gage | 5619 | sub code { |
| 282 : | my $self = shift; | ||
| 283 : | $self->{code} = shift ||$self->{code}; # replace the current code if non-empty | ||
| 284 : | $self->{code}; | ||
| 285 : | } | ||
| 286 : | sub height { | ||
| 287 : | my $self = shift; | ||
| 288 : | $self->{height} = shift ||$self->{height}; # replace the current height if non-empty | ||
| 289 : | $self->{height}; | ||
| 290 : | } | ||
| 291 : | sub width { | ||
| 292 : | my $self = shift; | ||
| 293 : | $self->{width} = shift ||$self->{width}; # replace the current width if non-empty | ||
| 294 : | $self->{width}; | ||
| 295 : | } | ||
| 296 : | sub archive { | ||
| 297 : | my $self = shift; | ||
| 298 : | $self->{archive} = shift ||$self->{archive}; # replace the current archive if non-empty | ||
| 299 : | $self->{archive}; | ||
| 300 : | } | ||
| 301 : | gage | 5574 | sub appletName { |
| 302 : | my $self = shift; | ||
| 303 : | $self->{appletName} = shift ||$self->{appletName}; # replace the current appletName if non-empty | ||
| 304 : | $self->{appletName}; | ||
| 305 : | } | ||
| 306 : | gage | 5619 | sub debug { |
| 307 : | gage | 5574 | my $self = shift; |
| 308 : | gage | 5619 | my $new_flag = shift; |
| 309 : | $self->{debug} = $new_flag if defined($new_flag); | ||
| 310 : | $self->{debug}; | ||
| 311 : | gage | 5574 | } |
| 312 : | gage | 5619 | sub appletId { |
| 313 : | appletName(@_); | ||
| 314 : | } | ||
| 315 : | sub state { | ||
| 316 : | gage | 5574 | my $self = shift; |
| 317 : | my $str = shift; | ||
| 318 : | gage | 5619 | $self->{base64_state} = encode_base64($str) ||$self->{base64_state}; # replace the current string if non-empty |
| 319 : | $self->{base64_state} =~ s/\n//g; | ||
| 320 : | decode_base64($self->{base64_state}); | ||
| 321 : | gage | 5574 | } |
| 322 : | |||
| 323 : | gage | 5619 | sub base64_state{ |
| 324 : | gage | 5574 | my $self = shift; |
| 325 : | gage | 5619 | $self->{base64_state} = shift ||$self->{base64_state}; # replace the current string if non-empty |
| 326 : | $self->{base64_state}; | ||
| 327 : | gage | 5574 | } |
| 328 : | gage | 5619 | sub config { |
| 329 : | my $self = shift; | ||
| 330 : | my $str = shift; | ||
| 331 : | $self->{base64_config} = encode_base64($str) || $self->{base64_config}; # replace the current string if non-empty | ||
| 332 : | $self->{base64_config} =~ s/\n//g; | ||
| 333 : | decode_base64($self->{base64_config}); | ||
| 334 : | } | ||
| 335 : | sub base64_config { | ||
| 336 : | my $self = shift; | ||
| 337 : | $self->{base64_config} = shift ||$self->{base64_config}; # replace the current string if non-empty | ||
| 338 : | $self->{base64_config} =$self->{base64_config}; | ||
| 339 : | $self->{base64_config}; | ||
| 340 : | } | ||
| 341 : | gage | 5574 | #FIXME |
| 342 : | # need to be able to adjust header material | ||
| 343 : | |||
| 344 : | sub insertHeader { | ||
| 345 : | my $self = shift; | ||
| 346 : | gage | 5622 | my $codebase = $self->codebase; |
| 347 : | my $appletId = $self->appletId; | ||
| 348 : | my $appletName = $self->appletName; | ||
| 349 : | gage | 5619 | my $base64_initialState = $self->base64_state; |
| 350 : | gage | 5622 | my $initializeAction = $self->initializeActionAlias; |
| 351 : | my $submitAction = $self->submitActionAlias; | ||
| 352 : | gage | 5619 | my $setState = $self->setStateAlias; |
| 353 : | my $getState = $self->getStateAlias; | ||
| 354 : | my $config = $self->configAlias; | ||
| 355 : | my $base64_config = $self->base64_config; | ||
| 356 : | my $debugMode = ($self->debug) ? "1": "0"; | ||
| 357 : | gage | 5622 | my $returnFieldName = $self->{returnFieldName}; |
| 358 : | # my $encodeStateQ = ($self->debug)?'' : "state = Base64.encode(state);"; # in debug mode base64 encoding is not used. | ||
| 359 : | # my $decodeStateQ = "if (!state.match(/<XML>*/i) ) {state = Base64.decode(state)}"; # decode if <XML> is not present | ||
| 360 : | my $headerText = $self->header(); | ||
| 361 : | |||
| 362 : | gage | 5574 | $headerText =~ s/(\$\w+)/$1/gee; # interpolate variables p17 of Cookbook |
| 363 : | |||
| 364 : | return $headerText; | ||
| 365 : | |||
| 366 : | |||
| 367 : | } | ||
| 368 : | |||
| 369 : | sub insertObject { | ||
| 370 : | gage | 5619 | my $self = shift; |
| 371 : | my $code = $self->{code}; | ||
| 372 : | my $codebase = $self->{codebase}; | ||
| 373 : | my $appletId = $self->{appletName}; | ||
| 374 : | gage | 5574 | my $appletName = $self->{appletName}; |
| 375 : | gage | 5619 | my $archive = $self->{archive}; |
| 376 : | my $width = $self->{width}; | ||
| 377 : | my $height = $self->{height}; | ||
| 378 : | gage | 5624 | my $javaParameters = ''; |
| 379 : | my $flashParameters = ''; | ||
| 380 : | gage | 5619 | my %param_hash = %{$self->params()}; |
| 381 : | foreach my $key (keys %param_hash) { | ||
| 382 : | gage | 5624 | $javaParameters .= qq!<param name ="$key" value = "$param_hash{$key}">\n!; |
| 383 : | $flashParameters .= uri_escape($key).'='.uri_escape($param_hash{$key}).'&'; | ||
| 384 : | gage | 5619 | } |
| 385 : | gage | 5624 | $flashParameters =~ s/\&$//; # trim last & |
| 386 : | gage | 5619 | |
| 387 : | gage | 5624 | |
| 388 : | gage | 5574 | $objectText = $self->{objectText}; |
| 389 : | $objectText =~ s/(\$\w+)/$1/gee; | ||
| 390 : | return $objectText; | ||
| 391 : | } | ||
| 392 : | sub initialize { | ||
| 393 : | my $self = shift; | ||
| 394 : | return q{ | ||
| 395 : | <script> | ||
| 396 : | gage | 5619 | initializeAction(); |
| 397 : | gage | 5574 | // this should really be done in the <body> tag |
| 398 : | </script> | ||
| 399 : | }; | ||
| 400 : | |||
| 401 : | } | ||
| 402 : | gage | 5661 | ######################################################## |
| 403 : | # HEADER material for one flash or java applet | ||
| 404 : | ######################################################## | ||
| 405 : | gage | 5574 | |
| 406 : | gage | 5619 | use constant DEFAULT_HEADER_TEXT =><<'END_HEADER_SCRIPT'; |
| 407 : | |||
| 408 : | <script language="JavaScript"> | ||
| 409 : | gage | 5661 | |
| 410 : | gage | 5662 | // set debug mode for this applet |
| 411 : | set_debug($debugMode); | ||
| 412 : | |||
| 413 : | gage | 5661 | ////////////////////////////////////////////////////////// |
| 414 : | gage | 5619 | //CONFIGURATIONS |
| 415 : | // | ||
| 416 : | // configurations are "permanent" | ||
| 417 : | gage | 5661 | ////////////////////////////////////////////////////////// |
| 418 : | |||
| 419 : | gage | 5619 | applet_config_list["$appletName"] = function() { |
| 420 : | gage | 5667 | debug_add("applet_config_list:\n attempt to configure $appletName . $config ( $base64_config ) if config function is defined: " |
| 421 : | gage | 5661 | ); |
| 422 : | gage | 5619 | try { |
| 423 : | gage | 5661 | if (( typeof(getApplet("$appletName").$config) == "function" ) ) { |
| 424 : | gage | 5667 | debug_add("CONFIGURE $appletName"); |
| 425 : | gage | 5619 | getApplet("$appletName").$config(Base64.decode("$base64_config")); |
| 426 : | } | ||
| 427 : | } catch(e) { | ||
| 428 : | gage | 5661 | alert("Error executing configuration command $config for $appletName: " + e ); |
| 429 : | gage | 5619 | } |
| 430 : | } | ||
| 431 : | gage | 5661 | //////////////////////////////////////////////////////////// |
| 432 : | gage | 5619 | // |
| 433 : | gage | 5661 | //STATE: |
| 434 : | // state can vary as the applet is manipulated -- it is reset from the questions _state values | ||
| 435 : | gage | 5619 | // |
| 436 : | gage | 5661 | ////////////////////////////////////////////////////////// |
| 437 : | |||
| 438 : | applet_setState_list["$appletName"] = function(state) { | ||
| 439 : | gage | 5667 | debug_add("Begin setState for applet $appletName"); |
| 440 : | debug_add("Obtain state from $appletName"+"_state"); | ||
| 441 : | gage | 5661 | state = state || getQE("$appletName"+"_state").value; |
| 442 : | if ( base64Q(state) ) { | ||
| 443 : | state=Base64.decode(state); | ||
| 444 : | } | ||
| 445 : | if (state.match(/<xml/i) || state.match(/<?xml/i) ) { // if state starts with <?xml | ||
| 446 : | |||
| 447 : | debug_add("applet_setState_list: \n set (decoded) state for $appletName to " + | ||
| 448 : | state +"\nfunction type is " +typeof(getApplet("$appletName").$setState) | ||
| 449 : | ); | ||
| 450 : | try { | ||
| 451 : | if (( typeof(getApplet("$appletName").$setState) =="function" ) ) { | ||
| 452 : | debug_add("setState for $appletName"); | ||
| 453 : | getApplet("$appletName").$setState( state ); | ||
| 454 : | } | ||
| 455 : | } catch(e) { | ||
| 456 : | alert("Error in setting state of $appletName using command $setState : " + e ); | ||
| 457 : | } | ||
| 458 : | } else if (debug) { | ||
| 459 : | alert("new state was empty string or did not begin with <xml-- state was not reset"); | ||
| 460 : | } | ||
| 461 : | gage | 5619 | }; |
| 462 : | applet_getState_list["$appletName"] = function () { | ||
| 463 : | gage | 5667 | debug_add("get current state for applet $appletName and store it in $appletName"+"_state"); |
| 464 : | gage | 5661 | var applet = getApplet("$appletName"); |
| 465 : | try { | ||
| 466 : | if (( typeof(applet.$getState) == "function" ) ) { // there may be no state function | ||
| 467 : | state = applet.$getState(); // get state in xml format | ||
| 468 : | } | ||
| 469 : | gage | 5667 | |
| 470 : | gage | 5661 | if (!debug) {state = Base64.encode(state) }; // replace state by encoded version unless in debug mode |
| 471 : | gage | 5667 | debug_add("state is "+state); // this should still be in plain text |
| 472 : | getQE("$appletName"+"_state").value = state; //place state in input item (debug: textarea, otherwise: hidden) | ||
| 473 : | gage | 5661 | } catch (e) { |
| 474 : | alert("Error in getting state for $appletName " + e ); | ||
| 475 : | } | ||
| 476 : | gage | 5619 | }; |
| 477 : | gage | 5661 | |
| 478 : | //////////////////////////////////////////////////////////// | ||
| 479 : | gage | 5619 | // |
| 480 : | //INITIALIZE | ||
| 481 : | // | ||
| 482 : | gage | 5661 | //////////////////////////////////////////////////////////// |
| 483 : | |||
| 484 : | |||
| 485 : | applet_checkLoaded_list["$appletName"] = function() { // this function returns 0 unless: | ||
| 486 : | // applet has already been flagged as ready in applet_isReady_list | ||
| 487 : | // applet.config is defined (or alias for .config) | ||
| 488 : | // applet.setState is defined | ||
| 489 : | // applet.isActive is defined | ||
| 490 : | // applet reported that it is loaded by calling loadQ() | ||
| 491 : | var ready = 0; | ||
| 492 : | var applet = getApplet("$appletName"); | ||
| 493 : | if (!debug && applet_isReady_list["$appletName"]) {return(1)}; // memorize readiness in non-debug mode | ||
| 494 : | if ( typeof(applet.$config) == "function") { | ||
| 495 : | debug_add( "applet.config is " + typeof(applet.$config) ); | ||
| 496 : | ready = 1; | ||
| 497 : | } | ||
| 498 : | if( typeof(applet.$getState) == "function") { | ||
| 499 : | debug_add( "applet.getState is " + typeof(applet.$getState) ); | ||
| 500 : | ready =1; | ||
| 501 : | } | ||
| 502 : | if (typeof(applet.isActive) == "function" && applet.isActive ) { | ||
| 503 : | debug_add( "applet.isActive is " + typeof(applet.isActive) ); | ||
| 504 : | ready =1; | ||
| 505 : | } | ||
| 506 : | if (typeof(applet_reportsLoaded_list["$appletName"]) !="undefined" && applet_reportsLoaded_list["$appletName"] != 0 ) { | ||
| 507 : | debug_add( "applet reports that it is loaded " + applet_reportsLoaded_list["$appletName"] ); | ||
| 508 : | ready =1; | ||
| 509 : | } | ||
| 510 : | gage | 5667 | applet_isReady_list["$appletName"]= ready; |
| 511 : | gage | 5661 | return(ready); |
| 512 : | } | ||
| 513 : | |||
| 514 : | applet_initializeAction_list["$appletName"] = function (state) { | ||
| 515 : | applet_setState_list["$appletName"](state); | ||
| 516 : | gage | 5619 | }; |
| 517 : | |||
| 518 : | applet_submitAction_list["$appletName"] = function () { | ||
| 519 : | gage | 5667 | if (! applet_isReady_list["$appletName"] ) { |
| 520 : | alert("$appletName is not ready"); | ||
| 521 : | } | ||
| 522 : | gage | 5619 | applet_getState_list["$appletName"](); |
| 523 : | gage | 5667 | //getQE("$returnFieldName").value = getApplet("$appletName").sendData(); //FIXME -- not needed in general? |
| 524 : | gage | 5619 | }; |
| 525 : | </script> | ||
| 526 : | |||
| 527 : | END_HEADER_SCRIPT | ||
| 528 : | |||
| 529 : | package FlashApplet; | ||
| 530 : | @ISA = qw(Applet); | ||
| 531 : | |||
| 532 : | |||
| 533 : | |||
| 534 : | =pod | ||
| 535 : | |||
| 536 : | The secret to making this applet work with IE in addition to normal browsers | ||
| 537 : | is the addition of the C(<form></form>) construct just before the object. | ||
| 538 : | |||
| 539 : | For some reason IE has trouble locating a flash object which is contained | ||
| 540 : | within a form. Adding this second blank form with the larger problemMainForm | ||
| 541 : | seems to solve the problem. | ||
| 542 : | |||
| 543 : | This follows method2 of the advice given in url(http://kb.adobe.com/selfservice/viewContent.do?externalId=kb400730&sliceId=2) | ||
| 544 : | Method1 and methods involving SWFObject(Geoff Stearns) and SWFFormFix (Steve Kamerman) have yet to be fully investigated: | ||
| 545 : | http://devel.teratechnologies.net/swfformfix/swfobject_swfformfix_source.js | ||
| 546 : | http://www.teratechnologies.net/stevekamerman/index.php?m=01&y=07&entry=entry070101-033933 | ||
| 547 : | |||
| 548 : | use constant DEFAULT_OBJECT_TEXT =><<'END_OBJECT_TEXT'; | ||
| 549 : | <form></form> | ||
| 550 : | <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" | ||
| 551 : | id="$appletName" width="500" height="375" | ||
| 552 : | codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab"> | ||
| 553 : | <param name="movie" value="$codebase/$appletName.swf" /> | ||
| 554 : | <param name="quality" value="high" /> | ||
| 555 : | <param name="bgcolor" value="#869ca7" /> | ||
| 556 : | <param name="allowScriptAccess" value="sameDomain" /> | ||
| 557 : | <embed src="$codebase/$appletName.swf" quality="high" bgcolor="#869ca7" | ||
| 558 : | width="$width" height="$height" name="$appletName" align="middle" id="$appletName" | ||
| 559 : | play="true" loop="false" quality="high" allowScriptAccess="sameDomain" | ||
| 560 : | type="application/x-shockwave-flash" | ||
| 561 : | pluginspage="http://www.macromedia.com/go/getflashplayer"> | ||
| 562 : | </embed> | ||
| 563 : | |||
| 564 : | </object> | ||
| 565 : | END_OBJECT_TEXT | ||
| 566 : | |||
| 567 : | |||
| 568 : | =cut | ||
| 569 : | |||
| 570 : | use constant DEFAULT_OBJECT_TEXT =><<'END_OBJECT_TEXT'; | ||
| 571 : | <form></form> | ||
| 572 : | <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" | ||
| 573 : | id="$appletName" width="500" height="375" | ||
| 574 : | codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab"> | ||
| 575 : | <param name="movie" value="$codebase/$appletName.swf" /> | ||
| 576 : | <param name="quality" value="high" /> | ||
| 577 : | <param name="bgcolor" value="#869ca7" /> | ||
| 578 : | <param name="allowScriptAccess" value="sameDomain" /> | ||
| 579 : | gage | 5624 | <param name="FlashVars" value="$flashParameters"/> |
| 580 : | gage | 5619 | <embed src="$codebase/$appletName.swf" quality="high" bgcolor="#869ca7" |
| 581 : | width="$width" height="$height" name="$appletName" align="middle" id="$appletName" | ||
| 582 : | play="true" loop="false" quality="high" allowScriptAccess="sameDomain" | ||
| 583 : | type="application/x-shockwave-flash" | ||
| 584 : | gage | 5624 | pluginspage="http://www.macromedia.com/go/getflashplayer" |
| 585 : | FlashVars="$flashParameters"> | ||
| 586 : | gage | 5619 | </embed> |
| 587 : | |||
| 588 : | </object> | ||
| 589 : | END_OBJECT_TEXT | ||
| 590 : | |||
| 591 : | sub new { | ||
| 592 : | my $class = shift; | ||
| 593 : | $class -> SUPER::new( objectText => DEFAULT_OBJECT_TEXT(), | ||
| 594 : | @_ | ||
| 595 : | ); | ||
| 596 : | |||
| 597 : | } | ||
| 598 : | |||
| 599 : | |||
| 600 : | package JavaApplet; | ||
| 601 : | @ISA = qw(Applet); | ||
| 602 : | |||
| 603 : | |||
| 604 : | |||
| 605 : | =pod | ||
| 606 : | |||
| 607 : | The secret to making this applet work with IE in addition to normal browsers | ||
| 608 : | is the addition of the C(<form></form>) construct just before the object. | ||
| 609 : | |||
| 610 : | For some reason IE has trouble locating a flash object which is contained | ||
| 611 : | within a form. Adding this second blank form with the larger problemMainForm | ||
| 612 : | seems to solve the problem. | ||
| 613 : | |||
| 614 : | This follows method2 of the advice given in url(http://kb.adobe.com/selfservice/viewContent.do?externalId=kb400730&sliceId=2) | ||
| 615 : | Method1 and methods involving SWFObject(Geoff Stearns) and SWFFormFix (Steve Kamerman) have yet to be fully investigated: | ||
| 616 : | http://devel.teratechnologies.net/swfformfix/swfobject_swfformfix_source.js | ||
| 617 : | http://www.teratechnologies.net/stevekamerman/index.php?m=01&y=07&entry=entry070101-033933 | ||
| 618 : | |||
| 619 : | use constant DEFAULT_OBJECT_TEXT =><<'END_OBJECT_TEXT'; | ||
| 620 : | <form></form> | ||
| 621 : | <applet | ||
| 622 : | code = "$code" | ||
| 623 : | codebase = "$codebase" | ||
| 624 : | archive = "$archive" | ||
| 625 : | name = "$appletName" | ||
| 626 : | id = "$appletName" | ||
| 627 : | width = "$width" | ||
| 628 : | height = "$height" | ||
| 629 : | MAYSCRIPT | ||
| 630 : | > | ||
| 631 : | gage | 5624 | $javaParameters |
| 632 : | gage | 5619 | </applet> |
| 633 : | END_OBJECT_TEXT | ||
| 634 : | |||
| 635 : | =cut | ||
| 636 : | |||
| 637 : | use constant DEFAULT_OBJECT_TEXT =><<'END_OBJECT_TEXT'; | ||
| 638 : | <form></form> | ||
| 639 : | <applet | ||
| 640 : | code = "$code" | ||
| 641 : | codebase = "$codebase" | ||
| 642 : | archive = "$archive" | ||
| 643 : | name = "$appletName" | ||
| 644 : | id = "$appletName" | ||
| 645 : | width = "$width" | ||
| 646 : | height = "$height" | ||
| 647 : | MAYSCRIPT | ||
| 648 : | > | ||
| 649 : | gage | 5624 | $javaParameters |
| 650 : | gage | 5667 | |
| 651 : | Sorry, the Applet could not be started. Please make sure that | ||
| 652 : | Java 1.4.2 (or later) is installed and activated. | ||
| 653 : | (<a href="http://java.sun.com/getjava">click here to install Java now</a>) | ||
| 654 : | gage | 5619 | </applet> |
| 655 : | END_OBJECT_TEXT | ||
| 656 : | |||
| 657 : | sub new { | ||
| 658 : | my $class = shift; | ||
| 659 : | $class -> SUPER::new( objectText => DEFAULT_OBJECT_TEXT(), | ||
| 660 : | @_ | ||
| 661 : | ); | ||
| 662 : | |||
| 663 : | } | ||
| 664 : | |||
| 665 : | |||
| 666 : | |||
| 667 : | gage | 5574 | 1; |
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |