If editable divs are going to go anywhere for chemists, you have to find a
user friendly way to include structure drawing. I've been using Resolver
Images - a very, very clunky process. There has to be a better way. Here ya
go...

Code edited for conciseness:

localStorage.setItem("myKey",
getElementById('drawFrame').contentWindow.jsmeApplet.jmeFile());

The above save of JMEfile to LS code can be fired from your draw page. Mine
is in an iFrame on the same page as the editable div, but Local Storage is
by domain, so it could be one page (or tab) talking to another (Think about
that concept!) - e.g. draw app page to editable div app page.

The function below, inserts an iFrame at the cursor in an editable div. It
can be fired by a dialog that asks for a LS key (myKey in this note).
What's being inserted is an iFrame containing Peter Ertl's simplest htm
page set to depict and with a bit of JS that extracts myKey from a query
string. Note that I really don't need the jmefile below, but I get it to
test myKey validity.

function strIframe(myKey) {
var jmefile = localStorage.getItem(myKey);
if (jmefile == null || jmefile == "") {  return null;  }
var ifr = '<iframe name="drawFrame" src="JSME2.htm?lsJSME=myKey"
scrolling="yes"
style="width:220px;height:220px;border:0;padding:0;margin:auto"></iframe>';
document.execCommand("insertHTML",false,ifr);
        return null;
}

Query String Extraction of myKey in Peter's page. The variable
startingStructure
is, if I recall, the term that Peter included in his original code for this
page. Here the JME file is extracted and rendered in the iFrame "image" -
i.e. Peter's page set to depict.

var srch = document.location.search;
var qsVal = "";
var startingStructure = "";
if (srch.indexOf("lsJSME=") >= 0) {
qsVal = srch.split("lsJSME=")[1].split("&")[0];
startingStructure = localStorage.getItem(qsVal);
}

No AJAX. No remote server. It can all be run locally. JSME structures and
reactions are depicted.

Otis

-- 
Otis Rothenberger
o...@chemagic.com
------------------------------------------------------------------------------
Slashdot TV.  Video for Nerds.  Stuff that Matters.
http://pubads.g.doubleclick.net/gampad/clk?id=160591471&iu=/4140/ostg.clktrk
_______________________________________________
Jmol-users mailing list
Jmol-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-users

Reply via email to