1 | "use strict";
|
2 |
|
3 | exports.__esModule = true;
|
4 | exports.default = void 0;
|
5 |
|
6 | var _dom = _interopRequireDefault(require("../../utils/dom"));
|
7 |
|
8 | var _utils = require("../../utils/utils");
|
9 |
|
10 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
11 |
|
12 | function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
13 |
|
14 | var Pagination = {
|
15 | update: function update() {
|
16 |
|
17 | var swiper = this;
|
18 | var rtl = swiper.rtl;
|
19 | var params = swiper.params.pagination;
|
20 | if (!params.el || !swiper.pagination.el || !swiper.pagination.$el || swiper.pagination.$el.length === 0) return;
|
21 | var slidesLength = swiper.virtual && swiper.params.virtual.enabled ? swiper.virtual.slides.length : swiper.slides.length;
|
22 | var $el = swiper.pagination.$el;
|
23 |
|
24 | var current;
|
25 | var total = swiper.params.loop ? Math.ceil((slidesLength - swiper.loopedSlides * 2) / swiper.params.slidesPerGroup) : swiper.snapGrid.length;
|
26 |
|
27 | if (swiper.params.loop) {
|
28 | current = Math.ceil((swiper.activeIndex - swiper.loopedSlides) / swiper.params.slidesPerGroup);
|
29 |
|
30 | if (current > slidesLength - 1 - swiper.loopedSlides * 2) {
|
31 | current -= slidesLength - swiper.loopedSlides * 2;
|
32 | }
|
33 |
|
34 | if (current > total - 1) current -= total;
|
35 | if (current < 0 && swiper.params.paginationType !== 'bullets') current = total + current;
|
36 | } else if (typeof swiper.snapIndex !== 'undefined') {
|
37 | current = swiper.snapIndex;
|
38 | } else {
|
39 | current = swiper.activeIndex || 0;
|
40 | }
|
41 |
|
42 |
|
43 | if (params.type === 'bullets' && swiper.pagination.bullets && swiper.pagination.bullets.length > 0) {
|
44 | var bullets = swiper.pagination.bullets;
|
45 | var firstIndex;
|
46 | var lastIndex;
|
47 | var midIndex;
|
48 |
|
49 | if (params.dynamicBullets) {
|
50 | swiper.pagination.bulletSize = bullets.eq(0)[swiper.isHorizontal() ? 'outerWidth' : 'outerHeight'](true);
|
51 | $el.css(swiper.isHorizontal() ? 'width' : 'height', swiper.pagination.bulletSize * (params.dynamicMainBullets + 4) + "px");
|
52 |
|
53 | if (params.dynamicMainBullets > 1 && swiper.previousIndex !== undefined) {
|
54 | swiper.pagination.dynamicBulletIndex += current - swiper.previousIndex;
|
55 |
|
56 | if (swiper.pagination.dynamicBulletIndex > params.dynamicMainBullets - 1) {
|
57 | swiper.pagination.dynamicBulletIndex = params.dynamicMainBullets - 1;
|
58 | } else if (swiper.pagination.dynamicBulletIndex < 0) {
|
59 | swiper.pagination.dynamicBulletIndex = 0;
|
60 | }
|
61 | }
|
62 |
|
63 | firstIndex = current - swiper.pagination.dynamicBulletIndex;
|
64 | lastIndex = firstIndex + (Math.min(bullets.length, params.dynamicMainBullets) - 1);
|
65 | midIndex = (lastIndex + firstIndex) / 2;
|
66 | }
|
67 |
|
68 | bullets.removeClass(params.bulletActiveClass + " " + params.bulletActiveClass + "-next " + params.bulletActiveClass + "-next-next " + params.bulletActiveClass + "-prev " + params.bulletActiveClass + "-prev-prev " + params.bulletActiveClass + "-main");
|
69 |
|
70 | if ($el.length > 1) {
|
71 | bullets.each(function (bullet) {
|
72 | var $bullet = (0, _dom.default)(bullet);
|
73 | var bulletIndex = $bullet.index();
|
74 |
|
75 | if (bulletIndex === current) {
|
76 | $bullet.addClass(params.bulletActiveClass);
|
77 | }
|
78 |
|
79 | if (params.dynamicBullets) {
|
80 | if (bulletIndex >= firstIndex && bulletIndex <= lastIndex) {
|
81 | $bullet.addClass(params.bulletActiveClass + "-main");
|
82 | }
|
83 |
|
84 | if (bulletIndex === firstIndex) {
|
85 | $bullet.prev().addClass(params.bulletActiveClass + "-prev").prev().addClass(params.bulletActiveClass + "-prev-prev");
|
86 | }
|
87 |
|
88 | if (bulletIndex === lastIndex) {
|
89 | $bullet.next().addClass(params.bulletActiveClass + "-next").next().addClass(params.bulletActiveClass + "-next-next");
|
90 | }
|
91 | }
|
92 | });
|
93 | } else {
|
94 | var $bullet = bullets.eq(current);
|
95 | var bulletIndex = $bullet.index();
|
96 | $bullet.addClass(params.bulletActiveClass);
|
97 |
|
98 | if (params.dynamicBullets) {
|
99 | var $firstDisplayedBullet = bullets.eq(firstIndex);
|
100 | var $lastDisplayedBullet = bullets.eq(lastIndex);
|
101 |
|
102 | for (var i = firstIndex; i <= lastIndex; i += 1) {
|
103 | bullets.eq(i).addClass(params.bulletActiveClass + "-main");
|
104 | }
|
105 |
|
106 | if (swiper.params.loop) {
|
107 | if (bulletIndex >= bullets.length - params.dynamicMainBullets) {
|
108 | for (var _i = params.dynamicMainBullets; _i >= 0; _i -= 1) {
|
109 | bullets.eq(bullets.length - _i).addClass(params.bulletActiveClass + "-main");
|
110 | }
|
111 |
|
112 | bullets.eq(bullets.length - params.dynamicMainBullets - 1).addClass(params.bulletActiveClass + "-prev");
|
113 | } else {
|
114 | $firstDisplayedBullet.prev().addClass(params.bulletActiveClass + "-prev").prev().addClass(params.bulletActiveClass + "-prev-prev");
|
115 | $lastDisplayedBullet.next().addClass(params.bulletActiveClass + "-next").next().addClass(params.bulletActiveClass + "-next-next");
|
116 | }
|
117 | } else {
|
118 | $firstDisplayedBullet.prev().addClass(params.bulletActiveClass + "-prev").prev().addClass(params.bulletActiveClass + "-prev-prev");
|
119 | $lastDisplayedBullet.next().addClass(params.bulletActiveClass + "-next").next().addClass(params.bulletActiveClass + "-next-next");
|
120 | }
|
121 | }
|
122 | }
|
123 |
|
124 | if (params.dynamicBullets) {
|
125 | var dynamicBulletsLength = Math.min(bullets.length, params.dynamicMainBullets + 4);
|
126 | var bulletsOffset = (swiper.pagination.bulletSize * dynamicBulletsLength - swiper.pagination.bulletSize) / 2 - midIndex * swiper.pagination.bulletSize;
|
127 | var offsetProp = rtl ? 'right' : 'left';
|
128 | bullets.css(swiper.isHorizontal() ? offsetProp : 'top', bulletsOffset + "px");
|
129 | }
|
130 | }
|
131 |
|
132 | if (params.type === 'fraction') {
|
133 | $el.find((0, _utils.classesToSelector)(params.currentClass)).text(params.formatFractionCurrent(current + 1));
|
134 | $el.find((0, _utils.classesToSelector)(params.totalClass)).text(params.formatFractionTotal(total));
|
135 | }
|
136 |
|
137 | if (params.type === 'progressbar') {
|
138 | var progressbarDirection;
|
139 |
|
140 | if (params.progressbarOpposite) {
|
141 | progressbarDirection = swiper.isHorizontal() ? 'vertical' : 'horizontal';
|
142 | } else {
|
143 | progressbarDirection = swiper.isHorizontal() ? 'horizontal' : 'vertical';
|
144 | }
|
145 |
|
146 | var scale = (current + 1) / total;
|
147 | var scaleX = 1;
|
148 | var scaleY = 1;
|
149 |
|
150 | if (progressbarDirection === 'horizontal') {
|
151 | scaleX = scale;
|
152 | } else {
|
153 | scaleY = scale;
|
154 | }
|
155 |
|
156 | $el.find((0, _utils.classesToSelector)(params.progressbarFillClass)).transform("translate3d(0,0,0) scaleX(" + scaleX + ") scaleY(" + scaleY + ")").transition(swiper.params.speed);
|
157 | }
|
158 |
|
159 | if (params.type === 'custom' && params.renderCustom) {
|
160 | $el.html(params.renderCustom(swiper, current + 1, total));
|
161 | swiper.emit('paginationRender', $el[0]);
|
162 | } else {
|
163 | swiper.emit('paginationUpdate', $el[0]);
|
164 | }
|
165 |
|
166 | $el[swiper.params.watchOverflow && swiper.isLocked ? 'addClass' : 'removeClass'](params.lockClass);
|
167 | },
|
168 | render: function render() {
|
169 |
|
170 | var swiper = this;
|
171 | var params = swiper.params.pagination;
|
172 | if (!params.el || !swiper.pagination.el || !swiper.pagination.$el || swiper.pagination.$el.length === 0) return;
|
173 | var slidesLength = swiper.virtual && swiper.params.virtual.enabled ? swiper.virtual.slides.length : swiper.slides.length;
|
174 | var $el = swiper.pagination.$el;
|
175 | var paginationHTML = '';
|
176 |
|
177 | if (params.type === 'bullets') {
|
178 | var numberOfBullets = swiper.params.loop ? Math.ceil((slidesLength - swiper.loopedSlides * 2) / swiper.params.slidesPerGroup) : swiper.snapGrid.length;
|
179 |
|
180 | if (swiper.params.freeMode && !swiper.params.loop && numberOfBullets > slidesLength) {
|
181 | numberOfBullets = slidesLength;
|
182 | }
|
183 |
|
184 | for (var i = 0; i < numberOfBullets; i += 1) {
|
185 | if (params.renderBullet) {
|
186 | paginationHTML += params.renderBullet.call(swiper, i, params.bulletClass);
|
187 | } else {
|
188 | paginationHTML += "<" + params.bulletElement + " class=\"" + params.bulletClass + "\"></" + params.bulletElement + ">";
|
189 | }
|
190 | }
|
191 |
|
192 | $el.html(paginationHTML);
|
193 | swiper.pagination.bullets = $el.find((0, _utils.classesToSelector)(params.bulletClass));
|
194 | }
|
195 |
|
196 | if (params.type === 'fraction') {
|
197 | if (params.renderFraction) {
|
198 | paginationHTML = params.renderFraction.call(swiper, params.currentClass, params.totalClass);
|
199 | } else {
|
200 | paginationHTML = "<span class=\"" + params.currentClass + "\"></span>" + ' / ' + ("<span class=\"" + params.totalClass + "\"></span>");
|
201 | }
|
202 |
|
203 | $el.html(paginationHTML);
|
204 | }
|
205 |
|
206 | if (params.type === 'progressbar') {
|
207 | if (params.renderProgressbar) {
|
208 | paginationHTML = params.renderProgressbar.call(swiper, params.progressbarFillClass);
|
209 | } else {
|
210 | paginationHTML = "<span class=\"" + params.progressbarFillClass + "\"></span>";
|
211 | }
|
212 |
|
213 | $el.html(paginationHTML);
|
214 | }
|
215 |
|
216 | if (params.type !== 'custom') {
|
217 | swiper.emit('paginationRender', swiper.pagination.$el[0]);
|
218 | }
|
219 | },
|
220 | init: function init() {
|
221 | var swiper = this;
|
222 | var params = swiper.params.pagination;
|
223 | if (!params.el) return;
|
224 | var $el = (0, _dom.default)(params.el);
|
225 | if ($el.length === 0) return;
|
226 |
|
227 | if (swiper.params.uniqueNavElements && typeof params.el === 'string' && $el.length > 1) {
|
228 | $el = swiper.$el.find(params.el);
|
229 | }
|
230 |
|
231 | if (params.type === 'bullets' && params.clickable) {
|
232 | $el.addClass(params.clickableClass);
|
233 | }
|
234 |
|
235 | $el.addClass(params.modifierClass + params.type);
|
236 |
|
237 | if (params.type === 'bullets' && params.dynamicBullets) {
|
238 | $el.addClass("" + params.modifierClass + params.type + "-dynamic");
|
239 | swiper.pagination.dynamicBulletIndex = 0;
|
240 |
|
241 | if (params.dynamicMainBullets < 1) {
|
242 | params.dynamicMainBullets = 1;
|
243 | }
|
244 | }
|
245 |
|
246 | if (params.type === 'progressbar' && params.progressbarOpposite) {
|
247 | $el.addClass(params.progressbarOppositeClass);
|
248 | }
|
249 |
|
250 | if (params.clickable) {
|
251 | $el.on('click', (0, _utils.classesToSelector)(params.bulletClass), function onClick(e) {
|
252 | e.preventDefault();
|
253 | var index = (0, _dom.default)(this).index() * swiper.params.slidesPerGroup;
|
254 | if (swiper.params.loop) index += swiper.loopedSlides;
|
255 | swiper.slideTo(index);
|
256 | });
|
257 | }
|
258 |
|
259 | (0, _utils.extend)(swiper.pagination, {
|
260 | $el: $el,
|
261 | el: $el[0]
|
262 | });
|
263 | },
|
264 | destroy: function destroy() {
|
265 | var swiper = this;
|
266 | var params = swiper.params.pagination;
|
267 | if (!params.el || !swiper.pagination.el || !swiper.pagination.$el || swiper.pagination.$el.length === 0) return;
|
268 | var $el = swiper.pagination.$el;
|
269 | $el.removeClass(params.hiddenClass);
|
270 | $el.removeClass(params.modifierClass + params.type);
|
271 | if (swiper.pagination.bullets) swiper.pagination.bullets.removeClass(params.bulletActiveClass);
|
272 |
|
273 | if (params.clickable) {
|
274 | $el.off('click', (0, _utils.classesToSelector)(params.bulletClass));
|
275 | }
|
276 | }
|
277 | };
|
278 | var _default = {
|
279 | name: 'pagination',
|
280 | params: {
|
281 | pagination: {
|
282 | el: null,
|
283 | bulletElement: 'span',
|
284 | clickable: false,
|
285 | hideOnClick: false,
|
286 | renderBullet: null,
|
287 | renderProgressbar: null,
|
288 | renderFraction: null,
|
289 | renderCustom: null,
|
290 | progressbarOpposite: false,
|
291 | type: 'bullets',
|
292 |
|
293 | dynamicBullets: false,
|
294 | dynamicMainBullets: 1,
|
295 | formatFractionCurrent: function formatFractionCurrent(number) {
|
296 | return number;
|
297 | },
|
298 | formatFractionTotal: function formatFractionTotal(number) {
|
299 | return number;
|
300 | },
|
301 | bulletClass: 'swiper-pagination-bullet',
|
302 | bulletActiveClass: 'swiper-pagination-bullet-active',
|
303 | modifierClass: 'swiper-pagination-',
|
304 |
|
305 | currentClass: 'swiper-pagination-current',
|
306 | totalClass: 'swiper-pagination-total',
|
307 | hiddenClass: 'swiper-pagination-hidden',
|
308 | progressbarFillClass: 'swiper-pagination-progressbar-fill',
|
309 | progressbarOppositeClass: 'swiper-pagination-progressbar-opposite',
|
310 | clickableClass: 'swiper-pagination-clickable',
|
311 |
|
312 | lockClass: 'swiper-pagination-lock'
|
313 | }
|
314 | },
|
315 | create: function create() {
|
316 | var swiper = this;
|
317 | (0, _utils.bindModuleMethods)(swiper, {
|
318 | pagination: _extends({
|
319 | dynamicBulletIndex: 0
|
320 | }, Pagination)
|
321 | });
|
322 | },
|
323 | on: {
|
324 | init: function init(swiper) {
|
325 | swiper.pagination.init();
|
326 | swiper.pagination.render();
|
327 | swiper.pagination.update();
|
328 | },
|
329 | activeIndexChange: function activeIndexChange(swiper) {
|
330 | if (swiper.params.loop) {
|
331 | swiper.pagination.update();
|
332 | } else if (typeof swiper.snapIndex === 'undefined') {
|
333 | swiper.pagination.update();
|
334 | }
|
335 | },
|
336 | snapIndexChange: function snapIndexChange(swiper) {
|
337 | if (!swiper.params.loop) {
|
338 | swiper.pagination.update();
|
339 | }
|
340 | },
|
341 | slidesLengthChange: function slidesLengthChange(swiper) {
|
342 | if (swiper.params.loop) {
|
343 | swiper.pagination.render();
|
344 | swiper.pagination.update();
|
345 | }
|
346 | },
|
347 | snapGridLengthChange: function snapGridLengthChange(swiper) {
|
348 | if (!swiper.params.loop) {
|
349 | swiper.pagination.render();
|
350 | swiper.pagination.update();
|
351 | }
|
352 | },
|
353 | destroy: function destroy(swiper) {
|
354 | swiper.pagination.destroy();
|
355 | },
|
356 | click: function click(swiper, e) {
|
357 | var targetEl = e.target;
|
358 |
|
359 | if (swiper.params.pagination.el && swiper.params.pagination.hideOnClick && swiper.pagination.$el.length > 0 && !(0, _dom.default)(targetEl).hasClass(swiper.params.pagination.bulletClass)) {
|
360 | if (swiper.navigation && (swiper.navigation.nextEl && targetEl === swiper.navigation.nextEl || swiper.navigation.prevEl && targetEl === swiper.navigation.prevEl)) return;
|
361 | var isHidden = swiper.pagination.$el.hasClass(swiper.params.pagination.hiddenClass);
|
362 |
|
363 | if (isHidden === true) {
|
364 | swiper.emit('paginationShow');
|
365 | } else {
|
366 | swiper.emit('paginationHide');
|
367 | }
|
368 |
|
369 | swiper.pagination.$el.toggleClass(swiper.params.pagination.hiddenClass);
|
370 | }
|
371 | }
|
372 | }
|
373 | };
|
374 | exports.default = _default; |
\ | No newline at end of file |