Ticket #14728 (reopened feature)

Opened 3 months ago

Last modified 5 weeks ago

support stopImmediatePropagation()

Reported by: bill Owned by: kzyp
Priority: undecided Milestone: 1.8
Component: Events Version: 1.7.1
Keywords: Cc: cjolif
Blocked by: Blocking:

Description

Newer browsers' event objects have a  stopImmediatePropagation() method. It would be nice if you could normalize the events from older browsers to have this too.

Unfortunately, even IE8 is missing this method, so dropping support for IE6-7 wouldn't help.

I think the implementation (for browsers that don't support this natively) would be fairly simple, just calling stopPropagation() and then setting a flag on the event object that subsequent handlers would check.

My personal use case for this feature is to help with widget event propagation. Consider a button widget with a template like:

<span>click me</span>

And some JS code to support a disabled attribute, for example:

postCreate: function(){
      on(this.domNode, "click", lang.hitch(this, function(evt){
             if(this.disabled){ evt.stopImmediatePropagation(); }
      });
}

And now consider that an app does:

on(dojo.byId("mybutton"), "click", function(){
     console.log("clicked!");
});

I need the second event handler to not fire, even though it's on the same DOMNode.

Attachments

stopImmediatePropagation.txt Download (740 bytes) - added by martinerko 5 weeks ago.

Change History

comment:1 Changed 3 months ago by kzyp

Would we need to normalize Webkit and FF (will be supporting versions that don't have stopImmediatePropagation), or just old IE?

comment:2 Changed 3 months ago by bill

I wondered about that too. It's not supported in FF3.6 or FF8, which we are supporting according to our  release notes for 1.8. FF3.6 is or will be  EOL before we ship 1.8 but for some reason #14570 talks about supporting FF3.6 until dojo 1.9.

Personally I'd prefer not to waste time on EOL'd browsers so we should debate it if the work is significant.

Last edited 3 months ago by bill (previous) (diff)

comment:3 Changed 3 months ago by kzyp

  • Status changed from new to closed
  • Resolution set to fixed

In [28041/dojo]:

Add support for stopImmediatePropagation, fixes #14728
Add support augmenting event objects in IE, fixes #14729 !strict

comment:4 Changed 2 months ago by bill

  • Milestone changed from tbd to 1.8

comment:5 Changed 2 months ago by pruzand

Since this patch, the dojox.geo.openlayers.tests.test_widget.html does not work anymore. The reason is that OpenLayers? defines a global Event object as a litteral object in case window.Event is not defined. (see  http://svn.openlayers.org/trunk/openlayers/lib/OpenLayers/Events.js). Therefore, the line:

has.add("event-stopimmediatepropogation", window.Event && !!window.Event.prototype.stopImmediatePropagation);

raises an error because Event.prototype is not defined in this case.

Honestly I am not sure who is the culprit, but maybe the code should double-check that we are in a case where window.Event has a prototype ?

comment:6 Changed 2 months ago by pruzand

  • Status changed from closed to reopened
  • Resolution fixed deleted

Changed 5 weeks ago by martinerko

comment:7 Changed 5 weeks ago by martinerko

I am also using OpenLayers?. I have added simple quick fix.

comment:8 Changed 5 weeks ago by cjolif

  • Cc cjolif added
Note: See TracTickets for help on using tickets.