#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: |
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 (8)
comment:1 Changed 12 years ago by
Component: | unfiled → event |
---|---|
Milestone: | 1.next → 1.7 |
Owner: | set to dmethvin |
Priority: | undecided → blocker |
Status: | new → assigned |
Summary: | .trigger()ed events shoudl not bubble to window → .trigger()ed events should not bubble to window |
comment:2 Changed 12 years ago by
Cc: | scott.gonzalez added |
---|
comment:3 Changed 11 years ago by
Cc: | cowboy added |
---|
comment:4 follow-up: 5 Changed 11 years ago by
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:6 Changed 11 years ago by
Resolution: | → invalid |
---|---|
Status: | assigned → closed |
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
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
Above comment does not work in IE8. This does work cross-browser:
$(window).resize(function(e) { if (!e.target.tagName) { // Window was resized. } });
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.