From 0afd7ca1a77097f70a66024afb9fbd48e40d8dd8 Mon Sep 17 00:00:00 2001 From: Tvrtko Date: Sat, 16 Jan 2016 21:10:07 +0100 Subject: [PATCH] use MouseEvent constructor to simulate touch events. simulating event with .initMouseEvent still available for browsers not supporting MouseEvent --- js/foundation.util.touch.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/js/foundation.util.touch.js b/js/foundation.util.touch.js index 236cdce4e..9a7c9e3c6 100644 --- a/js/foundation.util.touch.js +++ b/js/foundation.util.touch.js @@ -96,10 +96,23 @@ touchmove: 'mousemove', touchend: 'mouseup' }, - type = eventTypes[event.type]; - - var simulatedEvent = document.createEvent('MouseEvent'); - simulatedEvent.initMouseEvent(type, true, true, window, 1, first.screenX, first.screenY, first.clientX, first.clientY, false, false, false, false, 0/*left*/, null); + type = eventTypes[event.type], + simulatedEvent + ; + + if('MouseEvent' in window && typeof window.MouseEvent === 'function') { + simulatedEvent = window.MouseEvent(type, { + 'bubbles': true, + 'cancelable': true, + 'screenX': first.screenX, + 'screenY': first.screenY, + 'clientX': first.clientX, + 'clientY': first.clientY + }); + } else { + simulatedEvent = document.createEvent('MouseEvent'); + simulatedEvent.initMouseEvent(type, true, true, window, 1, first.screenX, first.screenY, first.clientX, first.clientY, false, false, false, false, 0/*left*/, null); + } first.target.dispatchEvent(simulatedEvent); }; }; -- 2.47.2