Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

101 строка
2.8 KiB

  1. const $ = require('jquery');
  2. class EventPagination {
  3. constructor(list) {
  4. if (!list.data('pagination') || list.data('items') >= list.children().length) {
  5. list.closest('.events-wrapper').next('.events-actions').find('.prev, .next').remove();
  6. return false;
  7. }
  8. this.list = list.addClass('initiated');
  9. this.wrapper = list.closest('.events-wrapper');
  10. this.items = list.children();
  11. this.current = 0;
  12. this.resizeTimer = null;
  13. this.scroll = this.list.data('scroll');
  14. this.show = this.list.data('items');
  15. if (!this.scroll) {
  16. this.scroll = this.show;
  17. }
  18. this.initButtons();
  19. this.goTo(0);
  20. this.initResize();
  21. }
  22. initResize() {
  23. $(window).on('resize', () => {
  24. if (this.resizeTimer) {
  25. clearTimeout(this.resizeTimer);
  26. }
  27. this.resizeTimer = setTimeout( () => {
  28. this.goTo(this.current);
  29. }, 250)
  30. })
  31. }
  32. initButtons() {
  33. this.prevBtn = this.wrapper.next('.events-actions').find('.prev');
  34. this.nextBtn = this.wrapper.next('.events-actions').find('.next');
  35. this.nextBtn.on('click', (e) => {
  36. e.preventDefault();
  37. this.next();
  38. })
  39. this.prevBtn.on('click', (e) => {
  40. e.preventDefault();
  41. this.prev();
  42. })
  43. }
  44. next() {
  45. if (this.current + this.scroll + this.show < this.items.length) {
  46. this.goTo(this.current + this.scroll);
  47. this.nextBtn.removeClass('disabled').removeAttr('disabled', 'disabled');
  48. }
  49. else {
  50. this.goTo(this.items.length - this.show);
  51. this.nextBtn.addClass('disabled').attr('disabled', 'disabled');
  52. }
  53. this.prevBtn.removeClass('disabled').removeAttr('disabled', 'disabled');
  54. }
  55. prev() {
  56. if (this.current - this.scroll > 0) {
  57. this.goTo(this.current - this.scroll);
  58. this.prevBtn.removeClass('disabled').removeAttr('disabled', 'disabled');
  59. }
  60. else {
  61. this.goTo(0);
  62. this.prevBtn.addClass('disabled').attr('disabled', 'disabled');
  63. }
  64. this.nextBtn.removeClass('disabled').removeAttr('disabled', 'disabled');
  65. }
  66. goTo(firstID) {
  67. const firstItem = this.items.eq(firstID);
  68. const lastItem = this.items.eq(firstID + this.show - 1);
  69. this.wrapper.css('height', (lastItem.position().top - firstItem.position().top + lastItem.outerHeight()) + 'px');
  70. this.list.css('transform', 'translate3d(0, -' + firstItem.position().top + 'px, 0');
  71. this.items.each((i, el) => {
  72. if (i < firstID || i > firstID + this.show - 1) {
  73. $(el).find('a').attr('tabindex', '-1');
  74. }
  75. else {
  76. $(el).find('a').removeAttr('tabindex');
  77. }
  78. })
  79. this.current = firstID;
  80. }
  81. }
  82. $('body').on('ihk-init dynamic-component-loaded gfi-dynamic-init', function () {
  83. $('.events-list[data-pagination="true"]:not(.initiated)').each(function(i) {
  84. new EventPagination($(this));
  85. });
  86. })