jQuery suggests to wait for the document ready
event before doing any DOM manipulation. In flight.js components, this.after('initialize')
seems to be called before that event triggers.
Is it necessary to wait for it within a flight component, like so?
this.after('initialize', function () {
// Is this necessary?
$(document).ready(function () {
...
});
// Or this, the flight way?
this.on(document, 'ready', function () {
...
});
});
Thank you
Rudi, it kind of depends on what you're trying to do. A Flight component, typically, is going to attach to a DOM element on initialization. So, if the element exists in the document statically and your script to initialize components is included at the end of the body, you are probably ok.
But, typically, when I'm writing Flight apps, I'll typically have a script or module that initializes all the components for that page and attaches them. In that script, you could wrap it to wait for DOMContentReady, especially if you have code that will dynamically write elements to the page that components will attach to after page load.
If the circumstances in that component need it to listen to DOMContentReady, that's also a useful way to do it int he after('initialize',...)
method as well.