/* @license GNU-GPL-2.0-or-later https://www.drupal.org/licensing/faq */
(function(ECL,Drupal,$){Drupal.behaviors.eclInPageNavigation={attach:function attach(context,settings){const inpage_navigations=document.querySelectorAll('.oe-theme-ecl-inpage-navigation');if(inpage_navigations.length===0)return;let containers=[].slice.call(document.querySelectorAll('.inpage-navigation-container'));if(containers.length===0)containers.push(document.querySelector('#main-content'));containers.forEach(function(container){const nav=container.querySelector(':scope .oe-theme-ecl-inpage-navigation');if(nav===null)return;let items_markup=Drupal.eclInPageNavigation.generateItems(container,function(id,text){return Drupal.theme('oe_theme_inpage_navigation_item',id,text);});if(items_markup.length===0){Drupal.eclInPageNavigation.handleEmptyInpageNavigation(nav);return;}nav.querySelector('ul').innerHTML=items_markup;const instance=new ECL.InpageNavigation(nav);instance.init();Drupal.eclInPageNavigation.instances.push(instance);});},detach:function detach(context,settings,trigger){Drupal.eclInPageNavigation.instances.forEach(function(instance){instance.destroy();});}};Drupal.eclInPageNavigation={seenIds:{},instances:[],generateItems:function(container,item_cb){Array.prototype.forEach.call(container.querySelectorAll(':scope [data-inpage-navigation-source-area]'),function(area){let selectors=area.getAttribute('data-inpage-navigation-source-area');Array.prototype.forEach.call(area.querySelectorAll(':scope '+selectors),function(element){element.setAttribute('data-inpage-navigation-source-element','');});});if(container.hasAttribute('data-inpage-navigation-source-area')){let selectors=container.getAttribute('data-inpage-navigation-source-area');Array.prototype.forEach.call(container.querySelectorAll(':scope '+selectors),function(element){element.setAttribute('data-inpage-navigation-source-element','');});}let items_markup='';Array.prototype.forEach.call(container.querySelectorAll(':scope [data-inpage-navigation-source-element]'),function(element){let title=element.textContent.trim();if(title.length===0)return;if(!element.hasAttribute('id')){let id=Drupal.eclInPageNavigation.slug(title);if(id===false)return;element.setAttribute('id',id);}element.removeAttribute('data-inpage-navigation-source-element');items_markup+=item_cb(element.getAttribute('id'),title);});return items_markup;},slug:function(value){let originalSlug=value.toLowerCase().trim().replace(/<[!\/a-z].*?>/ig,'').replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g,'').replace(/\s/g,'-');let slug=originalSlug;let occurrenceAccumulator=0;if(slug.length===0)return false;if(!slug[0].match("^[a-zA-Z]*$")){slug='ref-'+slug;originalSlug=slug;}if(!this.seenIds.hasOwnProperty(slug)&&document.querySelector('#'+slug))this.seenIds[slug]=0;if(this.seenIds.hasOwnProperty(slug)){occurrenceAccumulator=this.seenIds[slug];do{occurrenceAccumulator++;slug=originalSlug+'-'+occurrenceAccumulator;}while(this.seenIds.hasOwnProperty(slug)||document.querySelector('#'+slug));}this.seenIds[originalSlug]=occurrenceAccumulator;this.seenIds[slug]=0;return slug;},handleEmptyInpageNavigation:function(block){block.remove();}};Drupal.theme.oe_theme_inpage_navigation_item=function(id,text){return '<li class="ecl-inpage-navigation__item"><a href="#'+id+'" class="ecl-link ecl-link--standalone ecl-inpage-navigation__link" data-ecl-inpage-navigation-link>'+text+'</a></li>';};})(ECL,Drupal,jQuery);;
(function(Drupal,$){Drupal.eclInPageNavigation.handleEmptyInpageNavigation=function(element){if($(element).closest('.oe-theme-left-sidebar').children('.ecl-media-container').length>0){$(element).closest('.ecl-inpage-navigation').remove();return;}$(element).closest('.oe-theme-left-sidebar').next('.ecl-col-l-9').removeClass('ecl-col-l-9').addClass('ecl-col-l-12');$(element).closest('.oe-theme-left-sidebar.ecl-col-12.ecl-col-l-3').remove();};})(Drupal,jQuery);;
