[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 5583 - (download) (as text) (annotate)
Tue Nov 6 16:47:19 2007 UTC (12 years ago) by gage
File size: 10602 byte(s)
Added some further documentation pointing out the workaround to make
flash objects embedded within forms (as all objects in a PG problem are)
work with IE.

-- Mike

    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.2 2007/11/05 16:45:33 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 =pod
  141 
  142 The secret to making this applet work with IE in addition to normal browsers
  143 is the addition of the C(<form></form>) construct just before the object.
  144 
  145 For some reason IE has trouble locating a flash object which is contained
  146 within a form.  Adding this second blank form with the larger problemMainForm
  147 seems to solve the problem.
  148 
  149 This follows method2 of the advice given in url(http://kb.adobe.com/selfservice/viewContent.do?externalId=kb400730&sliceId=2)
  150 Method1 and methods involving SWFObject(Geoff Stearns) and SWFFormFix (Steve Kamerman) have yet to be fully investigated:
  151 http://devel.teratechnologies.net/swfformfix/swfobject_swfformfix_source.js
  152 http://www.teratechnologies.net/stevekamerman/index.php?m=01&y=07&entry=entry070101-033933
  153 
  154 =cut
  155 
  156 use constant DEFAULT_OBJECT_TEXT =><<'END_OBJECT_TEXT';
  157   <form></form>
  158   <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
  159              id="ExternalInterface" width="500" height="375"
  160              codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">
  161          <param name="movie" value="$codebase/$appletName.swf" />
  162          <param name="quality" value="high" />
  163          <param name="bgcolor" value="#869ca7" />
  164          <param name="allowScriptAccess" value="sameDomain" />
  165          <embed src="$codebase/$appletName.swf" quality="high" bgcolor="#869ca7"
  166              width="550" height="400" name="$appletName" align="middle" id="$appletID"
  167              play="true" loop="false" quality="high" allowScriptAccess="sameDomain"
  168              type="application/x-shockwave-flash"
  169              pluginspage="http://www.macromedia.com/go/getflashplayer">
  170          </embed>
  171 
  172      </object>
  173 END_OBJECT_TEXT
  174 
  175 
  176 sub new {
  177    my $class = shift;
  178    my $self = {
  179     host =>'',
  180     port => '',
  181     path => '',
  182     appletName =>'',
  183     codebase=>'',
  184     appletId  =>'',
  185     params    =>undef,
  186     base64_xmlString => 'foobar',
  187     initializeActionAlias => 'setupProblem',
  188     submitActionAlias  => 'checkAnswer',
  189     returnFieldName    => 'receivedField',
  190     headerText   => DEFAULT_HEADER_TEXT(),
  191     objectText   => DEFAULT_OBJECT_TEXT(),
  192     @_,
  193   };
  194   bless $self, $class;
  195   #$self -> _initialize(@_);
  196   return $self;
  197 }
  198 
  199 sub  header {
  200   my $self = shift;
  201   if ($_[0] eq "reset") {  # $applet->header('reset');  erases default header text.
  202     $self->{headerText}='';
  203   } else {
  204     $self->{headerText} .= join("",@_);  # $applet->header(new_text); concatenates new_text to existing header.
  205   }
  206     $self->{headerText};
  207 }
  208 sub  object {
  209   my $self = shift;
  210   if ($_[0] eq "reset") {
  211     $self->{objectText}='';
  212   } else {
  213     $self->{objectText} .= join("",@_);
  214   }
  215     $self->{objectText};
  216 }
  217 sub params {
  218   my $self = shift;
  219   if (ref($_[0]) =~/HASH/) {
  220     $self->{params} = shift;
  221   } elsif ( $_[0] =~ '') {
  222     # do nothing (read)
  223   } else {
  224     warn "You must enter a reference to a hash for the parameter list";
  225   }
  226   $self->{params};
  227 }
  228 
  229 sub initializeActionAlias {
  230   my $self = shift;
  231   $self->{initializeActionAlias} = shift ||$self->{initializeActionAlias}; # replace the current contents if non-empty
  232     $self->{initializeActionAlias};
  233 }
  234 
  235 sub submitActionAlias {
  236   my $self = shift;
  237   $self->{submitActionAlias} = shift ||$self->{submitActionAlias}; # replace the current contents if non-empty
  238     $self->{submitActionAlias};
  239 }
  240 sub returnFieldName {
  241   my $self = shift;
  242   $self->{returnFieldName} = shift ||$self->{returnFieldName}; # replace the current contents if non-empty
  243     $self->{returnFieldName};
  244 }
  245 sub codebase {
  246   my $self = shift;
  247   $self->{codebase} = shift ||$self->{codebase}; # replace the current codebase if non-empty
  248     $self->{codebase};
  249 }
  250 sub appletName {
  251   my $self = shift;
  252   $self->{appletName} = shift ||$self->{appletName}; # replace the current appletName if non-empty
  253     $self->{appletName};
  254 }
  255 sub appletId {
  256   my $self = shift;
  257   $self->{appletId} = shift ||$self->{appletId}; # replace the current appletName if non-empty
  258     $self->{appletId};
  259 }
  260 sub xmlString {
  261   my $self = shift;
  262   my $str = shift;
  263   $self->{base64_xmlString} =  encode_base64($str)   ||$self->{base64_xmlString}; # replace the current string if non-empty
  264   $self->{base64_xmlString} =~ s/\n//g;
  265     decode_base64($self->{base64_xmlString});
  266 }
  267 
  268 sub base64_xmlString{
  269   my $self = shift;
  270   $self->{base64_xmlString} = shift ||$self->{base64_xmlString}; # replace the current string if non-empty
  271     $self->{base64_xmlString};
  272 }
  273 
  274 #FIXME
  275 # need to be able to adjust header material
  276 
  277 sub insertHeader {
  278     my $self = shift;
  279     my $codebase = $self->{codebase};
  280     my $appletId = $self->{appletId};
  281     my $appletName = $self->{appletName};
  282     my $base64_xmlString = $self->{base64_xmlString};
  283     my $initializeAction = $self->{initializeActionAlias};
  284     my $submitAction = $self->{submitActionAlias};
  285     my $returnFieldName= $self->{returnFieldName};
  286     my $headerText = $self->header();
  287     $headerText =~ s/(\$\w+)/$1/gee;   # interpolate variables p17 of Cookbook
  288 
  289     return $headerText;
  290 
  291 
  292 }
  293 
  294 
  295 # <script language="javascript">
  296 #   if (AC_FL_RunContent == 0) {
  297 #     alert("This page requires AC_RunActiveContent.js.");
  298 #   } else {
  299 #     AC_FL_RunContent(
  300 #       'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
  301 #       'width', '100%',
  302 #       'height', '100%',
  303 #       'src', 'http://$codebase/$appletName',
  304 #       'quality', 'high',
  305 #       'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
  306 #       'align', 'middle',
  307 #       'play', 'true',
  308 #       'loop', 'true',
  309 #       'scale', 'showall',
  310 #       'wmode', 'window',
  311 #       'devicefont', 'false',
  312 #       'id', '$appletId',
  313 #       'bgcolor', '#ffffcc',
  314 #       'name', '$appletName',
  315 #       'menu', 'true',
  316 #       'allowFullScreen', 'false',
  317 #       'allowScriptAccess','sameDomain',
  318 #       'movie', '$appletName',
  319 #       'salign', ''
  320 #       ); //end AC code
  321 #   }
  322 # </script>
  323 sub insertObject {
  324     my $self = shift;
  325     my $codebase = $self->{codebase};
  326     my $appletId = $self->{appletId};
  327     my $appletName = $self->{appletName};
  328     $codebase = findAppletCodebase("$appletName.swf") unless $codebase;
  329     $objectText = $self->{objectText};
  330     $objectText =~ s/(\$\w+)/$1/gee;
  331     return $objectText;
  332 }
  333 
  334 sub initialize  {
  335     my $self = shift;
  336   return q{
  337     <script>
  338       initialize();
  339       // this should really be done in the <body> tag
  340     </script>
  341   };
  342 
  343 }
  344 
  345 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9