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

142 行
4.2 KiB

  1. import {getUrlParam} from "../../_global/scripts/helpers";
  2. const $ = global.$;
  3. class IHKIndex {
  4. constructor(section) {
  5. this.anchorLink = window.location.href.match(/#(.*)/);
  6. this.section = section.addClass('initiated');
  7. this.letterWrapper = section.find('.letters');
  8. this.letters = this.letterWrapper.find('a');
  9. this.contentWrapper = $('<div class="letter-content" />').insertAfter(this.letterWrapper);
  10. this.initContentWrappers();
  11. this.handleClicks();
  12. // this.initHeightCheck();
  13. }
  14. initContentWrappers() {
  15. this.letters.each((i, el) => {
  16. const letter = $(el).attr('data-index', i);
  17. const wrapper = $('<div class="a-z-content-wrapper" />').attr('data-source', letter.attr('href'));
  18. wrapper.appendTo(this.contentWrapper);
  19. })
  20. this.contents = this.contentWrapper.children();
  21. }
  22. handleClicks() {
  23. const letterInUrlParams = getUrlParam("letter");
  24. const letterElementFromParams = this.section.find("[data-letter='" + letterInUrlParams + "']");
  25. this.letters.on('click', (e) => {
  26. e.preventDefault();
  27. const a = $(e.currentTarget);
  28. const index = parseInt(a.attr('data-index'));
  29. a.parent('li').addClass('active').siblings('.active').removeClass('active');
  30. this.contentWrapper.css('height', this.contentWrapper.outerHeight() + 'px');
  31. this.contents.eq(index).addClass('current').siblings('.current').removeClass('current');
  32. if (!this.contents.eq(index).hasClass('loading') && !this.contents.eq(index).hasClass('loaded')) {
  33. this.loadContent(index);
  34. } else {
  35. this.updateHeight();
  36. }
  37. });
  38. if (letterInUrlParams && letterElementFromParams.length > 0) {
  39. letterElementFromParams.find("a").trigger("click");
  40. } else {
  41. this.letters.first().trigger("click");
  42. }
  43. }
  44. initHeightCheck() {
  45. $(window).on('resize', (e) => {
  46. this.handleResize();
  47. })
  48. this.handleResize();
  49. }
  50. handleResize() {
  51. if (this.letterWrapper.height() > 60) {
  52. this.letterWrapper.addClass('not-sticky');
  53. } else {
  54. this.letterWrapper.removeClass('not-sticky');
  55. }
  56. }
  57. loadContent(index) {
  58. const t = this;
  59. const wrapper = this.contents.eq(index).addClass('loading');
  60. const outer = $('<div class="outer accordion" />').appendTo(wrapper);
  61. let dataSource = this.section.attr('data-letter-content-url');
  62. const letterToLoad = this.letters.eq(index).parent().data("letter");
  63. if (!dataSource) {
  64. dataSource = this.letters.eq(index).attr('href');
  65. }
  66. const dataObj = {
  67. letter: letterToLoad
  68. };
  69. $.ajax({
  70. url: dataSource,
  71. data: dataObj,
  72. type: "GET",
  73. success: (result) => {
  74. outer.html(result);
  75. wrapper.removeClass('loading').addClass('loaded');
  76. $('body').trigger('dynamic-component-loaded');
  77. t.updateHeight();
  78. }
  79. });
  80. }
  81. updateHeight() {
  82. setTimeout(() => {
  83. this.contentWrapper.css('height', this.contentWrapper.children('.current').outerHeight() + 'px');
  84. }, 40)
  85. setTimeout(() => {
  86. this.contentWrapper.removeAttr('style');
  87. }, 500)
  88. if (this.anchorLink != null) {
  89. const anchorLinkElementText = (this.anchorLink[1].length > 10) ? this.anchorLink[1].substr(0, this.anchorLink[1].indexOf('&')) : this.anchorLink[1];
  90. const anchorLinkElement = $("#" + anchorLinkElementText);
  91. anchorLinkElement.css("display", "block");
  92. anchorLinkElement.parent().addClass("open");
  93. this.scrollToTarget(anchorLinkElement);
  94. this.anchorLink = null;
  95. } else {
  96. let target = this.section.offset().top - 100;
  97. if ($(window).width() < 768) {
  98. target = this.section.offset().top - 80;
  99. }
  100. if ($(window).scrollTop() > target) {
  101. $('html, body').animate({'scrollTop': target}, 500, 'easeInOutQuad');
  102. }
  103. }
  104. }
  105. scrollToTarget(anchorLinkElement) {
  106. // const anchorLinkElement = $("#" + anchorLink[1]);
  107. if (anchorLinkElement.length > 0) {
  108. $('html, body').animate({
  109. scrollTop: anchorLinkElement.first().offset().top - 250
  110. }, 200);
  111. }
  112. }
  113. }
  114. export default IHKIndex;
  115. $('body').on('ihk-init dynamic-component-loaded gfi-dynamic-init', function () {
  116. $('.a-z:not(.initiated)').each(function (i) {
  117. new IHKIndex($(this));
  118. });
  119. });