Thanks for your help. I have written the two following sets of code; both use Promise objects, but one uses JQuery and one does not. Common to both:
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);
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);
} // startMarvinJS()
With JQuery, setMarvinJS() is:
function setMarvinJS(mol, appletName, qFlags) {
$(document).ready(function handleDocumentReady(e) {
getMarvinPromise('#' + appletName).done(function (sketcherInstance) {
marvinSketcherInstance = sketcherInstance;
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': true,
'cpkColoring': true
});
} // if qFlags
if (!isEmpty(mol)) marvinSketcherInstance.importStructure(null, mol);
if (loadSelections) loadSelections();
}).fail(function () {
alert('Cannot retrieve sketcher instance from iframe.');
});
});
} // setMarvinJS()
Without JQuery, setMarvinJS() is:
function setMarvinJS(mol, appletName, qFlags) {
// wait until the iframe (id = appletName) is loaded
document.getElementById(appletName).addEventListener('load', function() {
// wait until the MarvinJS editor (id = #appletName) is loaded
MarvinJSUtil.getEditor('#' + appletName).then(function(sketcherInstance) {
marvinSketcherInstance = sketcherInstance;
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': true,
'cpkColoring': true
});
} // if qFlags
if (!isEmpty(mol)) marvinSketcherInstance.importStructure(null, mol);
if (loadSelections) loadSelections();
}, function(error) {
alert('Loading of the sketcher failed: ' + error);
}); // getEditor()
}); // addEventListener()
} // setMarvinJS()
With the code that does not use JQuery, the requested toolbar is not loaded; see screen shots. I note that the requested toolbar also fails to load when I specify the toolbar in the iframe tag instead of using setDisplaySettings(). ???