Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#7279 - .bind("ready") events fire out of order #80

Closed
wants to merge 6 commits into from

Conversation

cowboy
Copy link
Member

@cowboy cowboy commented Oct 30, 2010

My changes fix the issue described in this ticket. Here's an updated JSFiddle using my local build.

I basically check to see if the bind subsystem exists, and if it does, use rootjQuery.bind( "ready", fn ) otherwise just use readyList.push( fn ).

I also added a bunch of unit tests, so if nothing else you should grab those.

Hope this helps!

…ll now execute (and unbind) immediately if jQuery.isReady is true
…if possible. This ensures that ready event handlers execute in the proper order, regardless of how they are bound. Handlers bound via jQuery(document).bind( 'ready', fn ) will still have the event object passed in, while handlers bound via jQuery( fn ) and jQuery(document).ready( fn ) will still have a reference to jQuery passed in.
…to pass in a proper jQuery event object in the case of jQuery(document).bind( 'ready', fn ) being called after DOM ready. This solution can't be as full-featured as if trigger were called, but it should work well enough until the whole DOM ready sub-structure can be re-written.
@cowboy
Copy link
Member Author

cowboy commented Nov 1, 2010

BTW, I consider this a temporary fix. I really think that the DOM ready event system should really get an overhaul to avoid issues like these in the future.. but I don't know that the overall behavior (which my changes address) needs to wait until 1.5.

@dmethvin
Copy link
Member

Ben, the ready code is most likely being replaced by the Deferreds implementation from jaubourg, so all of this is getting an overhaul. From the discussion in the ticket and the code it seems like the two major issues were that some handlers were firing multiple times (fixed in DOM0 already) and also that handlers fired out of the order they were attached. Anything else?

@cowboy
Copy link
Member Author

cowboy commented Dec 26, 2010

The big issues I had were that:

  • some bound handlers were firing twice (already fixed).
  • unlike other "event shortcut" methods, $.fn.ready isn't a shortcut for $.fn.bind, which isn't a problem by itself, but these confusing side effects arise...
  • bound handlers can fire out-of-order, depending on which method is used to bind them.
  • when fn is called in $( fn ) and $(document).ready( fn ), a reference to jQuery is passed, but when fn is called in $(document).bind( "ready", fn ), an event object is passed.

@dmethvin
Copy link
Member

Ben, I suspect several of these issues are already resolved in 1.5.2, but can you review and see what might be left? I'm trying to figure out if #7279 should be closed or not.

@cowboy
Copy link
Member Author

cowboy commented Mar 31, 2011

Added a replacement pull #293, killing this one.

@cowboy cowboy closed this Mar 31, 2011
@lock lock bot locked as resolved and limited conversation to collaborators Jan 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants