Ticket #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 | |
| Blocking: | Blocked by: |
Description
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. --
http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-flow-bubbling
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
comment:1 Changed 2 years ago by dmethvin
- Status changed from new to assigned
- Component changed from unfiled to event
- Summary changed from .trigger()ed events shoudl not bubble to window to .trigger()ed events should not bubble to window
- Priority changed from undecided to blocker
- Milestone changed from 1.next to 1.7
- Owner set to dmethvin
comment:3 Changed 22 months 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 follow-up: ↓ 5 Changed 22 months 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 22 months ago by scott.gonzalez
I hate that I can comment anonymously now.
comment:6 Changed 22 months ago by dmethvin
- Status changed from assigned to closed
- Resolution set to invalid
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 20 months ago by rnice@…
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.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
