pelagios / pelagios-widgets

Embeddable Javascript widgets to access Pelagios data
GNU General Public License v3.0
7 stars 7 forks source link

Widget does not always display when div is added by javascript #88

Open julietteculver opened 12 years ago

julietteculver commented 12 years ago

There seems to be a race condition issue when

The pelagios widget javascript sometimes runs before the divs are added and therefore does not find them.

julietteculver commented 12 years ago

Possible options:

1) Add information to the documentation to make it clear that this is the responsibility of the person adding the widget to only run the script after the HTML has been added and give some examples of how this might be done. Improve the debug information and documentation so that it is easier for folk other than me to figure out what is going on when the widget does not work. Suggest adding the defer attribute to the pelagios script to decrease the chance that the problem arises, although as browser support is variable, this is not an ideal solution.

2) Add a query string to the Pelagios javascript to say that the Pelagios code should only be run until a particular event has been fired (could be a specific variable being set?). Set a listener for that event and add documentation to instruct the person embedding the widget to fire the event when all the HTML has been added (and if they are using the dreaded Google Maps v2, when that has been loaded). I seem to remember that there is an issue with scripts and query strings but hopefully that can be dealt with. Tom mentioned using a semaphore and I believe this solution is effectively no different from using a mutex.

3) As a short-term option use a timeout to delay the Pelagios script being run. I am not keen on this solution however because it does not offer any guarantees against the problem and delays the widget appearing.