vendor: 6,259 bytes, lines 1-200
1import { c as createElementIfNotDefined } from '../shared/create-element-if-not-defined.mjs'; 2import { m as makeElementsArray } from '../shared/utils.mjs'; 3 4function Navigation(_ref) { 5 let { 6 swiper, 7 extendParams, 8 on, 9 emit 10 } = _ref; 11 extendParams({ 12 navigation: { 13 nextEl: null, 14 prevEl: null, 15 hideOnClick: false, 16 disabledClass: 'swiper-button-disabled', 17 hiddenClass: 'swiper-button-hidden', 18 lockClass: 'swiper-button-lock', 19 navigationDisabledClass: 'swiper-navigation-disabled' 20 } 21 }); 22 swiper.navigation = { 23 nextEl: null, 24 prevEl: null 25 }; 26 function getEl(el) { 27 let res; 28 if (el && typeof el === 'string' && swiper.isElement) { 29 res = swiper.el.querySelector(el); 30 if (res) return res; 31 } 32 if (el) { 33 if (typeof el === 'string') res = [...document.querySelectorAll(el)]; 34 if (swiper.params.uniqueNavElements && typeof el === 'string' && res && res.length > 1 && swiper.el.querySelectorAll(el).length === 1) { 35 res = swiper.el.querySelector(el); 36 } else if (res && res.length === 1) { 37 res = res[0]; 38 } 39 } 40 if (el && !res) return el; 41 // if (Array.isArray(res) && res.length === 1) res = res[0]; 42 return res; 43 } 44 function toggleEl(el, disabled) { 45 const params = swiper.params.navigation; 46 el = makeElementsArray(el); 47 el.forEach(subEl => { 48 if (subEl) { 49 subEl.classList[disabled ? 'add' : 'remove'](...params.disabledClass.split(' ')); 50 if (subEl.tagName === 'BUTTON') subEl.disabled = disabled; 51 if (swiper.params.watchOverflow && swiper.enabled) { 52 subEl.classList[swiper.isLocked ? 'add' : 'remove'](params.lockClass); 53 } 54 } 55 }); 56 } 57 function update() { 58 // Update Navigation Buttons 59 const { 60 nextEl, 61 prevEl 62 } = swiper.navigation; 63 if (swiper.params.loop) { 64 toggleEl(prevEl, false); 65 toggleEl(nextEl, false); 66 return; 67 } 68 toggleEl(prevEl, swiper.isBeginning && !swiper.params.rewind); 69 toggleEl(nextEl, swiper.isEnd && !swiper.params.rewind); 70 } 71 function onPrevClick(e) { 72 e.preventDefault(); 73 if (swiper.isBeginning && !swiper.params.loop && !swiper.params.rewind) return; 74 swiper.slidePrev(); 75 emit('navigationPrev'); 76 } 77 function onNextClick(e) { 78 e.preventDefault(); 79 if (swiper.isEnd && !swiper.params.loop && !swiper.params.rewind) return; 80 swiper.slideNext(); 81 emit('navigationNext'); 82 } 83 function init() { 84 const params = swiper.params.navigation; 85 swiper.params.navigation = createElementIfNotDefined(swiper, swiper.originalParams.navigation, swiper.params.navigation, { 86 nextEl: 'swiper-button-next', 87 prevEl: 'swiper-button-prev' 88 }); 89 if (!(params.nextEl || params.prevEl)) return; 90 let nextEl = getEl(params.nextEl); 91 let prevEl = getEl(params.prevEl); 92 Object.assign(swiper.navigation, { 93 nextEl, 94 prevEl 95 }); 96 nextEl = makeElementsArray(nextEl); 97 prevEl = makeElementsArray(prevEl); 98 const initButton = (el, dir) => { 99 if (el) { 100 el.addEventListener('click', dir === 'next' ? onNextClick : onPrevClick); 101 } 102 if (!swiper.enabled && el) { 103 el.classList.add(...params.lockClass.split(' ')); 104 } 105 }; 106 nextEl.forEach(el => initButton(el, 'next')); 107 prevEl.forEach(el => initButton(el, 'prev')); 108 } 109 function destroy() { 110 let { 111 nextEl, 112 prevEl 113 } = swiper.navigation; 114 nextEl = makeElementsArray(nextEl); 115 prevEl = makeElementsArray(prevEl); 116 const destroyButton = (el, dir) => { 117 el.removeEventListener('click', dir === 'next' ? onNextClick : onPrevClick); 118 el.classList.remove(...swiper.params.navigation.disabledClass.split(' ')); 119 }; 120 nextEl.forEach(el => destroyButton(el, 'next')); 121 prevEl.forEach(el => destroyButton(el, 'prev')); 122 } 123 on('init', () => { 124 if (swiper.params.navigation.enabled === false) { 125 // eslint-disable-next-line 126 disable(); 127 } else { 128 init(); 129 update(); 130 } 131 }); 132 on('toEdge fromEdge lock unlock', () => { 133 update(); 134 }); 135 on('destroy', () => { 136 destroy(); 137 }); 138 on('enable disable', () => { 139 let { 140 nextEl, 141 prevEl 142 } = swiper.navigation; 143 nextEl = makeElementsArray(nextEl); 144 prevEl = makeElementsArray(prevEl); 145 if (swiper.enabled) { 146 update(); 147 return; 148 } 149 [...nextEl, ...prevEl].filter(el => !!el).forEach(el => el.classList.add(swiper.params.navigation.lockClass)); 150 }); 151 on('click', (_s, e) => { 152 let { 153 nextEl, 154 prevEl 155 } = swiper.navigation; 156 nextEl = makeElementsArray(nextEl); 157 prevEl = makeElementsArray(prevEl); 158 const targetEl = e.target; 159 let targetIsButton = prevEl.includes(targetEl) || nextEl.includes(targetEl); 160 if (swiper.isElement && !targetIsButton) { 161 const path = e.path || e.composedPath && e.composedPath(); 162 if (path) { 163 targetIsButton = path.find(pathEl => nextEl.includes(pathEl) || prevEl.includes(pathEl)); 164 } 165 } 166 if (swiper.params.navigation.hideOnClick && !targetIsButton) { 167 if (swiper.pagination && swiper.params.pagination && swiper.params.pagination.clickable && (swiper.pagination.el === targetEl || swiper.pagination.el.contains(targetEl))) return; 168 let isHidden; 169 if (nextEl.length) { 170 isHidden = nextEl[0].classList.contains(swiper.params.navigation.hiddenClass); 171 } else if (prevEl.length) { 172 isHidden = prevEl[0].classList.contains(swiper.params.navigation.hiddenClass); 173 } 174 if (isHidden === true) { 175 emit('navigationShow'); 176 } else { 177 emit('navigationHide'); 178 } 179 [...nextEl, ...prevEl].filter(el => !!el).forEach(el => el.classList.toggle(swiper.params.navigation.hiddenClass)); 180 } 181 }); 182 const enable = () => { 183 swiper.el.classList.remove(...swiper.params.navigation.navigationDisabledClass.split(' ')); 184 init(); 185 update(); 186 }; 187 const disable = () => { 188 swiper.el.classList.add(...swiper.params.navigation.navigationDisabledClass.split(' ')); 189 destroy(); 190 }; 191 Object.assign(swiper.navigation, { 192 enable, 193 disable, 194 update, 195 init, 196 destroy 197 }); 198} 199 200export { Navigation as default };
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.