Skip to content

Commit

Permalink
Merge pull request #111 from 2gis/fix/firefox-mouseup-bug
Browse files Browse the repository at this point in the history
Залипает драг в IE и FF
  • Loading branch information
andymost committed Dec 22, 2014
2 parents 7ac70f7 + a422c1f commit 60471e2
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"eqnull": false,
"evil": false,
"expr": true,
"forin": true,
"forin": false,
"immed": true,
"latedef": true,
"loopfunc": false,
Expand Down
65 changes: 65 additions & 0 deletions src/DGCustomization/src/DGCustomization.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,68 @@ DG.Map.addInitHook(function () {

// Add some browser detection
DG.Browser.safari51 = DG.Browser.safari && navigator.userAgent.indexOf('Version/5.1') !== -1;

// Fix for https://github.com/2gis/mapsapi/issues/111 , remove on the next leaflet version
L.Draggable.include({
_onMove: function (e) {
if (e.touches && e.touches.length > 1) {
this._moved = true;
return;
}

var first = (e.touches && e.touches.length === 1 ? e.touches[0] : e),
newPoint = new L.Point(first.clientX, first.clientY),
offset = newPoint.subtract(this._startPoint);

if (!offset.x && !offset.y) { return; }
if (L.Browser.touch && Math.abs(offset.x) + Math.abs(offset.y) < 3) { return; }

L.DomEvent.preventDefault(e);

if (!this._moved) {
this.fire('dragstart');

this._moved = true;
this._startPos = L.DomUtil.getPosition(this._element).subtract(offset);

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

this._lastTarget = e.target || e.srcElement;
L.DomUtil.addClass(this._lastTarget, 'leaflet-drag-target');
}

this._newPos = this._startPos.add(offset);
this._moving = true;

L.Util.cancelAnimFrame(this._animRequest);
this._animRequest = L.Util.requestAnimFrame(this._updatePosition, this, true, this._dragStartTarget);
},
_onUp: function () {
L.DomUtil.removeClass(document.body, 'leaflet-dragging');

if (this._lastTarget) {
L.DomUtil.removeClass(this._lastTarget, 'leaflet-drag-target');
this._lastTarget = null;
}

for (var i in L.Draggable.MOVE) {
L.DomEvent
.off(document, L.Draggable.MOVE[i], this._onMove, this)
.off(document, L.Draggable.END[i], this._onUp, this);
}

L.DomUtil.enableImageDrag();
L.DomUtil.enableTextSelection();

if (this._moved && this._moving) {
// ensure drag is not fired after dragend
L.Util.cancelAnimFrame(this._animRequest);

this.fire('dragend', {
distance: this._newPos.distanceTo(this._startPos)
});
}

this._moving = false;
}
});

0 comments on commit 60471e2

Please sign in to comment.