got5/tapestry5-jquery — pull request #228 by imbcmdth (2012-08-30 19:53:26+00:00)
Title: Fixed: `addScripts` functionality

My earlier commit on this issue was wrong. This one fixes `addScripts` in a much more robust way.

The problem with the existing code is that it depends on the index `i` of the current element in the `scripts` array as an index (`i + 1`)into the `callbacks` array. But the `callbacks` array may **not** have the same length as the `scripts` array because the `push` into it is conditional on the script under consideration not being present in the page already.

Given the following:

````javascript
scripts = [ "a.js", "b.js", "c.js" ];
````

Where `a.js` is already included in the page, the `callbacks` array will be:

````javascript
callbacks = [ b_callback, c_callback , original_callback ];
````

But when the `b_callback` function's `onload` or `onreadystatechange` handler is finally executed, it will call the `i + 1` element of the `callbacks` array where `i = 1` - because `b.js` is the second element in the original `scripts` array. This will cause the next function executed to be the third element in the `callbacks` array. In other words, the final callback is executed next and the script `c.js` will be skipped.