2026-02-05 17:08:59 +03:00

1 line
4.9 KiB
JavaScript

function awbTableOfContentsRefreshAllElements(){var e,t,o=(e=[],document.querySelectorAll("h1,h2,h3,h4,h5,h6").forEach((function(t){t.matches(".awb-toc-el__title")||e.push(t)})),e),n=document.querySelectorAll(".awb-toc-el"),i=document.body.classList.contains("fusion-builder-live-preview"),a={};function r(e,t,o=0){var n=0,a="awb-toc-el__list awb-toc-el__list--"+o,s="",c="";if("custom_icon"===t.counter_type&&t.icon&&(s='<span class="awb-toc-el__item-icon '+t.icon+'"></span>'),c+='<ul class="'+a+'">',i&&0===e.length&&window.awbTOCDummyContent1&&0===o){var l="object"==typeof t.allowed_heading_tags?Object.keys(t.allowed_heading_tags).length:3;3<l&&(l=3),e=window["awbTOCDummyContent"+l]}for(n=0;n<e.length;n++)c+='<li class="awb-toc-el__list-item">',e[n].title&&(c+='<a class="awb-toc-el__item-anchor" href="#'+e[n].id+'">'+s+e[n].title+"</a>"),Array.isArray(e[n].children)&&e[n].children.length&&(c+=r(e[n].children,t,o+1)),c+="</li>";return c+="</ul>"}function s(e){var t,n,r,s,c,l,d,u=[],w=o,f="";for("post_content"===e.limit_container?f=".fusion-content-tb *":"page_content"===e.limit_container?f="#content *":"custom"===e.limit_container&&e.select_custom_headings&&(f=e.select_custom_headings),e.ignore_headings||(e.ignore_headings=".awb-exclude-from-toc, .awb-exclude-from-toc *"),d=0;d<w.length;d++)if(t=w[d],void 0!==e.allowed_heading_tags[t.tagName.toLowerCase()]&&(!f||t.matches(f))&&(!e.ignore_headings||!t.matches(e.ignore_headings))&&(!i||!t.matches(".fusion-builder-module-controls-container *, .fusion-builder-modal-top-container *"))&&!t.matches(".awb-off-canvas *")&&("yes"!==e.hide_hidden_titles||jQuery(t).is(":visible"))){if(e.ignore_headings_words&&"string"==typeof e.ignore_headings_words){for(n=t.textContent.toLowerCase(),r=e.ignore_headings_words.split("|"),s=!1,l=0;l<r.length;l++)r[l]&&n.includes(r[l].toLowerCase())&&(s=!0);if(s)continue}0===(c=e.allowed_heading_tags[t.tagName.toLowerCase()])&&u.push(h(t)),0<c&&b(u,t,c)}return u;function h(e){var t="",o="";return e&&(t=function(e){var t,o=e.getAttribute("id"),n=0;o||(function o(i){a[i]?a[i]!==e&&(n&&(i=i.replace(/__\d+/,"")),n++,o(i=i+"__"+n)):(a[i]=e,t=i)}(t=function(e){var t,o,n,i="toc",a=e.split(" ");for(o=8,n=0;n<a.length&&0<o;n++)(t=a[n].normalize("NFKD").replaceAll(/[^a-zA-Z0-9_]/g,""))&&(o--,i+="_"+t);return i}(e.textContent)),e.setAttribute("id",t),o=t);return o}(e),o=function(e){var t=e.cloneNode(!0),o=["bdi","bdo","del","ins","q","s","small","strike","sub","sup","u"],n=["a","abbr","address","b","blockquote","code","data","em","i","kbd","mark","p","pre","span","strong","time"];return function e(t){var o,n=function(e){var t,o=[];if(void 0===e||void 0===e.childNodes||0===e.childNodes.length)return o;for(t=0;t<e.childNodes.length;t++)i(e.childNodes[t]),o.push(e.childNodes[t]);return o}(t);for(o=0;o<n.length;o++)e(n[o])}(t),t.innerHTML.replace(/<span><\/span>/g,"").trim();function i(e){var t;void 0===e.tagName?e.outerHTML=e.textContent:(t=e.tagName.toLowerCase(),-1!==o.indexOf(t)?e.outerHTML=e.outerHTML:-1!==n.indexOf(t)&&(e.outerHTML="<span>"+e.innerHTML+"</span>"))}}(e)),{title:o,children:[],id:t}}function b(e,t,o){0===o?e.push(h(t)):(0===e.length&&e.push(h("")),o--,b(e[e.length-1].children,t,o))}}function c(e,t){var o=e.getAttribute("data-awb-toc-id");window.awbTocScrollSpies||(window.awbTocScrollSpies={}),o&&(setTimeout((function(){window.awbTocScrollSpies[o]&&(window.awbTocScrollSpies[o].stopListening(),delete window.awbTocScrollSpies[o]),"yes"===t.highlight_current_heading&&(window.awbTocScrollSpies[o]=new window.awbScrollSpy(document.body,{target:"."+e.className.replace(/ /g,"."),currentItemClass:"awb-toc-el__list-item--highlighted",offset:fusionGetScrollOffset()}))}),10),jQuery(window).on("load fusion-sticky-change fusion-sticky-scroll-change",(function(){"object"==typeof window.awbTocScrollSpies[o]&&(window.awbTocScrollSpies[o].options.offset=fusionGetScrollOffset())})),jQuery(window).on("fusion-sticky-transition-change",(function(){setTimeout((function(){"object"==typeof window.awbTocScrollSpies[o]&&(window.awbTocScrollSpies[o].options.offset=fusionGetScrollOffset())}),300)})))}!function(){var e,t,o,i,a,l,d,u,w,f={},h=!1;for(e=0;e<n.length;e++)t=n[e],o=t.getAttribute("data-awb-toc-options"),l=t.getAttribute("data-awb-toc-id"),o&&!t.getAttribute("data-awb-toc-static")&&(o=JSON.parse(o),u="yes"===o.enable_cache,i=s(o),w=r(i,o),u&&(f[l]=i),(a=t.querySelector(".awb-toc-el__content"))&&(!u&&a.childElementCount&&(h=!0),d=!a.innerHTML&&-1===w.indexOf("</li"),a.innerHTML===w||d||(a.innerHTML="",a.insertAdjacentHTML("beforeend",w),u&&(h=!0)),c(n[e],o)));h&&function(e){var t=fusion.getCurrentPostID();if(!t)return;if(document.body.classList.contains("fusion-builder-live-preview"))return;jQuery.ajax({type:"POST",url:awbTOCElementVars.ajaxUrl,data:{action:"awb_save_toc_tree",postId:t,trees:e},dataType:"json"})}(f)}(),0===(t=window.location.hash).indexOf("#toc_")&&jQuery('[href*="'+t+'"]').fusion_scroll_to_anchor_target()}jQuery(document).ready(awbTableOfContentsRefreshAllElements);