Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (Support.touch) {
const passiveListener = touchEvents.start === 'touchstart' && Support.passiveListener && params.passiveListeners ? { passive: true, capture: false } : false;
el.addEventListener(touchEvents.start, swiper.onTouchStart, passiveListener);
el.addEventListener(touchEvents.move, swiper.onTouchMove, Support.passiveListener ? { passive: false, capture } : capture);
el.addEventListener(touchEvents.end, swiper.onTouchEnd, passiveListener);
if (touchEvents.cancel) {
el.addEventListener(touchEvents.cancel, swiper.onTouchEnd, passiveListener);
}
if (!dummyEventAttached) {
document.addEventListener('touchstart', dummyEventListener);
dummyEventAttached = true;
}
}
if ((params.simulateTouch && !Device.ios && !Device.android) || (params.simulateTouch && !Support.touch && Device.ios)) {
el.addEventListener('mousedown', swiper.onTouchStart, false);
document.addEventListener('mousemove', swiper.onTouchMove, capture);
document.addEventListener('mouseup', swiper.onTouchEnd, false);
}
}
// Prevent Links Clicks
if (params.preventClicks || params.preventClicksPropagation) {
el.addEventListener('click', swiper.onClick, true);
}
if (params.cssMode) {
wrapperEl.addEventListener('scroll', swiper.onScroll);
}
// Resize handler
if (params.updateOnWindowResize) {
swiper.on((Device.ios || Device.android ? 'resize orientationchange observerUpdate' : 'resize observerUpdate'), onResize, true);
} else {
swiper.on('observerUpdate', onResize, true);
swiper.onTouchStart = onTouchStart.bind(swiper);
swiper.onTouchMove = onTouchMove.bind(swiper);
swiper.onTouchEnd = onTouchEnd.bind(swiper);
if (params.cssMode) {
swiper.onScroll = onScroll.bind(swiper);
}
swiper.onClick = onClick.bind(swiper);
const capture = !!params.nested;
// Touch Events
if (!Support.touch && Support.pointerEvents) {
el.addEventListener(touchEvents.start, swiper.onTouchStart, false);
document.addEventListener(touchEvents.move, swiper.onTouchMove, capture);
document.addEventListener(touchEvents.end, swiper.onTouchEnd, false);
} else {
if (Support.touch) {
const passiveListener = touchEvents.start === 'touchstart' && Support.passiveListener && params.passiveListeners ? { passive: true, capture: false } : false;
el.addEventListener(touchEvents.start, swiper.onTouchStart, passiveListener);
el.addEventListener(touchEvents.move, swiper.onTouchMove, Support.passiveListener ? { passive: false, capture } : capture);
el.addEventListener(touchEvents.end, swiper.onTouchEnd, passiveListener);
if (touchEvents.cancel) {
el.addEventListener(touchEvents.cancel, swiper.onTouchEnd, passiveListener);
}
if (!dummyEventAttached) {
document.addEventListener('touchstart', dummyEventListener);
dummyEventAttached = true;
}
}
if ((params.simulateTouch && !Device.ios && !Device.android) || (params.simulateTouch && !Support.touch && Device.ios)) {
swiper.onTouchStart = onTouchStart.bind(swiper);
swiper.onTouchMove = onTouchMove.bind(swiper);
swiper.onTouchEnd = onTouchEnd.bind(swiper);
if (params.cssMode) {
swiper.onScroll = onScroll.bind(swiper);
}
swiper.onClick = onClick.bind(swiper);
const capture = !!params.nested;
// Touch Events
if (!Support.touch && Support.pointerEvents) {
el.addEventListener(touchEvents.start, swiper.onTouchStart, false);
document.addEventListener(touchEvents.move, swiper.onTouchMove, capture);
document.addEventListener(touchEvents.end, swiper.onTouchEnd, false);
} else {
if (Support.touch) {
const passiveListener = touchEvents.start === 'touchstart' && Support.passiveListener && params.passiveListeners ? { passive: true, capture: false } : false;
el.addEventListener(touchEvents.start, swiper.onTouchStart, passiveListener);
el.addEventListener(touchEvents.move, swiper.onTouchMove, Support.passiveListener ? { passive: false, capture } : capture);
el.addEventListener(touchEvents.end, swiper.onTouchEnd, passiveListener);
if (touchEvents.cancel) {
el.addEventListener(touchEvents.cancel, swiper.onTouchEnd, passiveListener);
}
if (!dummyEventAttached) {
document.addEventListener('touchstart', dummyEventListener);
dummyEventAttached = true;
}
}
if ((params.simulateTouch && !Device.ios && !Device.android) || (params.simulateTouch && !Support.touch && Device.ios)) {
el.addEventListener('mousedown', swiper.onTouchStart, false);
const passiveListener = Support.passiveListener ? { passive: true } : false;
const activeListener = Support.passiveListener ? { passive: false } : false;
document.addEventListener('click', appClick, true);
if (Support.passiveListener) {
document.addEventListener(app.touchEvents.start, appTouchStartActive, activeListener);
document.addEventListener(app.touchEvents.move, appTouchMoveActive, activeListener);
document.addEventListener(app.touchEvents.end, appTouchEndActive, activeListener);
document.addEventListener(app.touchEvents.start, appTouchStartPassive, passiveListener);
document.addEventListener(app.touchEvents.move, appTouchMovePassive, passiveListener);
document.addEventListener(app.touchEvents.end, appTouchEndPassive, passiveListener);
if (Support.touch && Support.gestures) {
document.addEventListener('gesturestart', appGestureActive, activeListener);
document.addEventListener('gesturechange', appGestureActive, activeListener);
document.addEventListener('gestureend', appGestureActive, activeListener);
document.addEventListener('gesturestart', appGesturePassive, passiveListener);
document.addEventListener('gesturechange', appGesturePassive, passiveListener);
document.addEventListener('gestureend', appGesturePassive, passiveListener);
}
} else {
document.addEventListener(app.touchEvents.start, (e) => {
appTouchStartActive(e);
appTouchStartPassive(e);
}, false);
document.addEventListener(app.touchEvents.move, (e) => {
appTouchMoveActive(e);
appTouchMovePassive(e);
}, false);
emitAppTouchEvent('touchend touchend:active', e);
}
function appTouchStartPassive(e) {
emitAppTouchEvent('touchstart:passive', e);
}
function appTouchMovePassive(e) {
emitAppTouchEvent('touchmove:passive', e);
}
function appTouchEndPassive(e) {
emitAppTouchEvent('touchend:passive', e);
}
const passiveListener = Support.passiveListener ? { passive: true } : false;
const activeListener = Support.passiveListener ? { passive: false } : false;
document.addEventListener('click', appClick, true);
if (Support.passiveListener) {
document.addEventListener(app.touchEvents.start, appTouchStartActive, activeListener);
document.addEventListener(app.touchEvents.move, appTouchMoveActive, activeListener);
document.addEventListener(app.touchEvents.end, appTouchEndActive, activeListener);
document.addEventListener(app.touchEvents.start, appTouchStartPassive, passiveListener);
document.addEventListener(app.touchEvents.move, appTouchMovePassive, passiveListener);
document.addEventListener(app.touchEvents.end, appTouchEndPassive, passiveListener);
} else {
document.addEventListener(app.touchEvents.start, (e) => {
appTouchStartActive(e);
appTouchStartPassive(e);
}, false);
document.addEventListener(app.touchEvents.move, (e) => {
appTouchMoveActive(e);
enableDraggable() {
const swiper = this;
if (!swiper.params.scrollbar.el) return;
const {
scrollbar, touchEventsTouch, touchEventsDesktop, params,
} = swiper;
const $el = scrollbar.$el;
const target = $el[0];
const activeListener = Support.passiveListener && params.passiveListeners ? { passive: false, capture: false } : false;
const passiveListener = Support.passiveListener && params.passiveListeners ? { passive: true, capture: false } : false;
if (!Support.touch) {
target.addEventListener(touchEventsDesktop.start, swiper.scrollbar.onDragStart, activeListener);
document.addEventListener(touchEventsDesktop.move, swiper.scrollbar.onDragMove, activeListener);
document.addEventListener(touchEventsDesktop.end, swiper.scrollbar.onDragEnd, passiveListener);
} else {
target.addEventListener(touchEventsTouch.start, swiper.scrollbar.onDragStart, activeListener);
target.addEventListener(touchEventsTouch.move, swiper.scrollbar.onDragMove, activeListener);
target.addEventListener(touchEventsTouch.end, swiper.scrollbar.onDragEnd, passiveListener);
}
},
disableDraggable() {
function appGestureActive(e) {
emitAppTouchEvent(`${e.type} ${e.type}:active`, e);
}
function appGesturePassive(e) {
emitAppTouchEvent(`${e.type}:passive`, e);
}
const passiveListener = Support.passiveListener ? { passive: true } : false;
const activeListener = Support.passiveListener ? { passive: false } : false;
document.addEventListener('click', appClick, true);
if (Support.passiveListener) {
document.addEventListener(app.touchEvents.start, appTouchStartActive, activeListener);
document.addEventListener(app.touchEvents.move, appTouchMoveActive, activeListener);
document.addEventListener(app.touchEvents.end, appTouchEndActive, activeListener);
document.addEventListener(app.touchEvents.start, appTouchStartPassive, passiveListener);
document.addEventListener(app.touchEvents.move, appTouchMovePassive, passiveListener);
document.addEventListener(app.touchEvents.end, appTouchEndPassive, passiveListener);
if (Support.touch && Support.gestures) {
document.addEventListener('gesturestart', appGestureActive, activeListener);
document.addEventListener('gesturechange', appGestureActive, activeListener);
document.addEventListener('gestureend', appGestureActive, activeListener);
document.addEventListener('gesturestart', appGesturePassive, passiveListener);
document.addEventListener('gesturechange', appGesturePassive, passiveListener);
document.addEventListener('gestureend', appGesturePassive, passiveListener);
}
} else {
document.addEventListener(app.touchEvents.start, (e) => {
document.addEventListener(app.touchEvents.end, appTouchEndActive, activeListener);
document.addEventListener(app.touchEvents.start, appTouchStartPassive, passiveListener);
document.addEventListener(app.touchEvents.move, appTouchMovePassive, passiveListener);
document.addEventListener(app.touchEvents.end, appTouchEndPassive, passiveListener);
if (Support.touch && Support.gestures) {
document.addEventListener('gesturestart', appGestureActive, activeListener);
document.addEventListener('gesturechange', appGestureActive, activeListener);
document.addEventListener('gestureend', appGestureActive, activeListener);
document.addEventListener('gesturestart', appGesturePassive, passiveListener);
document.addEventListener('gesturechange', appGesturePassive, passiveListener);
document.addEventListener('gestureend', appGesturePassive, passiveListener);
}
} else {
document.addEventListener(app.touchEvents.start, (e) => {
appTouchStartActive(e);
appTouchStartPassive(e);
}, false);
document.addEventListener(app.touchEvents.move, (e) => {
appTouchMoveActive(e);
appTouchMovePassive(e);
}, false);
document.addEventListener(app.touchEvents.end, (e) => {
appTouchEndActive(e);
appTouchEndPassive(e);
}, false);
if (Support.touch && Support.gestures) {
document.addEventListener('gesturestart', (e) => {
appGestureActive(e);
appGesturePassive(e);
}, false);
const activeListener = Support.passiveListener ? { passive: false } : false;
document.addEventListener('click', appClick, true);
if (Support.passiveListener) {
document.addEventListener(app.touchEvents.start, appTouchStartActive, activeListener);
document.addEventListener(app.touchEvents.move, appTouchMoveActive, activeListener);
document.addEventListener(app.touchEvents.end, appTouchEndActive, activeListener);
document.addEventListener(app.touchEvents.start, appTouchStartPassive, passiveListener);
document.addEventListener(app.touchEvents.move, appTouchMovePassive, passiveListener);
document.addEventListener(app.touchEvents.end, appTouchEndPassive, passiveListener);
if (Support.touch && Support.gestures) {
document.addEventListener('gesturestart', appGestureActive, activeListener);
document.addEventListener('gesturechange', appGestureActive, activeListener);
document.addEventListener('gestureend', appGestureActive, activeListener);
document.addEventListener('gesturestart', appGesturePassive, passiveListener);
document.addEventListener('gesturechange', appGesturePassive, passiveListener);
document.addEventListener('gestureend', appGesturePassive, passiveListener);
}
} else {
document.addEventListener(app.touchEvents.start, (e) => {
appTouchStartActive(e);
appTouchStartPassive(e);
}, false);
document.addEventListener(app.touchEvents.move, (e) => {
appTouchMoveActive(e);
appTouchMovePassive(e);
}, false);
document.addEventListener(app.touchEvents.end, (e) => {
appTouchEndActive(e);
emitAppTouchEvent(`${e.type} ${e.type}:active`, e);
}
function appGesturePassive(e) {
emitAppTouchEvent(`${e.type}:passive`, e);
}
const passiveListener = Support.passiveListener ? { passive: true } : false;
const activeListener = Support.passiveListener ? { passive: false } : false;
document.addEventListener('click', appClick, true);
if (Support.passiveListener) {
document.addEventListener(app.touchEvents.start, appTouchStartActive, activeListener);
document.addEventListener(app.touchEvents.move, appTouchMoveActive, activeListener);
document.addEventListener(app.touchEvents.end, appTouchEndActive, activeListener);
document.addEventListener(app.touchEvents.start, appTouchStartPassive, passiveListener);
document.addEventListener(app.touchEvents.move, appTouchMovePassive, passiveListener);
document.addEventListener(app.touchEvents.end, appTouchEndPassive, passiveListener);
if (Support.touch && Support.gestures) {
document.addEventListener('gesturestart', appGestureActive, activeListener);
document.addEventListener('gesturechange', appGestureActive, activeListener);
document.addEventListener('gestureend', appGestureActive, activeListener);
document.addEventListener('gesturestart', appGesturePassive, passiveListener);
document.addEventListener('gesturechange', appGesturePassive, passiveListener);
document.addEventListener('gestureend', appGesturePassive, passiveListener);
}
} else {
document.addEventListener(app.touchEvents.start, (e) => {
appTouchStartActive(e);