]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
use MouseEvent constructor to simulate touch events. 7898/head
authorTvrtko <tvrtkom@gmail.com>
Sat, 16 Jan 2016 20:10:07 +0000 (21:10 +0100)
committerTvrtko <tvrtkom@gmail.com>
Sat, 16 Jan 2016 20:10:07 +0000 (21:10 +0100)
simulating event with .initMouseEvent still available for browsers not supporting MouseEvent

js/foundation.util.touch.js

index 236cdce4ef57c0cacfabc725f02992fec51bef82..9a7c9e3c62357932a266e79e9e23314a1b431755 100644 (file)
             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);
     };
   };