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

singleclick event #108

Closed
msaspence opened this issue Jun 9, 2011 · 9 comments
Closed

singleclick event #108

msaspence opened this issue Jun 9, 2011 · 9 comments
Labels

Comments

@msaspence
Copy link
Contributor

when a double click occurs two single click events are triggered which is a problem if you want to do something on single click but not double click

the firing of two single click within a double click is browser behaviour but there are possible workarounds

sparkle provides a jquery singleclick that may be usefull

http://balupton.com/projects/jquery-sparkle

@mourner
Copy link
Member

mourner commented Jun 9, 2011

Unfortunately all such workarounds are based on deciding whether to fire click after a particular timeout, and it makes applications that don't care about double-clicking less responsive. So I would implement something like "singleclick" support as a plugin, but not include it in the Leaflet core.

@cvisto
Copy link

cvisto commented Feb 8, 2012

Does such plugin already exist?

@mourner
Copy link
Member

mourner commented Feb 8, 2012

Didn't yet heard of any.

@cvisto
Copy link

cvisto commented Feb 8, 2012

it is a pity. Is there any place where all shared plugins stored?

@mourner
Copy link
Member

mourner commented Feb 14, 2012

See my thoughts on this here: #399

@johtso
Copy link
Contributor

johtso commented Mar 26, 2012

See this comment from @michael for an example solution.

@mourner
Copy link
Member

mourner commented Oct 17, 2012

Closing as something that should go into a plugin.

@RickMohr
Copy link
Contributor

I'm working on a favorDoubleClick plugin for this issue. When the plugin is enabled, click events will call their handlers only if no second click happens before a specified timeout. The implementation is straightforward and safe but it requires replacing two core Leaflet functions, so I'm wondering if there's a better way.

Leaflet registers click handlers in various situations. For example, when a marker is added to the map L.Marker.onAdd registers a click handler via L.DomEvent.on. And when a popup is created, L.Layer.bindPopup registers a click handler via L.Evented.on. When the plugin is enabled, these actions must create click handlers which use a timeout as described above.

Strategy: L.favorDoubleClick.enable will replace L.DomEvent.on and L.Evented.on with versions which wrap the passed-in handler to implement the timeout behavior. Since all event binding ultimately uses one of these two core functions, all click handlers will have the desired behavior if the plugin is enabled before anything is added to the map. (To make L.favorDoubleClick.disable trivially simple, the wrapped handlers will only apply the timeout if L.favorDoubleClick.isEnabled.)

If anyone sees a problem with this strategy or has a better strategy, please speak up!

@glathoud
Copy link
Contributor

Here is a possible plugin: https://github.com/Alpstein/leaflet-singleclick_0.7

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

No branches or pull requests

6 participants