tomtom/shelve — pull request #4 by crass (2013-09-22 10:52:22+00:00)
Title: Fix shelve edit not close

For as long as I've used this addon the edit window for an individual shelve would not close when I hit the "ok" button. However, if I hit the "ok" button, then the "cancel" button, my changes would be saved (well most of them), but there would be no error message.

This was caused by having the autoselect feature turned on, which allowed shelve.setupAutoSelect to be called from the modal dialog. This was a problem because shelve.setupAutoSelect called shelve.addEventListener, which expects to be called from a browser window. So an uncaught exception was generated.

The first change fixes this issue by calling shelve.setupAutoSelect for each browser window.

However, upon making those changes, I discovered that the mechanism for ensuring that only one event listener for the autoselect feature was installed had a race condition on the global shelve.autoselect. So I've reworked the code to not need that global and added the functionality to remove the event listener if there are no auto-select shelves enhancing performance when auto-select is turned off.