--- loncom/homework/chemresponse.pm 2006/03/09 01:12:05 1.64 +++ loncom/homework/chemresponse.pm 2015/03/07 23:04:08 1.95 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # chemical equation style response # -# $Id: chemresponse.pm,v 1.64 2006/03/09 01:12:05 albertel Exp $ +# $Id: chemresponse.pm,v 1.95 2015/03/07 23:04:08 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -31,6 +31,9 @@ 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')); @@ -65,32 +68,151 @@ sub chem_standard_order { sub separate_jme_window { 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 'mozilla') { + if ($env{'browser.version'} < 4) { + $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=<'; } + 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"); +} + + - my $body=< - -Molecule Editor +CHEMJS + + $viewportjs = &Apache::loncommon::viewport_geometry_js(); + $viewportjs = ''; + + } else { + $buttonstyle = 'display:block'; + $js =< function submitSmiles() { jmeFile = document.applets.JME.jmeFile(); @@ -107,15 +229,42 @@ function openHelpWindow() { } 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".' - + +'; + if ($usejsme) { + $body.= <<"ENDCHEM"; + + +JSME Molecular Editor courtesy of Peter Ertl (Novartis) and Bruno Bienfait + +ENDCHEM + } else { + $body.=< - Select substituent + $lt{'seltext'} -C(=O)OH -C(=O)OMe -OC(=O)Me @@ -133,44 +282,69 @@ function substituent(r) {document.applet -You have to enable Java and JavaScript on your machine. +$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 + - -