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

Fix canvas not filtering click event after drag #4493

Merged
merged 2 commits into from
Jun 1, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix preclick not fired in canvas
  • Loading branch information
yohanboniface committed Apr 23, 2016
commit f2eb6f42ed1976b08429b82e5ed3ab037e8809a5
17 changes: 17 additions & 0 deletions spec/suites/layer/vector/CanvasSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,23 @@ describe('Canvas', function () {
map.off("click", spy);
});

it("should fire preclick before click", function () {
var clickSpy = sinon.spy();
var preclickSpy = sinon.spy();
layer.on('click', clickSpy);
layer.on('preclick', preclickSpy);
layer.once('preclick', function (e) {
expect(clickSpy.called).to.be(false);
});
happen.at('click', 50, 50); // Click on the layer.
expect(clickSpy.callCount).to.eql(1);
expect(preclickSpy.callCount).to.eql(1);
happen.at('click', 150, 150); // Click outside layer.
expect(clickSpy.callCount).to.eql(1);
expect(preclickSpy.callCount).to.eql(1);
layer.off();
});

});

describe("#events(interactive=false)", function () {
Expand Down
22 changes: 11 additions & 11 deletions src/map/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -989,17 +989,6 @@ L.Map = L.Evented.extend({

var type = e.type === 'keypress' && e.keyCode === 13 ? 'click' : e.type;

if (e.type === 'click') {
// Fire a synthetic 'preclick' event which propagates up (mainly for closing popups).
// @event preclick: MouseEvent
// Fired before mouse click on the map (sometimes useful when you
// want something to happen on click before any existing click
// handlers start running).
var synth = L.Util.extend({}, e);
synth.type = 'preclick';
this._handleDOMEvent(synth);
}

if (type === 'mousedown') {
// prevents outline when clicking on keyboard-focusable element
L.DomUtil.preventOutline(e.target || e.srcElement);
Expand All @@ -1010,6 +999,17 @@ L.Map = L.Evented.extend({

_fireDOMEvent: function (e, type, targets) {

if (e.type === 'click') {
// Fire a synthetic 'preclick' event which propagates up (mainly for closing popups).
// @event preclick: MouseEvent
// Fired before mouse click on the map (sometimes useful when you
// want something to happen on click before any existing click
// handlers start running).
var synth = L.Util.extend({}, e);
synth.type = 'preclick';
this._fireDOMEvent(synth, synth.type, targets);
}

if (e._stopped) { return; }

// Find the layer the event is propagating from and its parents.
Expand Down