zhuguifei
2025-07-04 186d172fc06dfe44dc2a61d238356e6a7db652d5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import onTouchStart from './onTouchStart.js';
import onTouchMove from './onTouchMove.js';
import onTouchEnd from './onTouchEnd.js';
import onResize from './onResize.js';
import onClick from './onClick.js';
import onScroll from './onScroll.js';
let dummyEventAttached = false;
 
function dummyEventListener() {}
 
const events = (swiper, method) => {
    const {
        params,
        touchEvents,
        wrapperEl,
        device,
        support
    } = swiper;
    let el = swiper.native;
    const capture = !!params.nested;
    const domMethod = method === 'on' ? 'on' : 'off';
    const swiperMethod = method;
    if (!support.touch) {
        let desktopMethod = method === 'on' ? 'addEventListener' : 'removeEventListener';
        if (document.querySelector(`#${swiper.$el.swiperElId}`)) {
            document.querySelector(`#${swiper.$el.swiperElId}`)[desktopMethod](touchEvents.start, swiper
                .onTouchStart,
                false);
        }
        document[desktopMethod](touchEvents.move, swiper.onTouchMove, capture);
        document[desktopMethod](touchEvents.end, swiper.onTouchEnd, false);
    } else {
        const passiveListener = touchEvents.start === 'touchstart' && support.passiveListener && params
            .passiveListeners ? {
                passive: true,
                capture: false
            } : false;
    }
};
 
function attachEvents() {
    const swiper = this;
    const {
        params,
        support
    } = swiper;
    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);
 
    events(swiper, 'on');
}
 
function detachEvents() {
    const swiper = this;
    events(swiper, 'off');
}
 
export default {
    attachEvents,
    detachEvents
};