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

Forward original event on drag #3264

Merged
merged 2 commits into from
Mar 2, 2015
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
Forward original event on drag
  • Loading branch information
yohanboniface committed Feb 27, 2015
commit 66654b94ebe0c235309dd6960e0e738ccfebe4c3
11 changes: 7 additions & 4 deletions src/dom/Draggable.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,16 @@ L.Draggable = L.Evented.extend({
this._moving = true;

L.Util.cancelAnimFrame(this._animRequest);
this._animRequest = L.Util.requestAnimFrame(this._updatePosition, this, true, this._dragStartTarget);
var animationCallback = function () {
this._updatePosition(e);
};
this._animRequest = L.Util.requestAnimFrame(animationCallback, this, true, this._dragStartTarget);
Copy link
Member

Choose a reason for hiding this comment

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

You can use L.bind(animationCallback, null, e) instead. Or this._lastEvent to avoid closure entirely.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point!
Which one do you prefer?

Copy link
Member Author

Choose a reason for hiding this comment

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

Latest (this._lastEvent) may be more readable, given that we are already passing a buntch of arguments to requestAnimFrame.

},

_updatePosition: function () {
this.fire('predrag');
_updatePosition: function (e) {
this.fire('predrag', e);
L.DomUtil.setPosition(this._element, this._newPos);
this.fire('drag');
this.fire('drag', e);
},

_onUp: function () {
Expand Down
7 changes: 4 additions & 3 deletions src/layer/marker/Marker.Drag.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ L.Handler.MarkerDrag = L.Handler.extend({
.fire('dragstart');
},

_onDrag: function () {
_onDrag: function (e) {
var marker = this._marker,
shadow = marker._shadow,
iconPos = L.DomUtil.getPosition(marker._icon),
Expand All @@ -58,10 +58,11 @@ L.Handler.MarkerDrag = L.Handler.extend({
}

marker._latlng = latlng;
e.latlng = latlng;

marker
.fire('move', {latlng: latlng})
.fire('drag');
.fire('move', e)
Copy link
Member

Choose a reason for hiding this comment

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

I don't like modified DOM event being passed as event data... In a similar situation in other place of Leaflet code, original event is passed as e.originalEvent.

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 originally done that, but then changed my mind, finding this version lighter, but I'll do that then :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Also, as we are doing two forwards, I'm not sure at which step we should introduce the originalEvent key ;)

Copy link
Member

Choose a reason for hiding this comment

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

Probably at the start.

.fire('drag', e);
},

_onDragEnd: function (e) {
Expand Down
6 changes: 3 additions & 3 deletions src/map/handler/Map.Drag.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ L.Map.Drag = L.Handler.extend({
}
},

_onDrag: function () {
_onDrag: function (e) {
if (this._map.options.inertia) {
var time = this._lastTime = +new Date(),
pos = this._lastPos = this._draggable._absPos || this._draggable._newPos;
Expand All @@ -78,8 +78,8 @@ L.Map.Drag = L.Handler.extend({
}

this._map
.fire('move')
.fire('drag');
.fire('move', e)
.fire('drag', e);
},

_onViewReset: function () {
Expand Down