Skip to main content

Bug Tracker

Side navigation

#9841 closed bug (invalid)

Opened July 16, 2011 12:29AM UTC

Closed September 08, 2011 03:22PM UTC

Last modified June 18, 2012 03:27PM UTC

.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.

Attachments (0)
Change History (8)

Changed July 16, 2011 12:30AM UTC by dmethvin comment:1

component: unfiledevent
milestone: 1.next1.7
owner: → dmethvin
priority: undecidedblocker
status: newassigned
summary: .trigger()ed events shoudl not bubble to window.trigger()ed events should not bubble to window

Changed July 19, 2011 06:12PM UTC by scottgonzalez comment:2

cc: → scott.gonzalez

Changed September 08, 2011 01:50PM UTC by dmethvin comment:3

cc: scott.gonzalezscott.gonzalez, cowboy

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.

Changed September 08, 2011 02:21PM UTC by anonymous comment:4

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.

Changed September 08, 2011 02:28PM UTC by scottgonzalez comment:5

I hate that I can comment anonymously now.

Changed September 08, 2011 03:22PM UTC by dmethvin comment:6

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!

Changed October 16, 2011 11:04PM UTC by rnice@nicey.com comment:7

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.

Changed June 18, 2012 03:27PM UTC by blaisekal@gmail.com comment:8

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

$(window).resize(function(e) {
  if (!e.target.tagName) {
    // Window was resized.
  }
});