giovedì 6 gennaio 2011

Mozilla - Dynamically filling menus

I'm updating a toolbar extension for Firefox I wrote last year. I have 3 toolbarbuttons with menupopups filled dynamically. A Javascript function called by an onpopupshowing handler retrieves the contents from the internet, builds the menuitems and adds them to a menupopup at runtime. Obviously the function depends on the remote server response speed and on my internet connection. In addition, the function takes a little time to manipulate the data. In short, in my case, the process of retrieving contents and filling a menu takes about half a second, so, if I click on the toolbarbutton, a very little white rectangle is showed for a split second before the menu appears.
I'd like to delay the menu appearence but it seems quite difficult.
According to Mozilla, if we have nothing to show on a menu, we should follow the standard used in Firefox: show a single disabled item with an "(Empty)" label. If filling the menu takes a noticeable amount of time, we should not make Firefox (and users) wait for it to fill up before displaying anything. It's best to show an item with a throbber image (chrome://global/skin/icons/loading_16.png) so the user knows there's something going on, and asynchronously fill its contents.
I'm still wondering if it's possible to delay the menu appearence.

Best regards.