From: Tvrtko Date: Sat, 16 Jan 2016 20:10:07 +0000 (+0100) Subject: use MouseEvent constructor to simulate touch events. X-Git-Tag: v6.1.2~48^2^2 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F7898%2Fhead;p=thirdparty%2Ffoundation%2Ffoundation-sites.git use MouseEvent constructor to simulate touch events. simulating event with .initMouseEvent still available for browsers not supporting MouseEvent --- 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); }; };