!function(){const{on:e,trigger:t}=window.ivent;new class{constructor(){const t=this;t.cache={},t.pendingAjax=!1,t.xhrAjaxSearch=!1,t.$preloader=document.createElement("div"),t.$preloader.className="docspress-preloader",t.$preloader.innerHTML="<span><span></span></span>",t.$singleAjax=document.querySelector(".docspress-single-ajax"),t.initEarlier(),e(document,"ready",(()=>{t.init()}))}stripHash(e){return e.replace(/#.*/,"")}initEarlier(){this.initSidebarScroll()}init(){this.initSearch(),this.initDocSearch(),this.initAnchors(),this.initFeedbacks(),this.initAjax()}initSearch(){const t=this;let s=!1;e(document,"submit",".docspress-search-form",(e=>{e.preventDefault(),t.prepareSearchResults(e.delegateTarget)})),e(document,"input",".docspress-search-form",(e=>{e.preventDefault(),clearTimeout(s),s=setTimeout((()=>{t.prepareSearchResults(e.delegateTarget)}),500)}))}prepareSearchResults(e){var t;const s=this;if(s.xhrAjaxSearch&&s.xhrAjaxSearch.abort(),null===(t=e.querySelector(".docspress-search-field"))||void 0===t||!t.value)return e.nextElementSibling.querySelector(".docspress-search-form-result").innerHTML="",void e.classList.remove("docspress-search-form-existence");let n=e.getAttribute("action");n+=(-1<n.indexOf("?")?"&":"?")+new URLSearchParams(new FormData(e)).toString(),s.xhrAjaxSearch=new XMLHttpRequest,s.xhrAjaxSearch.open("GET",n),s.xhrAjaxSearch.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),s.xhrAjaxSearch.onload=function(){if(200===s.xhrAjaxSearch.status){const t=(new DOMParser).parseFromString(s.xhrAjaxSearch.responseText,"text/html").querySelector(".docspress-search-list").outerHTML,n=e.parentElement.querySelector(":scope > .docspress-search-form-result");n&&(n.innerHTML=t),e.classList.add("docspress-search-form-existence")}else console.log("Error:",s.xhrAjaxSearch.status)},s.xhrAjaxSearch.onerror=function(){console.log("Request failed"),s.xhrAjaxSearch=!1},s.xhrAjaxSearch.send()}initDocSearch(){void 0!==window.docsearch&&document.querySelectorAll(".docspress-docsearch").forEach((e=>{const t=e.getAttribute("data-docsearch-app-id"),s=e.getAttribute("data-docsearch-api-key"),n=e.getAttribute("data-docsearch-index-name");t&&s&&n&&window.docsearch({appId:t,apiKey:s,indexName:n,container:e,debug:!1})}))}initAnchors(){const e=!!window.AnchorJS&&new window.AnchorJS;e&&(e.options={placement:"right",visible:"hover",icon:"#"},e.add(".docspress-single-content .entry-content h2, .docspress-single-content .entry-content h3, .docspress-single-content .entry-content h4"))}initFeedbacks(){const t=this;e(document,"click",".docspress-single-feedback a",(e=>{t.onFeedbackClick(e)})),e(document,"submit",".docspress-single-feedback + .docspress-single-feedback-suggestion",(e=>{t.onFeedbackSuggestionSend(e)}))}initSidebarScroll(){const e=document.querySelector(".docspress-single-sidebar-wrap");if(!e||e.scrollHeight<=e.clientHeight)return;const t=e.querySelector(".current_page_item");if(!t)return;const s=t.querySelector(":scope > a"),n=s.getBoundingClientRect().top,o=e.getBoundingClientRect().top,r=e.scrollTop,i=e.clientHeight,a=n+r-o,c=s.clientHeight,d=a-i+c;(e.scrollTop>a||e.scrollTop<d)&&(e.scrollTop=a-i/2+c/2)}initAjax(){var t;const s=this;if(!s.$singleAjax)return;s.setCache(window.location.href,{href:window.location.href,editHref:null===(t=document.querySelector("#wp-admin-bar-edit .ab-item"))||void 0===t?void 0:t.getAttribute("href"),title:document.title,doc:s.$singleAjax.innerHTML,html:document.documentElement.outerHTML}),e(s.$singleAjax,"click",".docspress-nav-list a, .docspress-single-breadcrumbs a, .docspress-single-articles a, .docspress-single-adjacent-nav a, .docspress-search-form-result a",(e=>{s.onDocLinksClick(e)}));let n=document.location.pathname,o="";e(window,"popstate",(e=>{o=document.location.pathname,o!==n&&s.renderDoc(e.delegateTarget.location.href),n=o}))}onFeedbackClick(e){e.preventDefault();const t=this,s=e.delegateTarget;if(t.pendingAjax)return;t.pendingAjax=!0;const n=s.closest(".docspress-single-feedback"),o=s.closest(".docspress-single-content").querySelector(".docspress-single-feedback-suggestion");n.classList.add("docspress-single-feedback-loading");const r=s.getAttribute("data-type"),i={post_id:s.getAttribute("data-id"),type:r,action:"docspress_ajax_feedback",_wpnonce:window.docspress_vars.nonce};n.appendChild(t.$preloader.cloneNode(!0)),fetch(window.docspress_vars.ajaxurl,{method:"POST",body:new URLSearchParams(i)}).then((e=>e.json())).then((e=>{n.innerHTML="<div>".concat(e.data,"</div>"),e.success&&o&&(o.style.display="block",o.innerHTML+='<input type="hidden" name="feedback_type" value="'.concat(r,'">')),n.classList.remove("docspress-single-feedback-loading"),t.pendingAjax=!1}))}onFeedbackSuggestionSend(e){e.preventDefault();const t=this,s=e.delegateTarget;if(t.pendingAjax)return;t.pendingAjax=!0;const n=s.closest(".docspress-single-feedback-suggestion"),o=s.querySelector("button");n.classList.add("docspress-single-feedback-suggestion-loading");const r=Array.from(new FormData(s)).reduce(((e,t)=>{let[s,n]=t;return e[s]=n,e}),{}),i={post_id:r.id,from:r.from,suggestion:r.suggestion,feedback_type:r.feedback_type,action:"docspress_ajax_feedback_suggestion",_wpnonce:window.docspress_vars.nonce};n.appendChild(t.$preloader.cloneNode(!0)),o.disabled=!0,fetch(window.docspress_vars.ajaxurl,{method:"POST",body:new URLSearchParams(i)}).then((e=>e.json())).then((e=>{n.innerHTML="<div>".concat(e.data,"</div>"),n.classList.remove("docspress-single-feedback-suggestion-loading"),t.pendingAjax=!1}))}setCache(e,t){t=t||!1,(e=e||!1)&&t&&!this.cache[e]&&(this.cache[e]=t)}getCache(e){return!(!(e=e||!1)||!this.cache[e])&&this.cache[e]}renderDoc(e){const s=this.getCache(e);var n;this.$singleAjax.innerHTML=s.doc,document.title=s.title,s.editHref&&(null===(n=document.querySelector("#wp-admin-bar-edit .ab-item"))||void 0===n||n.setAttribute("href",s.editHref));const o=document.querySelector(".docspress-single"),{top:r}=o.getBoundingClientRect();0>r&&o&&o.scrollIntoView(),this.initAnchors(),t(document,"docspress_ajax_loaded",{data:s})}onDocLinksClick(e){const t=e.delegateTarget;1<e.which||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||window.location.protocol===t.protocol&&window.location.hostname===t.hostname&&(-1<t.href.indexOf("#")&&this.stripHash(t.href)===this.stripHash(window.location.href)||"file:"!==window.location.protocol&&(e.defaultPrevented||(e.preventDefault(),this.loadDocPage(t.href))))}loadDocPage(e){const t=this;if(!(e=e||!1)||t.stripHash(e)===t.stripHash(window.location.href))return;const s=t.getCache(e);if(s)return t.renderDoc(e),void window.history.pushState(null,s.title,e);t.xhr&&t.xhr.abort&&(t.xhr.abort(),t.xhr={});const n=new XMLHttpRequest;t.$singleAjax.classList.add("docspress-single-ajax-loading"),t.$singleAjax.querySelector(".docspress-single-content").appendChild(t.$preloader.cloneNode(!0)),n.open("GET",e),n.onload=function(){if(200===n.status){var s,o;const r=n.responseText;if(!r)return void(window.location=e);let i=document.createElement("div");i.innerHTML=r;const a=i.querySelector("title").textContent||document.title,c=null===(s=i.querySelector("#wp-admin-bar-edit .ab-item"))||void 0===s?void 0:s.getAttribute("href"),d=null===(o=i.querySelector(".docspress-single-ajax"))||void 0===o?void 0:o.innerHTML;if(!d)return void(window.location=e);t.setCache(e,{href:e,editHref:c,title:a,doc:d,html:r}),t.renderDoc(e),window.history.pushState(null,a,e),i.remove(),i=null,t.$singleAjax.classList.remove("docspress-single-ajax-loading")}else 0!==n.status?console.log("error",n):window.location=e,t.$singleAjax.classList.remove("docspress-single-ajax-loading")},n.send()}}}();