--- loncom/homework/chemresponse.pm 2005/05/25 14:33:00 1.52 +++ loncom/homework/chemresponse.pm 2015/03/09 14:57:03 1.96 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # chemical equation style response # -# $Id: chemresponse.pm,v 1.52 2005/05/25 14:33:00 www Exp $ +# $Id: chemresponse.pm,v 1.96 2015/03/09 14:57:03 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -30,6 +30,10 @@ package Apache::chemresponse; use strict; use Apache::lonxml; use Apache::lonnet; +use Apache::lonlocal; +use lib '/home/httpd/lib/perl/'; +use LONCAPA; + BEGIN { &Apache::lonxml::register('Apache::chemresponse',('organicresponse','organicstructure','reactionresponse','chem')); @@ -63,27 +67,171 @@ sub chem_standard_order { } sub separate_jme_window { - my ($smile_input,$jme_input,$molecule,$options)=@_; + my ($smile_input,$jme_input,$molecule,$options,$shown_text)=@_; + my $usejsme = 1; + if (($env{'request.course.id'}) && ($env{'request.state'} ne 'construct')) { + if (exists($env{'course.'.$env{'request.course.id'}.'.usejsme'})) { + if ($env{'course.'.$env{'request.course.id'}.'.usejsme'} eq '0') { + $usejsme = 0; + } + } else { + my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'}); + if ($domdefs{'usejsme'} eq '0') { + $usejsme = 0; + } + } + } else { + my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'}); + if ($domdefs{'usejsme'} eq '0') { + $usejsme = 0; + } + } + if ($usejsme) { + if ($env{'browser.type'} eq 'safari') { + unless ($env{'browser.mobile'}) { + if ($env{'browser.version'} < 522) { + $usejsme = 0; + } + } + } elsif ($env{'browser.type'} eq 'mozilla') { + if ($env{'browser.version'} < 5) { + $usejsme = 0; + } elsif ($env{'browser.info'} =~ /^firefox\-([\d\.]+)/) { + my $firefox = $1; + if ($firefox < 12) { + $usejsme = 0; + } + } + } elsif ($env{'browser.type'} eq 'explorer') { + if ($env{'browser.version'} < 7) { + $usejsme = 0; + } + } elsif ($env{'browser.type'} eq 'opera') { + if ($env{'browser.version'} < 15) { + $usejsme = 0; + } + } + } else { + if ($env{'browser.mobile'}) { + $usejsme = 1; + } + } + my $linkstyle = 'display:none'; + my $creditstyle = 'display:inline'; + if ($env{'browser.type'} eq 'explorer') { + if (($env{'browser.os'} eq 'win') && ($env{'browser.version'} < 9)) { + $linkstyle = 'display:inline'; + $creditstyle = 'display:none'; + } + } my $smilesection; if (defined($smile_input)) { + my $smiles; + if ($usejsme) { + $smiles = 'document.JME.smiles()'; + } else { + $smiles = 'document.applets.JME.smiles()'; + } $smilesection=<'; } - my $body=< - -Molecule Editor + if ($molecule) { + if ($usejsme) { + $molecule = 'document.JME.readMolecule("'.$molecule.'")'; + } else { + $molecule=''; + } + } + my $insert_answer; + if ($shown_text eq '') { + $insert_answer= + ''; + } + + + + my ($jsme_js,$js,$buttonstyle,$viewportjs,$resizejs); + if ($usejsme) { + $buttonstyle = 'display:none'; + $resizejs =< +function callResize() { + var timer; + clearTimeout(timer); + timer=setTimeout('resize_jsme()',100); +} + +window.onresize = callResize; + +function resize_jsme() { + init_geometry(); + var vph = Geometry.getViewportHeight(); + var vpw = Geometry.getViewportWidth(); + var lowerdivheight = document.getElementById('JMEbuttons').offsetHeight; + var formheight = document.getElementById('JMEform').offsetHeight; + var freevspace = vph-(lowerdivheight+50); + var freehspace = vpw-20; + if (typeof jsmeApplet !== 'undefined') { + jsmeApplet.setSize(freehspace,freevspace); + } +} + +RESIZEJS + $resizejs = &Apache::loncommon::js_ready($resizejs); + $jsme_js = ' +'."\n"; + $js =< +function jsmeOnLoad() { + document.getElementById('JMErefresh').style.display="none"; + document.getElementById('JMEcredits').style.display="inline"; + jsmeApplet = new JSApplet.JSME("jme", "420px", "330px"); + document.JME = jsmeApplet; + $molecule; + document.getElementById('JMEbuttons').style.display="block"; + callResize(); +} + +function submitSmiles() { + jmeFile = document.JME.jmeFile(); + if (jmeFile == "") { + alert("Nothing to submit"); + } else { + $jmesection + $smilesection + window.close(); + } +} +function openHelpWindow() { + window.open("http://peter-ertl.com/jsme/2013_03/help.html","","scrollbars=yes,resizable=yes,width=500,height=600"); +} + + + +CHEMJS + + $viewportjs = &Apache::loncommon::viewport_geometry_js(); + $viewportjs = ''; + + } else { + $buttonstyle = 'display:block'; + $js =< function submitSmiles() { jmeFile = document.applets.JME.jmeFile(); @@ -98,33 +246,124 @@ function submitSmiles() { function openHelpWindow() { window.open("/adm/jme/jme_help.html","","scrollbars=yes,resizable=yes,width=500,height=600"); } +function substituent(r) {document.applets.JME.setSubstituent(r);} - - +CHEMJS + } + + my $start_page = + &Apache::loncommon::start_page('Molecule Editor',$viewportjs, + {'only_body' => 1, + 'js_ready' => 1, + 'bgcolor' => '#FFFFFF',}); + my $end_page = + &Apache::loncommon::end_page({'js_ready' => 1,}); + my $java_not_enabled=&Apache::lonhtmlcommon::java_not_enabled(); + my %lt = &Apache::lonlocal::texthash( + 'seltext' => 'Select substituent...', + 'close' => 'Close', + 'help' => 'Help', + ); + my $body = " +$jsme_js +$js".' - -You have to enable Java and JavaScript on your machine. + +'; + if ($usejsme) { + $body.= <<"ENDCHEM"; + + +JSME Molecular Editor courtesy of Peter Ertl (Novartis) and Bruno Bienfait + +ENDCHEM + } else { + $body.=< + + + + $lt{'seltext'} + -C(=O)OH + -C(=O)OMe + -OC(=O)Me + -CMe3 + -CF3 + -CCl3 + -NO2 + -SO2-NH2 + -NH-SO2-Me + -NMe2 + -C#N + -C#C-Me + -C#CH + + + + +$java_not_enabled $molecule - -JME Editor courtesy of Peter Ertl, Novartis - - + - +JME Editor courtesy of Peter Ertl, Novartis +CHEMPAGE + } + $body .= < +$insert_answer + - + + + +Display Molecule Editor + - -