From 3a4f9a139bb651883086231a361eea865d0beb7d Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 23 Feb 2018 10:18:23 -0800 Subject: [PATCH] Inline fire{Mouse,Touch}Event --- src/ui/bind_handlers.js | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/src/ui/bind_handlers.js b/src/ui/bind_handlers.js index 7db2f41645e..8c655f25f8b 100644 --- a/src/ui/bind_handlers.js +++ b/src/ui/bind_handlers.js @@ -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; @@ -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) { @@ -83,7 +80,7 @@ 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) { @@ -91,7 +88,11 @@ module.exports = function bindHandlers(map: Map, options: {}) { 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) { @@ -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) { @@ -140,7 +141,7 @@ 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; @@ -148,12 +149,4 @@ module.exports = function bindHandlers(map: Map, options: {}) { 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)); - } };