///////////////////////////////////////// // Functions to keep after refactoring // ///////////////////////////////////////// var syncKetcherLock = 0; var ignoreKetcherUpdates = 0 var ignoreTextFieldUpdates = 0 // The SMILES generated by Ketcher might look different than the one inserted // however we need this for internal comparison to check whether the SMILES taken // from the TextInput generates the same smiles. var SMILES = ""; function syncTextInputToKetcher(textInputId, ketcherId) { var ketcher = getKetcher(ketcherId); var textInputSMILES = $('#' + textInputId).val(); data = { "struct": textInputSMILES, "output_format": "chemical/x-mdl-molfile", "options": { "smart-layout": true, "ignore-stereochemistry-errors": true, "mass-skip-error-on-pseudoatoms": false, "gross-formula-add-rsites": true } } ketcher.server.layout(data).then( function(response) { if(response.struct != '') { console.log("Writing " + textInputSMILES + " to Ketcher"); ketcher.setMolecule(textInputSMILES); // Wait for ketcher to accept the change and set global SMILES setTimeout(function() { SMILES = ketcher.getSmiles(); }, 250); } } ).catch( function(res) { console.log("Promise failed" + res); } ); } function syncKetcherToTextInput(ketcherId, textInputId) { // Obtain values var ketcher = getKetcher(ketcherId); // Get the SMILES of the molecule currently drawn in Ketcher var tempKetcherSMILES; try { tempKetcherSMILES = ketcher.getSmiles(); } catch(err) { console.log(err); return; } // compare to SMILES from global scope if(SMILES == tempKetcherSMILES) { // There was no change originating from TextInput return } else { SMILES = tempKetcherSMILES; $("#" + textInputId).val(SMILES); } } function syncKetcherAndTextInput(origin, ketcherId, textInputId) { // check if function is "locked" if(origin == 'ketcher') { // Early exit - no op if (ignoreKetcherUpdates == 1) { return; } // Lock updates triggered by textInput ignoreTextFieldUpdates = 1; // Do the sync syncKetcherToTextInput(ketcherId, textInputId); ignoreTextFieldUpdates = 0; } else { // Early exit - no op if(ignoreTextFieldUpdates == 1) { return; } ignoreKetcherUpdates = 1; // Do the sync syncTextInputToKetcher(textInputId, ketcherId); ignoreKetcherUpdates = 0; } } // Returns the ketcher object usually located in an iframe function getKetcher(idToUse){ if (idToUse === undefined) { console.log("getKetcher() called without id!"); idToUse = 'ifKetcher'; } var ketcherFrame = document.getElementById(idToUse); if ('contentDocument' in ketcherFrame) { return ketcherFrame.contentWindow.ketcher; } else { // IE7 return document.frames[idToUse].window.ketcher; } } function enterKeyPressed(event){ // 13 means return/enter if (event.which == 13 || event.keyCode == 13) { return false; } return true }; // Function to attach an RSS feed available at feedUrl and attaches it to attachElement function loadRSSFeed(attachElement, feedUrl) { $.ajax(feedUrl, { accepts:{ xml:"application/rss+xml" }, dataType:"xml", success:function(data) { $(data).find("item").each(function () { var el = $(this); document.getElementById(attachElement).innerHTML += '
" + el.find("description").text() + "
| ' + keys[k] + ' | '; } break; } table += header; table += '
|---|
| ' + result['result'][r][k] + ' | '; } body += '