12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import { CLS, addClass, eachChild, isHorizontal, removeClass, transform, transition } from './swiper-utils';
  2. /*=========================
  3. Pagination
  4. ===========================*/
  5. export function updatePagination(s) {
  6. if (!s.paginationType || !s._paginationContainer)
  7. return;
  8. var paginationHTML = '';
  9. if (s.paginationType === 'bullets') {
  10. var numberOfBullets = s.loop ? Math.ceil((s._slides.length - s.loopedSlides * 2) / s.slidesPerGroup) : s._snapGrid.length;
  11. for (var i = 0; i < numberOfBullets; i++) {
  12. if (s.paginationBulletRender) {
  13. paginationHTML += s.paginationBulletRender(i, CLS.bullet);
  14. }
  15. else {
  16. paginationHTML += "<button class=\"" + CLS.bullet + "\" aria-label=\"Go to slide " + (i + 1) + "\" data-slide-index=\"" + i + "\"></button>";
  17. }
  18. }
  19. }
  20. else if (s.paginationType === 'fraction') {
  21. paginationHTML =
  22. '<span class="' + CLS.paginationCurrent + '"></span>' +
  23. ' / ' +
  24. '<span class="' + CLS.paginationTotal + '"></span>';
  25. }
  26. else if (s.paginationType === 'progress') {
  27. paginationHTML = '<span class="' + CLS.paginationProgressbar + '"></span>';
  28. }
  29. s._paginationContainer.innerHTML = paginationHTML;
  30. s._bullets = s._paginationContainer.querySelectorAll('.' + CLS.bullet);
  31. }
  32. export function updatePaginationClasses(s) {
  33. // Current/Total
  34. var current;
  35. var total = s.loop ? Math.ceil((s._slides.length - s.loopedSlides * 2) / s.slidesPerGroup) : s._snapGrid.length;
  36. if (s.loop) {
  37. current = Math.ceil((s._activeIndex - s.loopedSlides) / s.slidesPerGroup);
  38. if (current > s._slides.length - 1 - s.loopedSlides * 2) {
  39. current = current - (s._slides.length - s.loopedSlides * 2);
  40. }
  41. if (current > total - 1) {
  42. current = current - total;
  43. }
  44. if (current < 0 && s.paginationType !== 'bullets') {
  45. current = total + current;
  46. }
  47. }
  48. else {
  49. if (typeof s._snapIndex !== 'undefined') {
  50. current = s._snapIndex;
  51. }
  52. else {
  53. current = s._activeIndex || 0;
  54. }
  55. }
  56. // Types
  57. if (s.paginationType === 'bullets' && s._bullets) {
  58. var selector = current + (current < 0 ? s._bullets.length : 0);
  59. for (var i = 0; i < s._bullets.length; i++) {
  60. if (i === selector) {
  61. addClass(s._bullets[i], CLS.bulletActive);
  62. }
  63. else {
  64. removeClass(s._bullets[i], CLS.bulletActive);
  65. }
  66. }
  67. }
  68. if (s.paginationType === 'fraction') {
  69. eachChild(s._paginationContainer, '.' + CLS.paginationCurrent, function (ele) {
  70. ele.textContent = (current + 1);
  71. });
  72. eachChild(s._paginationContainer, '.' + CLS.paginationTotal, function (ele) {
  73. ele.textContent = total;
  74. });
  75. }
  76. if (s.paginationType === 'progress') {
  77. var scale = (current + 1) / total, scaleX = scale, scaleY = 1;
  78. if (!isHorizontal(s)) {
  79. scaleY = scale;
  80. scaleX = 1;
  81. }
  82. eachChild(s._paginationContainer, '.' + CLS.paginationProgressbar, function (ele) {
  83. transform(ele, 'translate3d(0,0,0) scaleX(' + scaleX + ') scaleY(' + scaleY + ')');
  84. transition(ele, s.speed);
  85. });
  86. }
  87. }
  88. //# sourceMappingURL=swiper-pagination.js.map