--- loncom/homework/functionplotresponse.pm 2012/08/16 23:03:01 1.97 +++ loncom/homework/functionplotresponse.pm 2015/04/05 17:09:12 1.110 @@ -1,7 +1,7 @@ # LearningOnline Network with CAPA # Functionplot responses # -# $Id: functionplotresponse.pm,v 1.97 2012/08/16 23:03:01 www Exp $ +# $Id: functionplotresponse.pm,v 1.110 2015/04/05 17:09:12 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -49,9 +49,49 @@ BEGIN { # Return a true value if HTML5 should be used. sub useHTML5 { - return 1; + if ($env{'browser.type'} eq 'chrome') { + if ($env{'browser.version'} >= 14) { + return 1; + } + } elsif ($env{'browser.type'} eq 'safari') { + if ($env{'browser.os'} eq 'mac') { + my ($prefix,$version) = ($env{'browser.version'} =~ /^(\d*)(\d{3})\./); + if ($version >= 536) { + return 1; + } + } + } elsif ($env{'browser.type'} eq 'mozilla') { + if ($env{'browser.info'} =~ /^firefox\-(\d+)/) { + my $firefox = $1; + if ((($env{'browser.os'} eq 'mac') && ($firefox >= 20)) || + (($env{'browser.os'} eq 'unix') && ($firefox >= 17)) || + (($env{'browser.os'} eq 'win') && ($firefox >= 14))) { + return 1; + } + } + } elsif ($env{'browser.type'} eq 'explorer') { + if (($env{'browser.os'} eq 'win') && ($env{'browser.version'} >= 10)) { + return 1; + } + } elsif ($env{'browser.type'} eq 'opera') { + if ($env{'browser.version'} >= 18) { + return 1; + } + } + return 0; } +# +# HTML5 version does not understand "_" in IDs +# +sub appid { + my ($id)=@_; + $id=~s/\_/rid/gs; + $id=~s/\W//gs; + return $id; +} + +# # Routines to start the applet (Java) or the HTML5/JavaScript # # There can be a number of applets on a page, each called ggbApplet_$id, @@ -88,12 +128,13 @@ sub geogebra_default_parameters { sub java_geogebra_startcode { my ($id,$width,$height)=@_; + my $appid=&appid($id); $width=int(1.*$width); $height=int(1.*$height); unless ($width) { $width=700; } unless ($height) { $height=400; } return (< ENDSTARTCODE @@ -111,6 +152,7 @@ sub java_geogebra_code_param { sub html5_geogebra_startcode { my ($id,$width,$height)=@_; + my $appid=&appid($id); $width=int(1.*$width); $height=int(1.*$height); unless ($width) { $width=700; } @@ -118,7 +160,7 @@ sub html5_geogebra_startcode { my $code=&geogebra_internal_program(); return (< ENDSTARTCODE } @@ -136,12 +178,13 @@ sub geogebra_internal_program { # sub java_geogebra_default_parameters { my ($id)=@_; + my $appid=&appid($id); return(< - + @@ -156,7 +199,7 @@ sub java_geogebra_default_parameters { - + ENDDEFAULTPARAMETERS } @@ -171,7 +214,7 @@ sub init_script { if ($#Apache::functionplotresponse::callscripts>=0) { my $script=''; foreach my $id (@Apache::functionplotresponse::callscripts) { - $script.="if (param=='applet_$id') { loaded_$id=true; }\n"; + $script.="if (param=='ggbApplet".&appid($id)."') { loaded_$id=true; }\n"; } $script.="if (".join(' && ',map { "loaded_$_" } (@Apache::functionplotresponse::callscripts)). ") { setTimeout('ggbInitAll()',200) }"; @@ -179,7 +222,7 @@ sub init_script { my $html5init=''; if (&useHTML5()) { $html5init= - ''; + ''; } return (< // 0)) { $return.=(<0)) { $return.=(<8) { $order=8; } $Apache::functionplotresponse::counter++; my $label='CSpline'.$Apache::functionplotresponse::counter; - my $output='document.ggbApplet_'.$id.'.evalCommand("'.$label.'=Spline'.$order.'['; + my $output='document.ggbApplet'.$appid.'.evalCommand("'.$label.'=Spline'.$order.'['; for (my $i=0;$i<=$#points;$i+=4) { $output.="($points[$i],$points[$i+1]),($points[$i+2],$points[$i+3]),"; } $output=~s/\,$//; $output.=']");'."\n"; for (my $i=2; $i<2*$order; $i+=2) { - $output.='document.ggbApplet_'.$id.'.setColor("'.$label.'_'.($i>=10?'{':'').$i.($i>=10?'}':'').'",0,170,0);'."\n"; + $output.='document.ggbApplet'.$appid.'.setColor("'.$label.'_'.($i>=10?'{':'').$i.($i>=10?'}':'').'",0,170,0);'."\n"; } for (my $i=1; $i<2*$order; $i+=2) { - $output.='document.ggbApplet_'.$id.'.setVisible("'.$label.'_'.($i>=10?'{':'').$i.($i>=10?'}':'').'",false);'."\n"; + $output.='document.ggbApplet'.$appid.'.setVisible("'.$label.'_'.($i>=10?'{':'').$i.($i>=10?'}':'').'",false);'."\n"; } return $output; @@ -531,6 +584,7 @@ sub answer_spline_script { sub generate_spline { my ($id,$label,$xmin,$xmax,$ymin,$ymax,$fixed)=@_; + my $appid=&appid($id); my $result=''; my $order=$Apache::functionplotresponse::splineorder{$label}; my $x=$Apache::functionplotresponse::splineinitx{$label}; @@ -547,7 +601,7 @@ sub generate_spline { $x+=$sx/(2.*($order-1)); push(@coords,$label.'S'.$i); } - $result.='document.ggbApplet_'.$id.'.evalCommand("Spline'.$order.'['.join(',',@coords).']");'."\n"; + $result.='document.ggbApplet'.$appid.'.evalCommand("Spline'.$order.'['.join(',',@coords).']");'."\n"; return $result; } @@ -666,6 +720,7 @@ sub start_drawvectorsum { my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; my $result=''; my $internalid = $Apache::inputtags::part.'_'.$Apache::inputtags::response[-1]; + my $internalappid=&appid($internalid); my $tailx=&Apache::lonxml::get_param('tailx',$parstack,$safeeval); my $taily=&Apache::lonxml::get_param('taily',$parstack,$safeeval); my $showvalue=&Apache::lonxml::get_param('showvalue',$parstack,$safeeval); @@ -694,25 +749,25 @@ sub start_drawvectorsum { my $vectorx=$thisvector.'X'; my $vectory=$thisvector.'Y'; $result.=(<'.&mt('Function Plot Question').'' + .''.&Apache::loncommon::insert_folding_button().&mt('Function Plot Question').'' .''.&mt('Delete?').' ' .&Apache::edit::deletelist($target,$token).'   ' .&Apache::edit::insertlist($target,$token).'   ' @@ -1456,7 +1511,7 @@ sub start_functionplotresponse { $env{'form.counter'},$Apache::lonxml::curdepth); &Apache::lonxml::add_script_result( &Apache::loncommon::modal_adhoc_window($function_name,700,500, - '
'.$Apache::functionplotresponse::ruleslog.'
', + '
'.$Apache::functionplotresponse::ruleslog.'
', &mt('Rules Log'))."
"); } return $result; @@ -1989,7 +2044,7 @@ sub start_functionplotruleset { my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; if ($target eq 'edit') { return &Apache::edit::start_table($token). - ''.&mt('Function Plot Rule Set').'' + ''.&Apache::loncommon::insert_folding_button().&mt('Function Plot Rule Set').'' .''.&mt('Delete?').' ' .&Apache::edit::deletelist($target,$token).'   '. &Apache::edit::insertlist($target,$token).'   ' @@ -2182,7 +2237,8 @@ sub start_functionplotelements { if ($target eq 'edit') { return &Apache::edit::start_table($token). - ''.&mt('Function Plot Elements').'' + ''.&Apache::loncommon::insert_folding_button() + .&mt('Function Plot Elements').'' .''.&mt('Delete?').' ' .&Apache::edit::deletelist($target,$token).'   '. &Apache::edit::insertlist($target,$token).'   '