Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

93 linhas
2.6 KiB

  1. import $ from 'jquery';
  2. class IHKContact {
  3. constructor(wrapper) {
  4. this.wrapper = wrapper;
  5. this.contactsWrapper = wrapper.find('.contacts');
  6. this.contacts = this.contactsWrapper.find('.contact-person');
  7. this.current = 0;
  8. this.tabStyle = wrapper.data('tab-style');
  9. this.TABS_CLOSED = "closed";
  10. this.TABS_OPEN = "open";
  11. this.initTabs();
  12. this.initSizeObserver();
  13. }
  14. initTabs() {
  15. if (this.tabStyle === this.TABS_OPEN || this.contacts.length < 2) {
  16. this.contacts.addClass('active');
  17. return;
  18. }
  19. this.tabs = $('<ul />').addClass('tab-buttons').insertBefore(this.contactsWrapper);
  20. this.contacts.each((i, el) => {
  21. const c = $(el);
  22. const a = $('<a href="' + c.attr('id') + '" />').attr('data-index', i).text(c.data('contact-tab'));
  23. a.addClass('btn').addClass('btn-small');
  24. if (!c.data('contact-tab')) {
  25. a.text( i < 9 ? '0' + (i + 1) : i + 1 );
  26. }
  27. $('<li />').append(a).appendTo(this.tabs);
  28. });
  29. const tabAnchors = this.tabs.find('a');
  30. tabAnchors.on('click', (e) => {
  31. e.preventDefault();
  32. const btn = $(e.currentTarget);
  33. const index = parseInt(btn.attr('data-index'));
  34. this.contacts.eq(index).addClass('active').siblings('.active').removeClass('active');
  35. btn.parent('li').addClass('active').siblings('.active').removeClass('active');
  36. this.changeHeight(this.current, index);
  37. this.current = index;
  38. });
  39. if(this.tabStyle !== this.TABS_CLOSED){
  40. tabAnchors.first().trigger('click');
  41. }
  42. }
  43. changeHeight(prev, next) {
  44. if (prev === next) {
  45. return;
  46. }
  47. this.contactsWrapper.css('height', this.contacts.eq(prev).outerHeight() + 'px');
  48. setTimeout(() => {
  49. this.contactsWrapper.css('height', this.contacts.eq(next).outerHeight() + 'px');
  50. }, 40)
  51. setTimeout(() => {
  52. this.contactsWrapper.removeAttr('style').trigger('resize');
  53. }, 500)
  54. }
  55. initSizeObserver() {
  56. const observer = new ResizeObserver((entries) => {
  57. entries.map((entry) => {
  58. const w = entry.borderBoxSize[0].inlineSize;
  59. const wrapper = this.wrapper.get(0);
  60. if (w < 500) {
  61. wrapper.dataset.size = 'sm';
  62. } else if (w < 1000) {
  63. wrapper.dataset.size = 'md';
  64. } else {
  65. wrapper.dataset.size = 'lg';
  66. }
  67. })
  68. })
  69. observer.observe(this.wrapper.get(0));
  70. }
  71. }
  72. export default IHKContact;
  73. $('body').on('ihk-init dynamic-component-loaded gfi-dynamic-init', function () {
  74. $('.contact-wrapper:not(.initiated)').each(function () {
  75. new IHKContact($(this));
  76. });
  77. });