Skip to content

Commit

Permalink
Inline fire{Mouse,Touch}Event
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Feb 23, 2018
1 parent c700592 commit 3a4f9a1
Showing 1 changed file with 14 additions and 21 deletions.
35 changes: 14 additions & 21 deletions src/ui/bind_handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ module.exports = function bindHandlers(map: Map, options: {}) {
el.addEventListener('dblclick', onDblClick, false);
el.addEventListener('contextmenu', onContextMenu, false);

function onMouseOut(e: MouseEvent) {
fireMouseEvent('mouseout', e);
}

function onMouseDown(e: MouseEvent) {
mouseDown = true;

Expand All @@ -67,12 +63,13 @@ module.exports = function bindHandlers(map: Map, options: {}) {

if (contextMenuEvent && !rotating) {
// This will be the case for Mac
fireMouseEvent('contextmenu', contextMenuEvent);
map.fire(new MapMouseEvent('contextmenu', map, contextMenuEvent));
}

contextMenuEvent = null;
mouseDown = false;
fireMouseEvent('mouseup', e);

map.fire(new MapMouseEvent('mouseup', map, e));
}

function onMouseMove(e: MouseEvent) {
Expand All @@ -83,15 +80,19 @@ module.exports = function bindHandlers(map: Map, options: {}) {
while (target && target !== el) target = target.parentNode;
if (target !== el) return;

fireMouseEvent('mousemove', e);
map.fire(new MapMouseEvent('mousemove', map, e));
}

function onMouseOver(e: MouseEvent) {
let target: any = e.toElement || e.target;
while (target && target !== el) target = target.parentNode;
if (target !== el) return;

fireMouseEvent('mouseover', e);
map.fire(new MapMouseEvent('mouseover', map, e));
}

function onMouseOut(e: MouseEvent) {
map.fire(new MapMouseEvent('mouseout', map, e));
}

function onTouchStart(e: TouchEvent) {
Expand All @@ -110,19 +111,19 @@ module.exports = function bindHandlers(map: Map, options: {}) {
}

function onTouchMove(e: TouchEvent) {
fireTouchEvent('touchmove', e);
map.fire(new MapTouchEvent('touchmove', map, e));
}

function onTouchEnd(e: TouchEvent) {
fireTouchEvent('touchend', e);
map.fire(new MapTouchEvent('touchend', map, e));
}

function onTouchCancel(e: TouchEvent) {
fireTouchEvent('touchcancel', e);
map.fire(new MapTouchEvent('touchcancel', map, e));
}

function onClick(e: MouseEvent) {
fireMouseEvent('click', e);
map.fire(new MapMouseEvent('click', map, e));
}

function onDblClick(e: MouseEvent) {
Expand All @@ -140,20 +141,12 @@ module.exports = function bindHandlers(map: Map, options: {}) {
const rotating = map.dragRotate.isActive();
if (!mouseDown && !rotating) {
// Windows: contextmenu fired on mouseup, so fire event now
fireMouseEvent('contextmenu', e);
map.fire(new MapMouseEvent('contextmenu', map, e));
} else if (mouseDown) {
// Mac: contextmenu fired on mousedown; we save it until mouseup for consistency's sake
contextMenuEvent = e;
}

e.preventDefault();
}

function fireMouseEvent(type: string, originalEvent: MouseEvent) {
map.fire(new MapMouseEvent(type, map, originalEvent));
}

function fireTouchEvent(type: string, originalEvent: TouchEvent) {
map.fire(new MapTouchEvent(type, map, originalEvent));
}
};

0 comments on commit 3a4f9a1

Please sign in to comment.