[OpenLayers-Dev] stop propagation in handlers

Tim Schaub tschaub at openplans.org
Tue Feb 26 13:00:43 EST 2008


Hey-

Pierre GIRAUD wrote:
> Hello,
> 
> In most handlers, in fact those dealing with browser events, we need,
> in most case need to stop event propagation, to prevent weird
> behaviors. However, I think that propagation stop isn't complete.
> Returning false to an event callback doesn't to be enough.
> In my code, I play with vector symbols using SVG 'symbol' and 'use'
> tags. The latter have a 'href' property with a reference to the
> symbol. Ctrl+Click on the corresponding feature on the map opens a new
> tab in FF.

Yeah, three kinds of stopping really.  The stopDown property is about 
stopping other listeners for the same events instance (same dom element 
in the case of browser events) from getting notified.

Do we want a separate property for stopping events from bubbling to 
other dom elements?

How about stopping the browser default for an event?

I think lumping all three of those in one property (on a handler) might 
come back to haunt us.

Tim


> I need this Ctrl+Click because I need to select several feature.
> http://dev.openlayers.org/sandbox/camptocamp/vectorSymbols/examples/select-feature.html
> 
> I'm not really convinced by this solution but I would prefer something
> like following. It seems to work fine for me in my example.
> 
>      mousedown: function(evt) {
>          this.down = evt.xy;
> -        return this.handle(evt) ? !this.stopDown : true;
> +        if (this.handle(evt)) {
> +            if (this.stopDown) {
> +                OpenLayers.Event.stop(evt, true);
> +            }
> +            return !this.stopDown;
> +        } else {
> +            return true;
> +        }
>      },
> 
> Any comment on that ?
> 
> Regards,
> Pierre
> _______________________________________________
> Dev mailing list
> Dev at openlayers.org
> http://openlayers.org/mailman/listinfo/dev
> 
> !DSPAM:4033,47c2cba2327006491211187!
> 




More information about the Dev mailing list