User 870ab5b546
12-01-2015 15:07:13
When I load the resource
<script src="../nosession/marvinJS/js/util.js" type="text/javascript"></script>
*and* setMarvinJS() in the following code is called with eschewJQuery set to true, then only the default toolbar loads, even though I request the reporting toolbar. Also, the molecule mol is not loaded into the sketcher. So it appears that there may be a conflict between util.js and MarvinJSUtil.getEditor(). ??
var marvinSketcherInstance;
var NO_MJS_SETTINGS = -1;
// Creates and initiates the MarvinJS drawing object.
function startMarvinJS(mol, qTypeRaw, qFlags, appletName) {
var qTypeNeg = qTypeRaw < 0;
var qType = Math.abs(qTypeRaw);
var isMechanism = qType === MECHANISM;
var isSynthesis = qType === SYNTHESIS;
var panelWidth = 450;
var panelHeight = (['responseApplet', 'synthAuthApplet',
'hybridMarvin', 'pKaMarvin', 'targetapplet', 'queryapplet',
'evalApplet'].contains(appletName) ? 400 : 350);
panelHeight = 400;
if (((isMechanism || isSynthesis) && !qTypeNeg) ||
(!isMechanism && !isSynthesis && qTypeNeg)) {
panelWidth = 500;
panelHeight = (appletName === 'responseApplet' ? 530 : 500);
} // how big to make canvas
// use of editorws.html in following line makes it possible to use
// JChem Web Services
var bld = new String.builder().
append('<iframe id="').append(appletName).
append('" class="sketcher-frame" ' +
'src="\/nosession\/marvinJS\/editorws.html" ');
if (is3D(qFlags)) {
bld.append('data-templateurl="templates\/3DTemplates.mrv" ');
} // if is3D
bld.append('style="min-width:').append(panelWidth).
append('px; min-height:').append(panelHeight).
append('px; overflow:hidden; border:1px solid darkgray;" \/><\/iframe>');
var iframe = bld.toString();
setInnerHTML(appletName + 'Cell', iframe);
setMarvinJS(mol, appletName, qFlags, true);
} // startMarvinJS()
// Gets the editor object when it is ready, sets its initial values.
// Called from above and also from resetFigure() in homework/answerJS.jsp.h.
function setMarvinJS(mol, appletName, qFlags, eschewJQuery) {
if (eschewJQuery != null && eschewJQuery) {
// wait until the iframe (id = appletName) is loaded
getCell(appletName).addEventListener('load', function() {
// wait until the MarvinJS editor (id = #appletName) is loaded
MarvinJSUtil.getEditor('#' + appletName).then(function(sketcherInstance) {
marvinSketcherInstance = sketcherInstance;
setMarvinJSValues(mol, appletName, qFlags);
}, function(error) {
alert('Loading of the sketcher failed: ' + error);
}); // getEditor()
}); // addEventListener()
} else {
$(document).ready(function handleDocumentReady(e) {
getMarvinPromise('#' + appletName).done(function (sketcherInstance) {
marvinSketcherInstance = sketcherInstance;
setMarvinJSValues(mol, appletName, qFlags);
}).fail(function () {
alert('Cannot retrieve sketcher instance from iframe.');
}); // getMarvinPromise.done()
}); // document.ready()
} // if useJQuery
} // setMarvinJS()
// Loads the molecule, perhaps sets the display settings.
// Called from above.
function setMarvinJSValues(mol, appletName, qFlags) {
if (qFlags >= 0) {
marvinSketcherInstance.setDisplaySettings({
'toolbars': 'reporting',
'copyasmrv': true,
'carbonLabelVisible': allCVisible(qFlags),
'implicitHydrogen': getHVisibilityJS(qFlags),
'valenceErrorVisible': valenceErrorVisible(qFlags),
'atomIndicesVisible': appletName === 'hybridMarvin',
'lonePairsVisible': lonePairsVisible(qFlags),
'atomMapsVisible': atomMapsVisible(qFlags),
'chiralFlagVisible': false, // don't show absolute stereo flag
// currently no way to turn R/S flag visibility on or off
'cpkColoring': true
});
} // if qFlags
if (!isEmpty(mol)) marvinSketcherInstance.importStructure(null, mol);
if (loadSelections) loadSelections();
} // setMarvinJSValues()
// gets an HTML element
function getCell(cellName) {
return document.getElementById(cellName);
} // getCell()