Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop click on _openPopup #3605

Merged
merged 1 commit into from
Jul 9, 2015
Merged

Stop click on _openPopup #3605

merged 1 commit into from
Jul 9, 2015

Conversation

yohanboniface
Copy link
Member

Fix #3604.
I had a quick break.
Bubbling from marker is supposed to be the default, now, so I just stopped the event on _openPopup.
I could also just add it on bindPopup, if you prefer this pattern.

@mourner
Copy link
Member

mourner commented Jul 8, 2015

Bubbling from marker is supposed to be the default, now

Hmm, but why? I think I'd prefer to keep not bubbling up from markers the default.

@yohanboniface
Copy link
Member Author

Hmm, but why?

The map is an event target, so it's considered while traversing the DOM, and given that it listens for click the event is fired.

I think I'd prefer to keep not bubbling up from markers the default.

Are we sure it's a problem (out of retrocompat) ? It's closer to DOM behaviour, no?

@ktoto
Copy link

ktoto commented Jul 8, 2015

@yohanboniface problem not in openPopup. problem happen when i have 'click' handler in marker and in map.
openPopup just is special case with this binding.

@yohanboniface
Copy link
Member Author

@ktoto (take this with caution, as it's not fully decided): with the current code when you listen to a click event and you don't want the map to also receive it, you are responsible of stopping it.
In the case of bindPopup, given that the event listener has been added by Leaflet internally, it's its responsibility to then stop it. Makes sense?

@ktoto
Copy link

ktoto commented Jul 8, 2015

@yohanboniface but before #3307 all be fine. I just want to understand why logic with map is changed?
Why map want click if the first interaction element was marker? Why just not stop on marker at all?

@yohanboniface
Copy link
Member Author

Why map want click if the first interaction element was marker? Why just not stop on marker at all?

Just like in normal DOM, when an event is fired by an element, all its ancestors get it, unless stopPropagation is called at some point.
You may have a use case where you want to catch all click events, both on markers (or polygons) and map.

@mourner
Copy link
Member

mourner commented Jul 8, 2015

I'd rather not follow DOM conventions and do an exception here, since I can't think of a use case where you'd want to trigger both map and marker on marker click, but people will have a very hard time adjusting to this breaking change.

@yohanboniface
Copy link
Member Author

I'd rather not follow DOM conventions and do an exception here

You mean exception for marker or for click ? i.e. never bubble click or never bubble click on marker but still bubble it on polygons?
I can think of many use cases where I'd love to receive click events that where initially fired on a polygon. And by the way, being able to receive click on a map whatever the source was would be a killer simplification for all "drawing" application on the map.
But you decide :)

@mourner
Copy link
Member

mourner commented Jul 8, 2015

Exception for marker specifically, as opposed to vector layers and image overlays (which can be perceived as "click through" in some interfaces).

@yohanboniface
Copy link
Member Author

OK, I'll do that asap :)

@yohanboniface
Copy link
Member Author

@mourner only for click or we can think about other events?

@mourner
Copy link
Member

mourner commented Jul 8, 2015

@yohanboniface let's follow the 0.7.3 behavior here.

options: {
unpropagateEvents: '' // Space separated events that should not be propagated
},

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be in Layer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hesitated ;)

@@ -696,7 +696,8 @@ L.Map = L.Evented.extend({
for (var i = 0; i < targets.length; i++) {
if (targets[i].listens(type, true)) {
targets[i].fire(type, data, true);
if (data.originalEvent._stopped) { return; }
if (data.originalEvent._stopped
|| (targets[i].options.nonBubblingEvents && targets[i].options.nonBubblingEvents.indexOf(type) !== -1)) { return; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately IE only supports array indexOf starting from 9. We'll probably have to iterate over the array in a loop.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gasp :/
Should I add a polyfill L.Util.inArray for that? To make the code shorter here and more readable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, maybe something like L.Util.indexOf.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L.Util.indexOf seems meaning it also will work on strings, is that what we want?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine to keep only for arrays since string indexOf doesn't need an util method. It's an internal utility after all, we don't have to make it generic.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK done :)

@yohanboniface
Copy link
Member Author

Meeeeehhhh, how the console is playing with me!?
screenshot from 2015-07-09 13 50 10

Array.prototype.indexOf?

@mourner
Copy link
Member

mourner commented Jul 9, 2015

Mine is like this :)
image
I think we're fine just not using native indexOf. It's not that much of a difference.

@yohanboniface
Copy link
Member Author

Yeah, Chrome vs FF :/
OK, I make the loop for everybody :)

@mourner
Copy link
Member

mourner commented Jul 9, 2015

OK, let's rebase now.

@yohanboniface
Copy link
Member Author

Actually I think it's fine at this moment :)

Humm, not sure which moment :p Seems I've commit one second before to remove the use of Array.indexOf

@mourner
Copy link
Member

mourner commented Jul 9, 2015

Nevermind :)

@yohanboniface yohanboniface force-pushed the stop-click-on-openpopup branch from 720b02e to b20ffaa Compare July 9, 2015 12:10
@yohanboniface yohanboniface force-pushed the stop-click-on-openpopup branch from b20ffaa to 74018f2 Compare July 9, 2015 12:12
@yohanboniface
Copy link
Member Author

Rebased and green :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants