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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6021 - (download) (as text) (annotate)
Tue Mar 10 12:10:36 2009 UTC (10 years, 8 months ago) by gage
File size: 27051 byte(s)
replaced configAlias by setConfigAlias

receivedFieldName replaced by answerBoxName

    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.17 2009/02/19 16:35:26 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      # can be replaced by $applet =FlashApplet() when using AppletObjects.pl
   29      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   $applet->config(qq{<XML>
   41   <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 The module Applet stores common code for the two types of applet.
   81 
   82 =head1 USAGE
   83 
   84 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 
   87 qw(Applet FlashApplet JavaApplet)
   88 
   89 =cut
   90 
   91 
   92 
   93 package Applet;
   94 
   95 use URI::Escape;
   96 
   97 
   98 
   99 use MIME::Base64 qw( encode_base64 decode_base64);
  100 
  101 
  102 =head2 Default javaScript functions placed in header
  103 
  104 =pod
  105 
  106 These functions are automatically defined for use for
  107 any javaScript placed in the text of a PG question.
  108 
  109     getApplet(appletName)  -- finds the applet path in the DOM
  110 
  111     submitAction()            -- calls the submit action of the applets
  112 
  113     initializeWWquestion()    -- calls the initialize action of the applets
  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 
  198 There are three different "images" of the applet.  The first is the java or flash applet itself.  The object that actually does the work.
  199 The second is a perl image of the applet -- henceforth the perlApplet -- which is configured in the .pg file and allows a WeBWorK question
  200 to communicate with the applet.  The third image is a javaScript image of the applet -- henceforth the jsApplet which is a mirror of the perlApplet
  201 but 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
  202 the jsApplet as a runtime version of the perlApplet since it can be accessed and modified after the virtual HTML page has been created by
  203 the PG rendering process.
  204 
  205 The perlApplet is initialized by   $newApplet = new flashApplet( appletName=>'myApplet',..... ); The jsApplet is automatically defined in
  206 ww_applet_list["myApplet"] by copying the instance variables of $newApplet to a corresponding javaScript object.  So  $newApplet->{appletName}
  207 corresponds to ww_applet_list["myApplet"].appletName.  (This paragraph is not yet fully implemented :-().
  208 
  209 Currently 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
  210 to 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 
  216 The 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
  253 
  254 sub new {
  255    my $class = shift;
  256    my $self = {
  257     appletName =>'',
  258     code=>'',
  259     codebase=>'',
  260 #   appletId  =>'',   #always use identical applet Id's and applet Names
  261     params    =>undef,
  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        =>  '',
  272     getConfigAlias     =>  'getConfig',
  273     setConfigAlias     =>  'setConfig',
  274     initializeActionAlias => 'setXML',
  275     submitActionAlias  =>  'getXML',
  276     submitActionScript  =>  '',        # script executed on submitting the WW question
  277     answerBox          =>  'answerBox',
  278     headerText         =>  DEFAULT_HEADER_TEXT(),
  279     objectText         => '',
  280     debug              => 0,
  281     @_,
  282   };
  283   bless $self, $class;
  284   $self->initialState('<xml></xml>');
  285   if ($self->{configAlias}) { # backward compatibility
  286     warn "use setConfigAlias instead of configAlias";
  287     $self->{configAlias}='';
  288   }
  289   $self->config('<xml></xml>');
  290   return $self;
  291 }
  292 
  293 sub  header {
  294   my $self = shift;
  295   if ($_[0] eq "reset") {  # $applet->header('reset');  erases default header text.
  296     $self->{headerText}='';
  297   } else {
  298     $self->{headerText} .= join("",@_);  # $applet->header(new_text); concatenates new_text to existing header.
  299   }
  300     $self->{headerText};
  301 }
  302 sub  object {
  303   my $self = shift;
  304   if ($_[0] eq "reset") {
  305     $self->{objectText}='';
  306   } else {
  307     $self->{objectText} .= join("",@_);
  308   }
  309     $self->{objectText};
  310 }
  311 sub params {
  312   my $self = shift;
  313   if (ref($_[0]) =~/HASH/) {
  314     $self->{params} = shift;
  315   } elsif ( !defined($_[0]) or $_[0] =~ '') {
  316     # do nothing (read)
  317   } else {
  318     warn "You must enter a reference to a hash for the parameter list";
  319   }
  320   $self->{params};
  321 }
  322 
  323 sub initializeActionAlias {
  324   my $self = shift;
  325   $self->{initializeActionAlias} = shift ||$self->{initializeActionAlias}; # replace the current contents if non-empty
  326     $self->{initializeActionAlias};
  327 }
  328 
  329 sub submitActionAlias {
  330   my $self = shift;
  331   $self->{submitActionAlias} = shift ||$self->{submitActionAlias}; # replace the current contents if non-empty
  332     $self->{submitActionAlias};
  333 }
  334 sub submitActionScript {
  335   my $self = shift;
  336   $self->{submitActionScript} = shift ||$self->{submitActionScript}; # replace the current contents if non-empty
  337     $self->{submitActionScript};
  338 }
  339 sub getStateAlias {
  340   my $self = shift;
  341   $self->{getStateAlias} = shift ||$self->{getStateAlias}; # replace the current contents if non-empty
  342     $self->{getStateAlias};
  343 }
  344 
  345 sub setStateAlias {
  346   my $self = shift;
  347   $self->{setStateAlias} = shift ||$self->{setStateAlias}; # replace the current contents if non-empty
  348     $self->{setStateAlias};
  349 }
  350 sub configAlias {
  351   my $self = shift;
  352   $self->{setConfigAlias} = shift ||$self->{setConfigAlias}; # replace the current contents if non-empty
  353     $self->{setConfigAlias};
  354 }
  355 sub setConfigAlias {
  356   my $self = shift;
  357   $self->{setConfigAlias} = shift ||$self->{setConfigAlias}; # replace the current contents if non-empty
  358     $self->{setConfigAlias};
  359 }
  360 sub getConfigAlias {
  361   my $self = shift;
  362   $self->{getConfigAlias} = shift ||$self->{getConfigAlias}; # replace the current contents if non-empty
  363     $self->{getConfigAlias};
  364 }
  365 
  366 sub answerBoxName {
  367   my $self = shift;
  368   $self->{answerBox} = shift ||$self->{answerBox}; # replace the current contents if non-empty
  369     $self->{answerBox};
  370 }
  371 sub codebase {
  372   my $self = shift;
  373   $self->{codebase} = shift ||$self->{codebase}; # replace the current codebase if non-empty
  374     $self->{codebase};
  375 }
  376 sub code {
  377   my $self = shift;
  378   $self->{code} = shift ||$self->{code}; # replace the current code if non-empty
  379     $self->{code};
  380 }
  381 sub height {
  382   my $self = shift;
  383   $self->{height} = shift ||$self->{height}; # replace the current height if non-empty
  384     $self->{height};
  385 }
  386 sub width {
  387   my $self = shift;
  388   $self->{width} = shift ||$self->{width}; # replace the current width if non-empty
  389     $self->{width};
  390 }
  391 sub bgcolor {
  392   my $self = shift;
  393   $self->{bgcolor} = shift ||$self->{bgcolor}; # replace the current background color if non-empty
  394     $self->{bgcolor};
  395 }
  396 sub archive {
  397   my $self = shift;
  398   $self->{archive} = shift ||$self->{archive}; # replace the current archive if non-empty
  399     $self->{archive};
  400 }
  401 sub appletName {
  402   my $self = shift;
  403   $self->{appletName} = shift ||$self->{appletName}; # replace the current appletName if non-empty
  404     $self->{appletName};
  405 }
  406 sub debug {
  407   my $self = shift;
  408   my $new_flag = shift;
  409   $self->{debug} = $new_flag if defined($new_flag);
  410   $self->{debug};
  411 }
  412 sub appletId {
  413   appletName(@_);
  414 }
  415 
  416 sub initialState {
  417   my $self = shift;
  418   my $str = shift;
  419   $self->{initialState} = $str   ||$self->{initialState}; # replace the current string if non-empty
  420     $self->{initialState};
  421 }
  422 
  423 sub config {
  424   my $self = shift;
  425   my $str = shift;
  426   $self->{base64_config} =  encode_base64($str)   || $self->{base64_config}; # replace the current string if non-empty
  427   $self->{base64_config} =~ s/\n//g;
  428     decode_base64($self->{base64_config});
  429 }
  430 #######################
  431 # soon to be deprecated?
  432 #######################
  433 sub state {
  434   my $self = shift;
  435   my $str = shift;
  436   $self->{base64_state} =  encode_base64($str)   ||$self->{base64_state}; # replace the current string if non-empty
  437   $self->{base64_state} =~ s/\n//g;
  438     decode_base64($self->{base64_state});
  439 }
  440 sub base64_state{
  441   my $self = shift;
  442   $self->{base64_state} = shift ||$self->{base64_state}; # replace the current string if non-empty
  443     $self->{base64_state};
  444 }
  445 
  446 sub base64_config {
  447   my $self = shift;
  448   $self->{base64_config} = shift ||$self->{base64_config}; # replace the current string if non-empty
  449   $self->{base64_config} =$self->{base64_config};
  450     $self->{base64_config};
  451 }
  452 
  453 sub returnFieldName {
  454   my $self = shift;
  455     warn "use  answerBoxName  instead of returnFieldName";
  456 }
  457 sub answerBox {
  458   my $self = shift;
  459     warn "use  answerBoxName  instead of AnswerBox";
  460 }
  461 #########################
  462 #FIXME
  463 # need to be able to adjust header material
  464 
  465 sub insertHeader {
  466     my $self = shift;
  467 
  468     my $codebase              =  $self->codebase;
  469     my $appletId              =  $self->appletId;
  470     my $appletName            =  $self->appletName;
  471     my $base64_initialState   = $self->base64_state;
  472     my $initializeAction      =  $self->initializeActionAlias;
  473     my $submitActionAlias     =  $self->submitActionAlias;
  474     my $submitActionScript    = $self->submitActionScript;
  475     my $setStateAlias         =  $self->setStateAlias;
  476     my $getStateAlias         =  $self->getStateAlias;
  477 
  478     my $setConfigAlias        =  $self->setConfigAlias;
  479     my $getConfigAlias        =  $self->getConfigAlias;
  480     my $base64_config         =  $self->base64_config;
  481     my $debugMode             =  ($self->debug) ? "1": "0";
  482     my $returnFieldName       =  $self->{returnFieldName};
  483     my $answerBox             =  $self->{answerBox};
  484     my $headerText            =  $self->header();
  485 
  486 
  487     $submitActionScript =~ s/"/\\"/g;    # escape quotes for ActionScript
  488                                          # other variables should not have quotes.
  489 
  490     $submitActionScript =~ s/\n/ /g;     # replace returns with spaces -- returns in the wrong spot can cause trouble with javaScript
  491     $submitActionScript =~ s/\r/ /g;     # replace returns with spaces -- returns can cause trouble
  492 
  493     $headerText =~ s/(\$\w+)/$1/gee;   # interpolate variables p17 of Cookbook
  494 
  495     return $headerText;
  496 
  497 
  498 }
  499 
  500 sub insertObject {
  501     my $self       = shift;
  502     my $code       = $self->{code};
  503     my $codebase   = $self->{codebase};
  504     my $appletId   = $self->{appletName};
  505     my $appletName = $self->{appletName};
  506     my $archive    = $self->{archive};
  507     my $width      = $self->{width};
  508     my $height     = $self->{height};
  509     my $applet_bgcolor = $self->{bgcolor};
  510     my $javaParameters = '';
  511     my $flashParameters = '';
  512     my %param_hash = %{$self->params()};
  513     foreach my $key (keys %param_hash) {
  514       $javaParameters .= qq!<param name ="$key"  value = "$param_hash{$key}">\n!;
  515       $flashParameters .= uri_escape($key).'='.uri_escape($param_hash{$key}).'&';
  516     }
  517     $flashParameters =~ s/\&$//;    # trim last &
  518 
  519 
  520     $objectText = $self->{objectText};
  521     $objectText =~ s/(\$\w+)/$1/gee;
  522     return $objectText;
  523 }
  524 # sub initialize  {
  525 #     my $self = shift;
  526 #   return q{
  527 #     <script>
  528 #       initializeAllApplets();
  529 #       // this should really be done in the <body> tag
  530 #     </script>
  531 #   };
  532 #
  533 # }
  534 ########################################################
  535 # HEADER material for one flash or java applet
  536 ########################################################
  537 
  538 use constant DEFAULT_HEADER_TEXT =><<'END_HEADER_SCRIPT';
  539     <script src="/webwork2_files/js/Base64.js" language="javascript">
  540     </script>
  541     <script src="/webwork2_files/js/ww_applet_support.js" language="javascript">
  542         //upload functions stored in /opt/webwork/webwork2/htdocs/js ...
  543 
  544      </script>
  545   <script language="JavaScript">
  546 
  547   // set debug mode for this applet
  548     set_debug($debugMode);
  549 
  550     //////////////////////////////////////////////////////////
  551   //TEST code
  552   //
  553     //
  554     //////////////////////////////////////////////////////////
  555 
  556     ww_applet_list["$appletName"] = new ww_applet("$appletName");
  557 
  558 
  559   ww_applet_list["$appletName"].code = "$code";
  560   ww_applet_list["$appletName"].codebase = "$codebase";
  561     ww_applet_list["$appletName"].appletID = "$appletID";
  562   ww_applet_list["$appletName"].base64_state = "$base64_initializationState";
  563   ww_applet_list["$appletName"].base64_config = "$base64_config";
  564   ww_applet_list["$appletName"].getStateAlias = "$getStateAlias";
  565   ww_applet_list["$appletName"].setStateAlias = "$setStateAlias";
  566   ww_applet_list["$appletName"].setConfigAlias   = "$setConfigAlias";
  567   ww_applet_list["$appletName"].getConfigAlias   = "$getConfigAlias";
  568   ww_applet_list["$appletName"].initializeActionAlias = "$initializeAction";
  569   ww_applet_list["$appletName"].submitActionAlias = "$submitActionAlias";
  570   ww_applet_list["$appletName"].submitActionScript = "$submitActionScript";
  571   ww_applet_list["$appletName"].answerBox = "$answerBox";
  572   ww_applet_list["$appletName"].debug = "$debugMode";
  573 
  574     </script>
  575 
  576 END_HEADER_SCRIPT
  577 
  578 package FlashApplet;
  579 @ISA = qw(Applet);
  580 
  581 
  582 =head2 Insertion HTML code for FlashApplet
  583 
  584 =pod
  585 
  586 The secret to making this applet work with IE in addition to normal browsers
  587 is the addition of the C(<form></form>) construct just before the object.
  588 
  589 For some reason IE has trouble locating a flash object which is contained
  590 within a form.  Adding this second blank form with the larger problemMainForm
  591 seems to solve the problem.
  592 
  593 This follows method2 of the advice given in url(http://kb.adobe.com/selfservice/viewContent.do?externalId=kb400730&sliceId=2)
  594 Method1 and methods involving SWFObject(Geoff Stearns) and SWFFormFix (Steve Kamerman) have yet to be fully investigated:
  595 http://devel.teratechnologies.net/swfformfix/swfobject_swfformfix_source.js
  596 http://www.teratechnologies.net/stevekamerman/index.php?m=01&y=07&entry=entry070101-033933
  597 
  598     use constant DEFAULT_OBJECT_TEXT =><<'END_OBJECT_TEXT';
  599       <form></form>
  600       <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
  601            id="$appletName" width="500" height="375"
  602            codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">
  603          <param name="movie" value="$codebase/$appletName.swf" />
  604          <param name="quality" value="high" />
  605          <param name="bgcolor" value="$applet_bgcolor" />
  606          <param name="allowScriptAccess" value="sameDomain" />
  607          <embed src="$codebase/$appletName.swf" quality="high" bgcolor="$applet_bgcolor"
  608            width="$width" height="$height" name="$appletName" align="middle" id="$appletName"
  609            play="true" loop="false" quality="high" allowScriptAccess="sameDomain"
  610            type="application/x-shockwave-flash"
  611            pluginspage="http://www.macromedia.com/go/getflashplayer">
  612          </embed>
  613 
  614        </object>
  615     END_OBJECT_TEXT
  616 
  617 
  618 =cut
  619 
  620 use constant DEFAULT_OBJECT_TEXT =><<'END_OBJECT_TEXT';
  621   <form></form>
  622   <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
  623              id="$appletName" width="500" height="375"
  624              codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">
  625          <param name="movie" value="$codebase/$appletName.swf" />
  626          <param name="quality" value="high" />
  627          <param name="bgcolor" value="$applet_bgcolor" />
  628          <param name="allowScriptAccess" value="sameDomain" />
  629          <param name="FlashVars" value="$flashParameters"/>
  630          <embed src="$codebase/$appletName.swf" quality="high" bgcolor="$applet_bgcolor"
  631              width="$width" height="$height" name="$appletName" align="middle" id="$appletName"
  632              play="true" loop="false" quality="high" allowScriptAccess="sameDomain"
  633              type="application/x-shockwave-flash"
  634              pluginspage="http://www.macromedia.com/go/getflashplayer"
  635              FlashVars="$flashParameters">
  636          </embed>
  637 
  638      </object>
  639 END_OBJECT_TEXT
  640 
  641 sub new {
  642     my $class = shift;
  643   $class -> SUPER::new( objectText   => DEFAULT_OBJECT_TEXT(),
  644                   @_
  645   );
  646 
  647 }
  648 
  649 
  650 package JavaApplet;
  651 @ISA = qw(Applet);
  652 
  653 =head2 Insertion HTML code for JavaApplet
  654 
  655 =pod
  656 
  657 The secret to making this applet work with IE in addition to normal browsers
  658 is the addition of the C(<form></form>) construct just before the object.
  659 
  660 For some reason IE has trouble locating a flash object which is contained
  661 within a form.  Adding this second blank form with the larger problemMainForm
  662 seems to solve the problem.
  663 
  664 This follows method2 of the advice given in url(http://kb.adobe.com/selfservice/viewContent.do?externalId=kb400730&sliceId=2)
  665 Method1 and methods involving SWFObject(Geoff Stearns) and SWFFormFix (Steve Kamerman) have yet to be fully investigated:
  666 http://devel.teratechnologies.net/swfformfix/swfobject_swfformfix_source.js
  667 http://www.teratechnologies.net/stevekamerman/index.php?m=01&y=07&entry=entry070101-033933
  668 
  669     use constant DEFAULT_OBJECT_TEXT =><<'END_OBJECT_TEXT';
  670       <form></form>
  671      <applet
  672       code     = "$code"
  673       codebase = "$codebase"
  674       archive  = "$archive"
  675       name     = "$appletName"
  676       id       = "$appletName"
  677       width    = "$width"
  678       height   = "$height"
  679       MAYSCRIPT
  680      >
  681       $javaParameters
  682      </applet>
  683     END_OBJECT_TEXT
  684 
  685 =cut
  686 
  687 use constant DEFAULT_OBJECT_TEXT =><<'END_OBJECT_TEXT';
  688   <form></form>
  689  <applet
  690   code     = "$code"
  691   codebase = "$codebase"
  692   archive  = "$archive"
  693   name     = "$appletName"
  694     id       = "$appletName"
  695     width    = "$width"
  696     height   = "$height"
  697     bgcolor  = "$applet_bgcolor"
  698     MAYSCRIPT
  699  >
  700   $javaParameters
  701 
  702   Sorry, the Applet could not be started. Please make sure that
  703 Java 1.4.2 (or later) is installed and activated.
  704 (<a href="http://java.sun.com/getjava">click here to install Java now</a>)
  705  </applet>
  706 END_OBJECT_TEXT
  707 
  708 sub new {
  709     my $class = shift;
  710   $class -> SUPER::new( objectText   => DEFAULT_OBJECT_TEXT(),
  711                   @_
  712   );
  713 
  714 }
  715 
  716 
  717 
  718 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9