requested toolbar fails to load when util.js is resource

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()

However, if eschewJQuery is set to false, or if I omit the utils.js resource, then the requested toolbar and the provided molecule load as expected. 



I looked at the utils.js file, and it appears to provide additional functionality for the Promise object, so I am hesitant to omit it from the list of resources, as I believe that MarvinJSUtil.getEditor() returns a Promise object that we use. Do you have any solutions?

User 870ab5b546

14-01-2015 16:46:21

OK, I figured out that when I use the eschewJQuery code in setMarvinJS(), everything works fine without any of the js resources associated with JQuery *or* with Promise objects. So I don't need to load util.js, promise.min.js, and jquery.min,js. When I omit these resources, the requested toolbar and the initial molecule load properly, and my other code (exporting structures from the sketcher, etc.) works fine as well.

ChemAxon f052bdfe3c

16-01-2015 08:37:35

We are glad that it work that way. Thank you for the feedback.


Best regards,


Efi