01org/appframework — pull request #335 by dpesch (2013-08-08 16:43:11+00:00)
Title: fixes that $.trigger call all bound event handler

even, if they or some of them use $.unbind() to unbind themselves

I've wondered today why not all of my "content-loaded" event handler were called. And after I've bound additional (test) functions, my function was called.

These function(s) should always only run once after they're called, so they unbind themselves with:
$.unbind($.ui, "content-loaded", _myFunction)

But this brakes the loop over the referenced event array, because it's length got reduced, and some handler won't be reached. Sometimes they're called on the next event, or later which causes really strange effects.

The fix creates a copy of the event array which doesn't change on $.unbind() so all event handler are called.

I'll hope you'll like it.

Best regards
dom