Bug Tracker

Modify

Ticket #9841 (closed bug: invalid)

Opened 2 years ago

Last modified 12 months ago

.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:2 Changed 2 years ago by scott.gonzalez

  • Cc scott.gonzalez added

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.

comment:8 Changed 12 months ago by blaisekal@…

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

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

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.