Bug Tracker

Opened 12 years ago

Closed 11 years ago

Last modified 11 years ago

#9841 closed bug (invalid)

.trigger()ed events should not bubble to window

Reported by: dmethvin Owned by: dmethvin
Priority: blocker Milestone: 1.7
Component: event Version: 1.6.2
Keywords: Cc: scott.gonzalez, cowboy
Blocked by: Blocking:


Essentially this reverts #8712. According to the W3C:

Bubbling events will then trigger any additional event listeners found by following the EventTarget's parent chain upward, checking for any event listeners registered on each successive EventTarget. This upward propagation will continue up to and including the Document. --


There are several negative implications of bubbling all events to window since that contains all globals. If an event matches a global variable or method it may inadvertently trigger unwanted behavior. Related tickets: #9724, #6170, and #7930.

Change History (8)

comment:1 Changed 12 years ago by dmethvin

Component: unfiledevent
Milestone: 1.next1.7
Owner: set to dmethvin
Priority: undecidedblocker
Status: newassigned
Summary: .trigger()ed events shoudl not bubble to window.trigger()ed events should not bubble to window

comment:2 Changed 12 years ago by scottgonzalez

Cc: scott.gonzalez added

comment:3 Changed 11 years ago by dmethvin

Cc: cowboy added

Opinions, anyone? I am still inclined to land this to reduce the chances of global variables causing issues, but browsers do seem to contradict the W3C and bubble to window. So much for standards.

comment:4 Changed 11 years ago by anonymous

The standards changed :-( DOM Level 2 says events bubble to the document, DOM Level 3 says events bubble to the window. I emailed Doug Schepers to ask why this was changed, but never got a response.

comment:5 in reply to:  4 Changed 11 years ago by scottgonzalez

I hate that I can comment anonymously now.

comment:6 Changed 11 years ago by dmethvin

Resolution: invalid
Status: assignedclosed

Well it comes in handy if I am thinking about shooting the messenger tho.

DOM Level 3 says events bubble to the window

OK, well then we shall follow the freshest available standard. :) The three linked tickets are still open and I'm looking at solutions for 1.7. Thanks for checking!

comment:7 Changed 11 years ago by [email protected]

So when you have a window resize defined and a ui-resizable element the trigger on the element gets 'bubbled' to the window?

Okay, but then you need to update the documentation for the resize method to indicate that a window resize message can be triggered when the window doesn't actually resize! Ergo, that you should always check the target, e.g.

$(window).resize(function(e) {
  if (e.target == window)
    /* do your stuff here */;

Quite why a resize event on some non significant sub element should bubble up to the window is a mystery to me and it's confusing as hell to us mere mortals. It'd make more sense the other way around, when the window size changes notify all the children. Oh well.

comment:8 Changed 11 years ago by [email protected]

Above comment does not work in IE8. This does work cross-browser:

$(window).resize(function(e) {
  if (!e.target.tagName) {
    // Window was resized.
Note: See TracTickets for help on using tickets.