update events

This commit is contained in:
Luke Pulverenti 2016-08-07 15:43:52 -04:00
parent 08c6ef7935
commit 0e0fa54547
17 changed files with 140 additions and 141 deletions

View file

@ -1,30 +1,4 @@
define(['browser', 'layoutManager', 'scrollStyles'], function (browser, layoutManager) {
var supportsCaptureOption = false;
try {
var opts = Object.defineProperty({}, 'capture', {
get: function () {
supportsCaptureOption = true;
}
});
window.addEventListener("test", null, opts);
} catch (e) { }
function addEventListenerWithOptions(target, type, handler, options) {
var optionsOrCapture = options;
if (!supportsCaptureOption) {
optionsOrCapture = options.capture;
}
target.addEventListener(type, handler, optionsOrCapture);
}
function removeEventListenerWithOptions(target, type, handler, options) {
var optionsOrCapture = options;
if (!supportsCaptureOption) {
optionsOrCapture = options.capture;
}
target.removeEventListener(type, handler, optionsOrCapture);
}
define(['browser', 'layoutManager', 'dom', 'scrollStyles'], function (browser, layoutManager, dom) {
/**
* Return type of the value.
@ -102,13 +76,9 @@ define(['browser', 'layoutManager', 'scrollStyles'], function (browser, layoutMa
var namespace = pluginName;
// Other global values
var dragInitEventNames = ['touchstart', 'mousedown'];
var dragInitEvents = 'touchstart.' + namespace + ' mousedown.' + namespace;
var dragMouseEvents = ['mousemove', 'mouseup'];
var dragTouchEvents = ['touchmove', 'touchend'];
var wheelEvent = (document.implementation.hasFeature('Event.wheel', '3.0') ? 'wheel' : 'mousewheel');
var clickEvent = 'click.' + namespace;
var mouseDownEvent = 'mousedown.' + namespace;
var interactiveElements = ['INPUT', 'SELECT', 'TEXTAREA'];
var tmpArray = [];
var time;
@ -926,14 +896,20 @@ define(['browser', 'layoutManager', 'scrollStyles'], function (browser, layoutMa
window.removeEventListener('resize', onResize, true);
// Reset native FRAME element scroll
removeEventListenerWithOptions(frameElement, 'scroll', resetScroll, {
dom.removeEventListener(frameElement, 'scroll', resetScroll, {
passive: true
});
removeEventListenerWithOptions(scrollSource, wheelEvent, scrollHandler, {
dom.removeEventListener(scrollSource, wheelEvent, scrollHandler, {
passive: true
});
dom.removeEventListener(dragSourceElement, 'touchstart', dragInitSlidee, {
passive: true
});
dragSourceElement.removeEventListener('mousedown', dragInitSlidee);
// Reset initialized status and return the instance
self.initialized = 0;
return self;
@ -991,22 +967,24 @@ define(['browser', 'layoutManager', 'scrollStyles'], function (browser, layoutMa
}
if (transform) {
dragInitEventNames.forEach(function (eventName) {
dragSourceElement.addEventListener(eventName, dragInitSlidee);
dom.addEventListener(dragSourceElement, 'touchstart', dragInitSlidee, {
passive: true
});
dragSourceElement.addEventListener('mousedown', dragInitSlidee);
if (!o.scrollWidth) {
window.addEventListener('resize', onResize, true);
}
if (!o.horizontal) {
addEventListenerWithOptions(frameElement, 'scroll', resetScroll, {
dom.addEventListener(frameElement, 'scroll', resetScroll, {
passive: true
});
}
// Scrolling navigation
addEventListenerWithOptions(scrollSource, wheelEvent, scrollHandler, {
dom.addEventListener(scrollSource, wheelEvent, scrollHandler, {
passive: true
});
@ -1015,7 +993,7 @@ define(['browser', 'layoutManager', 'scrollStyles'], function (browser, layoutMa
// Don't bind to mouse events with vertical scroll since the mouse wheel can handle this natively
// Scrolling navigation
addEventListenerWithOptions(scrollSource, wheelEvent, scrollHandler, {
dom.addEventListener(scrollSource, wheelEvent, scrollHandler, {
passive: true
});
}