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