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

229 строки
6.9 KiB

  1. import $ from "jquery";
  2. class IHKNav {
  3. constructor(nav) {
  4. this.nav = nav.addClass('initiated');
  5. this.primary = nav.find('.primary');
  6. this.baseUrl = this.primary.attr('data-base-url');
  7. this.rootUrl = this.primary.attr('data-root-url');
  8. this.initPrimaryNav();
  9. this.initSecondaryNav();
  10. $('body').on('open-navigation', (event, data) => {
  11. this.initPrimaryNav(data.rootUrl);
  12. })
  13. }
  14. initPrimaryNav(optionalRootUrl) {
  15. this.primary.empty()
  16. if (optionalRootUrl) {
  17. this.rootUrl = optionalRootUrl;
  18. this.primary.off('click', 'a');
  19. }
  20. this.primary.append($('<ul class="current" />').attr('data-json', this.baseUrl + this.rootUrl));
  21. this.primary.on('click', 'a', (e) => {
  22. const a = $(e.currentTarget);
  23. const li = a.parent();
  24. const ul = li.parent('ul');
  25. if (li.hasClass('deep')) {
  26. e.preventDefault();
  27. if (a.siblings('ul').length) {
  28. ul.removeClass('current');
  29. this.toTop(ul);
  30. a.siblings('ul').addClass('current');
  31. li.addClass('open');
  32. this.manageTabIndex();
  33. } else {
  34. const deepUl = $('<ul />').attr('data-json', a.attr('href')).appendTo(li);
  35. this.loadNav(deepUl);
  36. }
  37. } else if (li.hasClass('back')) {
  38. e.preventDefault();
  39. this.toTop(ul);
  40. if (ul.closest('li').length) {
  41. ul.removeClass('current')
  42. .closest('li').removeClass('open')
  43. .parent('ul').addClass('current');
  44. this.manageTabIndex();
  45. } else {
  46. const backUl = $('<ul />').attr('data-json', a.attr('href')).insertBefore(ul);
  47. this.loadNav(backUl);
  48. }
  49. }
  50. });
  51. this.loadNav(this.nav.find('.primary ul'));
  52. }
  53. initSecondaryNav() {
  54. // secondary-nav-item
  55. const $secondary = this.nav.find(".secondary");
  56. const $secondaryItems = $secondary.find(".secondary-nav-item");
  57. $.each($secondaryItems, (index, element) => {
  58. $(element).on("click", (e) => {
  59. if ($(element).data("is-channel")) {
  60. e.preventDefault();
  61. const elementRootUrl= $(this).data("root-url");
  62. this.initPrimaryNav(elementRootUrl);
  63. } else {
  64. return true;
  65. }
  66. });
  67. });
  68. }
  69. loadNav(ul) {
  70. const currentPageId = this.nav.find('.primary').data("page-content-id");
  71. if (ul.parent('li').length) {
  72. ul.addClass('current');
  73. setTimeout(() => {
  74. const parentUl = ul.addClass('loading').parent('li').addClass('open')
  75. .closest('.current').removeClass('current');
  76. this.toTop(parentUl);
  77. }, 20)
  78. }
  79. $.ajax({
  80. url: ul.attr('data-json'),
  81. type: "GET",
  82. dataType: "json",
  83. xhrFields: {withCredentials: true}
  84. }).done((data) => {
  85. ul.attr('data-cm-metadata', '[{"_":{"$Ref":"content/' + data.tocListId + '"}}]');
  86. if (data.parentId) {
  87. $('<li class="back" />').appendTo(ul)
  88. .append($('<a />').attr('href', this.baseUrl + data.parentId).text(data.title));
  89. }
  90. if(!data.hideOverview) {
  91. if (data.showOverview) {
  92. const overviewElement = $('<li class="overview" />');
  93. overviewElement.appendTo(ul)
  94. .append($('<a />').attr('href', data.url).text(window.ihk.translations.overview));
  95. if (data.contentId === currentPageId.toString()) {
  96. overviewElement.find("a").addClass("active");
  97. }
  98. }
  99. }
  100. const parentElement = data;
  101. $.each(data.items, (index, item) => {
  102. const itemsBaseUrl = ihk.settings !== undefined ? ihk.settings.navigationItemsUrl : '';
  103. let itemUrl = item.url;
  104. if (itemsBaseUrl) {
  105. itemUrl = itemsBaseUrl + itemUrl;
  106. }
  107. let li = $('<li />').attr('data-id', item.contentId).attr('data-cm-metadata', '[{"_":{"$Ref":"content/' + item.contentId + '"}}]').appendTo(ul),
  108. a = $('<a />').html(item.title).appendTo(li);
  109. switch (item.type) {
  110. case "CMChannel" :
  111. li.addClass('deep');
  112. a.attr('href', this.baseUrl + item.contentId);
  113. break;
  114. case "CMArticle" :
  115. li.addClass('link');
  116. a.attr('href', itemUrl);
  117. break;
  118. default :
  119. li.addClass('miscellaneous');
  120. li.attr('data-type', item.type);
  121. a.attr('href', itemUrl);
  122. }
  123. if (item.linktype === 'external') {
  124. li.addClass('external');
  125. $(li).find("a").attr("target","_blank")
  126. }
  127. if (item.viewType === 'onlinemagazinstart') {
  128. // todo als link
  129. li.removeClass('deep');
  130. li.addClass('magazine-nav');
  131. $(li).find("a").attr("href",itemUrl);
  132. if (item.titleImage) {
  133. a.text('').append($('<img src="' + item.titleImage + '" alt="' + item.title + '" />'))
  134. }
  135. }
  136. if (item.viewType === 'themenseite' && !parentElement.root) {
  137. li.addClass('overview');
  138. li.removeClass('deep');
  139. a.attr('href', itemUrl);
  140. }
  141. if (item.trackCode && item.trackCode.length > 0) {
  142. $(li).find("a").attr("onmousedown", item.trackCode);
  143. }
  144. if (item.restrictedTo && item.restrictedTo.indexOf('extranet') > -1) {
  145. li.addClass('extranet');
  146. } else if (item.restrictedTo && item.restrictedTo.indexOf('intranet') > -1) {
  147. li.addClass('intranet');
  148. }
  149. if (item.doctype &&
  150. (item.doctype.indexOf('Datei') > -1 || item.doctype.indexOf('PDF') > -1 || item.doctype.indexOf('PIC') > -1)) {
  151. li.addClass('download');
  152. }
  153. if(item.contentId === currentPageId.toString()){
  154. $(li).find("a").addClass("active");
  155. }
  156. });
  157. ul.addClass('current').attr('data-id', data.contentId);
  158. if (ul.parent('li').length) {
  159. setTimeout( () => {
  160. const parentUl = ul.removeClass('loading').parent('li').addClass('open')
  161. .closest('.current').removeClass('current');
  162. this.toTop(parentUl);
  163. this.manageTabIndex();
  164. }, 20)
  165. } else if (ul.next('ul').length) {
  166. const innerUl = ul.next('ul');
  167. let wrapperLi = ul.find('li[data-id="' + innerUl.attr('data-id') + '"]').addClass('open');
  168. if (!wrapperLi.length) {
  169. wrapperLi = $('<li />').addClass('open').appendTo(ul);
  170. }
  171. wrapperLi.append(innerUl);
  172. setTimeout(() => {
  173. innerUl.removeClass('current');
  174. wrapperLi.removeClass('open');
  175. this.manageTabIndex();
  176. }, 20)
  177. }
  178. })
  179. }
  180. manageTabIndex() {
  181. this.nav.find('.primary a').attr('tabindex', '-1');
  182. this.nav.find('.primary .current > li > a').removeAttr('tabindex');
  183. }
  184. toTop(ul) {
  185. if (ul.scrollTop() > 0) {
  186. ul.animate({'scrollTop': 0}, 300, 'swing');
  187. }
  188. }
  189. }
  190. export default IHKNav;
  191. $('body').on('ihk-init dynamic-component-loaded gfi-dynamic-init', function () {
  192. $('.page-header nav:not(.initiated)').each(function () {
  193. new IHKNav($(this));
  194. });
  195. });