選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 

107 行
2.9 KiB

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