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("." + params.currentClass).text(params.formatFractionCurrent(current + 1));
|
134 | $el.find("." + 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("." + 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 | for (var i = 0; i < numberOfBullets; i += 1) {
|
181 | if (params.renderBullet) {
|
182 | paginationHTML += params.renderBullet.call(swiper, i, params.bulletClass);
|
183 | } else {
|
184 | paginationHTML += "<" + params.bulletElement + " class=\"" + params.bulletClass + "\"></" + params.bulletElement + ">";
|
185 | }
|
186 | }
|
187 |
|
188 | $el.html(paginationHTML);
|
189 | swiper.pagination.bullets = $el.find("." + params.bulletClass.replace(/ /g, '.'));
|
190 | }
|
191 |
|
192 | if (params.type === 'fraction') {
|
193 | if (params.renderFraction) {
|
194 | paginationHTML = params.renderFraction.call(swiper, params.currentClass, params.totalClass);
|
195 | } else {
|
196 | paginationHTML = "<span class=\"" + params.currentClass + "\"></span>" + ' / ' + ("<span class=\"" + params.totalClass + "\"></span>");
|
197 | }
|
198 |
|
199 | $el.html(paginationHTML);
|
200 | }
|
201 |
|
202 | if (params.type === 'progressbar') {
|
203 | if (params.renderProgressbar) {
|
204 | paginationHTML = params.renderProgressbar.call(swiper, params.progressbarFillClass);
|
205 | } else {
|
206 | paginationHTML = "<span class=\"" + params.progressbarFillClass + "\"></span>";
|
207 | }
|
208 |
|
209 | $el.html(paginationHTML);
|
210 | }
|
211 |
|
212 | if (params.type !== 'custom') {
|
213 | swiper.emit('paginationRender', swiper.pagination.$el[0]);
|
214 | }
|
215 | },
|
216 | init: function init() {
|
217 | var swiper = this;
|
218 | var params = swiper.params.pagination;
|
219 | if (!params.el) return;
|
220 | var $el = (0, _dom.default)(params.el);
|
221 | if ($el.length === 0) return;
|
222 |
|
223 | if (swiper.params.uniqueNavElements && typeof params.el === 'string' && $el.length > 1) {
|
224 | $el = swiper.$el.find(params.el);
|
225 | }
|
226 |
|
227 | if (params.type === 'bullets' && params.clickable) {
|
228 | $el.addClass(params.clickableClass);
|
229 | }
|
230 |
|
231 | $el.addClass(params.modifierClass + params.type);
|
232 |
|
233 | if (params.type === 'bullets' && params.dynamicBullets) {
|
234 | $el.addClass("" + params.modifierClass + params.type + "-dynamic");
|
235 | swiper.pagination.dynamicBulletIndex = 0;
|
236 |
|
237 | if (params.dynamicMainBullets < 1) {
|
238 | params.dynamicMainBullets = 1;
|
239 | }
|
240 | }
|
241 |
|
242 | if (params.type === 'progressbar' && params.progressbarOpposite) {
|
243 | $el.addClass(params.progressbarOppositeClass);
|
244 | }
|
245 |
|
246 | if (params.clickable) {
|
247 | $el.on('click', "." + params.bulletClass.replace(/ /g, '.'), function onClick(e) {
|
248 | e.preventDefault();
|
249 | var index = (0, _dom.default)(this).index() * swiper.params.slidesPerGroup;
|
250 | if (swiper.params.loop) index += swiper.loopedSlides;
|
251 | swiper.slideTo(index);
|
252 | });
|
253 | }
|
254 |
|
255 | (0, _utils.extend)(swiper.pagination, {
|
256 | $el: $el,
|
257 | el: $el[0]
|
258 | });
|
259 | },
|
260 | destroy: function destroy() {
|
261 | var swiper = this;
|
262 | var params = swiper.params.pagination;
|
263 | if (!params.el || !swiper.pagination.el || !swiper.pagination.$el || swiper.pagination.$el.length === 0) return;
|
264 | var $el = swiper.pagination.$el;
|
265 | $el.removeClass(params.hiddenClass);
|
266 | $el.removeClass(params.modifierClass + params.type);
|
267 | if (swiper.pagination.bullets) swiper.pagination.bullets.removeClass(params.bulletActiveClass);
|
268 |
|
269 | if (params.clickable) {
|
270 | $el.off('click', "." + params.bulletClass.replace(/ /g, '.'));
|
271 | }
|
272 | }
|
273 | };
|
274 | var _default = {
|
275 | name: 'pagination',
|
276 | params: {
|
277 | pagination: {
|
278 | el: null,
|
279 | bulletElement: 'span',
|
280 | clickable: false,
|
281 | hideOnClick: false,
|
282 | renderBullet: null,
|
283 | renderProgressbar: null,
|
284 | renderFraction: null,
|
285 | renderCustom: null,
|
286 | progressbarOpposite: false,
|
287 | type: 'bullets',
|
288 |
|
289 | dynamicBullets: false,
|
290 | dynamicMainBullets: 1,
|
291 | formatFractionCurrent: function formatFractionCurrent(number) {
|
292 | return number;
|
293 | },
|
294 | formatFractionTotal: function formatFractionTotal(number) {
|
295 | return number;
|
296 | },
|
297 | bulletClass: 'swiper-pagination-bullet',
|
298 | bulletActiveClass: 'swiper-pagination-bullet-active',
|
299 | modifierClass: 'swiper-pagination-',
|
300 |
|
301 | currentClass: 'swiper-pagination-current',
|
302 | totalClass: 'swiper-pagination-total',
|
303 | hiddenClass: 'swiper-pagination-hidden',
|
304 | progressbarFillClass: 'swiper-pagination-progressbar-fill',
|
305 | progressbarOppositeClass: 'swiper-pagination-progressbar-opposite',
|
306 | clickableClass: 'swiper-pagination-clickable',
|
307 |
|
308 | lockClass: 'swiper-pagination-lock'
|
309 | }
|
310 | },
|
311 | create: function create() {
|
312 | var swiper = this;
|
313 | (0, _utils.bindModuleMethods)(swiper, {
|
314 | pagination: _extends({
|
315 | dynamicBulletIndex: 0
|
316 | }, Pagination)
|
317 | });
|
318 | },
|
319 | on: {
|
320 | init: function init(swiper) {
|
321 | swiper.pagination.init();
|
322 | swiper.pagination.render();
|
323 | swiper.pagination.update();
|
324 | },
|
325 | activeIndexChange: function activeIndexChange(swiper) {
|
326 | if (swiper.params.loop) {
|
327 | swiper.pagination.update();
|
328 | } else if (typeof swiper.snapIndex === 'undefined') {
|
329 | swiper.pagination.update();
|
330 | }
|
331 | },
|
332 | snapIndexChange: function snapIndexChange(swiper) {
|
333 | if (!swiper.params.loop) {
|
334 | swiper.pagination.update();
|
335 | }
|
336 | },
|
337 | slidesLengthChange: function slidesLengthChange(swiper) {
|
338 | if (swiper.params.loop) {
|
339 | swiper.pagination.render();
|
340 | swiper.pagination.update();
|
341 | }
|
342 | },
|
343 | snapGridLengthChange: function snapGridLengthChange(swiper) {
|
344 | if (!swiper.params.loop) {
|
345 | swiper.pagination.render();
|
346 | swiper.pagination.update();
|
347 | }
|
348 | },
|
349 | destroy: function destroy(swiper) {
|
350 | swiper.pagination.destroy();
|
351 | },
|
352 | click: function click(swiper, e) {
|
353 | if (swiper.params.pagination.el && swiper.params.pagination.hideOnClick && swiper.pagination.$el.length > 0 && !(0, _dom.default)(e.target).hasClass(swiper.params.pagination.bulletClass)) {
|
354 | var isHidden = swiper.pagination.$el.hasClass(swiper.params.pagination.hiddenClass);
|
355 |
|
356 | if (isHidden === true) {
|
357 | swiper.emit('paginationShow');
|
358 | } else {
|
359 | swiper.emit('paginationHide');
|
360 | }
|
361 |
|
362 | swiper.pagination.$el.toggleClass(swiper.params.pagination.hiddenClass);
|
363 | }
|
364 | }
|
365 | }
|
366 | };
|
367 | exports.default = _default; |
\ | No newline at end of file |