Customizing gallery shortcode in 3.5
Make sure that the javascript loaded by your load-scripts.php is waiting for the document to finish loading before attaching all of the listeners. When you created a separate function the code ran only a tiny bit earlier, but it was probably early enough for the elements to finish loading and the listeners to properly attach.