Hi Francois,
The main problem I ran into is that the code expects a certain sequence of events:
- Load BM script (sets up window.bm and registers onload handler)
- Call bm.init() (in a script tag)
- onload event fires and creates BM elements and does other BM setup
The problems I ran into were:
- If I haven't called bm.init() before onload fires, for example, it runs into some problems with undefined values.
- If I load the script AFTER onload has already fired, it never fires the onload event and finishes the BM setup
The most flexible approach would probably be to have it so that the onload handler does nothing if it was previously already run or bm.init() was not called, and then have bm.init() do that onload work if it's called after the page has already loaded. You can check if the page has loaded using document.readystate I believe.
The code could be super-async if you don't realy on bm being present before calling bm.init, you can take a look at how google analytics does this for an example. Not useful in my case, however, I can know that the brassmonkey js is loaded AND the DOM is loaded when I call bm.init().
If I had the original sources I could probably stick this logic in there myself...
Cheers,
Dobes