got5/tapestry5-jquery — pull request #226 by imbcmdth (2012-08-26 20:17:34+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 final callback and script `c.js` will be skipped.