Skip to content

Commit

Permalink
Merge pull request #4387 from Leaflet/fix-disable-enable-drag
Browse files Browse the repository at this point in the history
Make drag handler insensitive to order of handlers events
  • Loading branch information
IvanSanchez committed Apr 15, 2016
2 parents 37532b3 + 5389d23 commit fcffa30
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
58 changes: 58 additions & 0 deletions spec/suites/map/handler/Map.DragSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,64 @@ describe("Map.Drag", function () {
toucher.wait(100).moveTo(200, 200, 0)
.down().moveBy(1, 0, 20).moveBy(1, 0, 200).up();
});

it.skipIfNotTouch('reset itself after touchend', function (done) {

var container = document.createElement('div');
container.style.width = container.style.height = '600px';
container.style.top = container.style.left = 0;
container.style.position = 'absolute';
document.body.appendChild(container);
var map = new L.Map(container, {
dragging: true,
inertia: false,
zoomAnimation: false // If true, the test has to wait extra 250msec
});
map.setView([0, 0], 1);

// Change default events order to make the tap comming before the touchzoom.
// See #4315
map.dragging.disable();
map.dragging.enable();

var center = map.getCenter(),
zoom = map.getZoom();


var mouseHand = new Hand({
timing: 'fastframe',
onStop: function () {
document.body.removeChild(container);
expect(map.getCenter()).to.eql(center);
expect(map.getZoom()).to.eql(zoom);

done();
}
});
var mouse = mouseHand.growFinger('mouse');
var hand = new Hand({
timing: 'fastframe',
onStop: function () {
expect(map.getCenter()).not.to.eql(center);
expect(map.getZoom()).not.to.eql(zoom);
center = map.getCenter();
zoom = map.getZoom();
mouse.moveTo(220, 220, 0).moveBy(200, 0, 2000);
}
});

var f1 = hand.growFinger('touch');
var f2 = hand.growFinger('touch');

hand.sync(5);
f1.wait(100).moveTo(275, 300, 0)
.down().moveBy(-200, 0, 1000).up(200);
// This finger should touch me map after the other one.
f2.wait(110).moveTo(325, 300, 0)
.down().moveBy(210, 0, 1000).up(200);

});

});

});
17 changes: 16 additions & 1 deletion src/dom/Draggable.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ L.Draggable = L.Evented.extend({
},

_onDown: function (e) {
// Ignore simulated events, since we handle both touch and
// mouse explicitly; otherwise we risk getting duplicates of
// touch events, see #4315.
if (e._simulated) { return; }

this._moved = false;

if (L.DomUtil.hasClass(this._element, 'leaflet-zoom-anim')) { return; }
Expand Down Expand Up @@ -100,6 +105,11 @@ L.Draggable = L.Evented.extend({
},

_onMove: function (e) {
// Ignore simulated events, since we handle both touch and
// mouse explicitly; otherwise we risk getting duplicates of
// touch events, see #4315.
if (e._simulated) { return; }

if (e.touches && e.touches.length > 1) {
this._moved = true;
return;
Expand Down Expand Up @@ -155,7 +165,12 @@ L.Draggable = L.Evented.extend({
this.fire('drag', e);
},

_onUp: function () {
_onUp: function (e) {
// Ignore simulated events, since we handle both touch and
// mouse explicitly; otherwise we risk getting duplicates of
// touch events, see #4315.
if (e._simulated) { return; }

L.DomUtil.removeClass(document.body, 'leaflet-dragging');

if (this._lastTarget) {
Expand Down

0 comments on commit fcffa30

Please sign in to comment.