1
votes

I am developing a single-page web-application with Dojo 1.9.

We use the Dojo Parser to initialize widgets in HTML fragments loaded from the server into a dojox.layout.ContentPane.

Before we insert the ContentPane into the page, we want to wait until all of the widgets finish initialization completely.

Is there a way to do this?

I have been trying to achieve this by waiting on the promise returned by ContentPane.content but this seems to get resolved earlier.

var onParseEnd = pane.set("content", htmlText);

I think that onParseEnd gets resolved immediately after the parser has "parsed" the HTML content and not after all of the widget initializations have finished.

1
have you tried dojo/parser?. It returns a promise which gets resolved after all the dojo widgets gets instantiated. e.g require (["dojo/parser"], function ( parser ){ parser.parse( html_fragment ).then(onComplete_Callback);}); - frank
Unfortunatelly, we only use dojo/parser indirectly. We call 'ContentPane.set("content", htmlFragment)' because that also executes the Javascript placed into the fragment, attaches CSS...etc - sola
As per the dojox/contentpane documentation at the end it does offer a clue ( unfortunately it is not clear) which might be a solution to your problem. The documentation goes like this. Through the use of the scriptHasHooks setting, a Deferred instance, onLoadDeferred and it’s then() method, you can simulate the dojo.ready behavior from inside the loaded content. An alternative is to set scriptHasHooks=true, and have content like this in your loaded content: - frank
Here is a discussion on dojo forum which relates to a similar problem - frank
Yes, that is correct. onLoadDeferred only waits for the content itself to load (in the case of setting href rather than content) and for parse to run (in case there were any new modules that needed to be required). Resolution isn't delayed for the script execution enabled by dojox/layout/ContentPane (actually handled by dojox/html/_base). It is ideally preferable to organize JavaScript into modules and templated widgets as necessary so that your code is well-organized and you don't end up at the mercy of loose scripts evaluated as part of mixed content. - Ken Franqueiro

1 Answers

0
votes

If you need to be sure the widgets have rendered you could consider domReady! to get an event firing after the widgets have initialized and have been rendered: http://dojotoolkit.org/reference-guide/1.10/dojo/domReady.html

However, the startup() event of your widget(s) is usually the better option, to avoid "glitches" where content is added/modified after having been rendered by the browser.