25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

71 lines
2.0 KiB

  1. const $ = require('jquery');
  2. class Contacts {
  3. constructor(wrapper) {
  4. wrapper.addClass('initiated');
  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. }
  13. initTabs() {
  14. if (this.tabStyle === this.TABS_OPEN || this.contacts.length < 2) {
  15. this.contacts.addClass('active');
  16. return;
  17. }
  18. this.tabs = $('<ul />').addClass('tab-buttons').insertBefore(this.contactsWrapper);
  19. this.contacts.each((i, el) => {
  20. const c = $(el);
  21. const a = $('<a href="' + c.attr('id') + '" />').attr('data-index', i).text(c.data('contact-tab'));
  22. if (!c.data('contact-tab')) {
  23. a.text( i < 9 ? '0' + (i + 1) : i + 1 );
  24. }
  25. $('<li />').append(a).appendTo(this.tabs);
  26. });
  27. const tabAnchors = this.tabs.find('a');
  28. tabAnchors.on('click', (e) => {
  29. e.preventDefault();
  30. const btn = $(e.currentTarget);
  31. const index = parseInt(btn.attr('data-index'));
  32. this.contacts.eq(index).addClass('active').siblings('.active').removeClass('active');
  33. btn.parent('li').addClass('active').siblings('.active').removeClass('active');
  34. this.changeHeight(this.current, index);
  35. this.current = index;
  36. });
  37. if(this.tabStyle !== this.TABS_CLOSED){
  38. tabAnchors.first().trigger('click');
  39. }
  40. }
  41. changeHeight(prev, next) {
  42. if (prev === next) {
  43. return;
  44. }
  45. this.contactsWrapper.css('height', this.contacts.eq(prev).outerHeight() + 'px');
  46. setTimeout(() => {
  47. this.contactsWrapper.css('height', this.contacts.eq(next).outerHeight() + 'px');
  48. }, 40)
  49. setTimeout(() => {
  50. this.contactsWrapper.removeAttr('style').trigger('resize');
  51. }, 500)
  52. }
  53. }
  54. $('body').on('ihk-init dynamic-component-loaded gfi-dynamic-init', function () {
  55. $('.contact-wrapper:not(.initiated)').each(function() {
  56. new Contacts($(this));
  57. });
  58. })