(()=>{"use strict";const{flextension:e,trippApp:t,DOMParser:n,URL:i,FormData:s,history:r,setTimeout:a}=window;new class{constructor(){this.settings={container:"#site-content",exclude:{links:[],selectors:[]}},"object"==typeof t.settings.singlePage&&(this.settings=Object.assign(this.settings,t.settings.singlePage)),this.container=document.querySelector(this.settings.container),null!==this.container&&(this.query={},this.placeholders=[".archive-image",".archive-title",".archive-description",".posts-count",".main-posts .posts-list"],this.scrollTarget=this.container,this.init())}init(){t.router.onPopState=e=>{if(null!==e&&null!==e.state){const n=window.location.href.replace(/\/$/,"");if(n!==t.router.currentURL&&t.router.routers[e.state.routerId]){const i=Object.assign({},t.router.query);t.router.currentURL=n,t.router.query=e.state.query,!0===e.state.done?"ajaxPagination"===e.state.routerId&&i.path!==e.state.query.path?this.getPage(n,e.state.query):t.router.routers[e.state.routerId].done(n,e.state.query).then((()=>{e.state.scrollPosition&&window.scrollTo({top:e.state.scrollPosition.y,left:e.state.scrollPosition.x,behavior:"instant"})})):t.router.routers[e.state.routerId].fail(n,e.state.error)}}},t.on("router.pushState",((e,t)=>{if(!t.error){const e=Object.assign({},r.state||{},{scrollPosition:{x:window.scrollX,y:window.scrollY}});r.replaceState(e,"",window.location.href.replace(/\/$/,""))}t.scrollPosition={x:window.scrollX,y:window.scrollY}})),this.router=t.router.create("singlePage",((e,t)=>this.getPage(e,t)),(e=>this.getPage(e,{id:-1}))),t.router.parse().then((e=>{if(!1===e)return;const t={routerId:this.router.id,done:!0,scrollPosition:{x:window.scrollX,y:window.scrollY},query:e};r.pushState(t,"",window.location.href)})),this.initExcludingList(),t.on("singlePage.initLinks",((e,t)=>{this.initLinks(t)})),t.on("ready",((e,t)=>{t&&this.ready(t)})),this.ready()}initExcludingList(){this.excludingLinks=["wp-login","wp-admin/","wp-content/","wp-includes/"],this.excludingSelectors=['.no-ajax, .pagination a, .comments-section .loadmore-pagination a, .comment-reply-link, #cancel-comment-reply-link, a[href$=".jpg"], a[href$=".jpeg"], a[href$=".png"], a[href$=".gif"], a[href$=".bmp"], a[href$=".mp4"], a[href$=".mov"], a[href$=".ogv"], a[href$=".ogg"], a[href$=".webm"]'],"object"==typeof this.settings.exclude&&("object"==typeof this.settings.exclude.links&&this.settings.exclude.links.forEach((e=>{e&&this.excludingLinks.push(e)})),"object"==typeof this.settings.exclude.selectors&&this.settings.exclude.selectors.forEach((e=>{e&&this.excludingSelectors.push(e)})))}ready(e){e||(e=document),this.initSearchForm(e),this.initWidgets(e),this.initMainContent(e),this.afterGetPage(),t.emit("singlePage.ready")}isValidLink(e){if(!e)return!1;if(e.onclick)return!1;const t=new i(e.toString());return!(!t||t.href.startsWith("#")||t.pathname===location.pathname&&t.search===location.search&&t.hash)}isExcludingURL(e){let t=!1;for(const n in this.excludingLinks)if(new RegExp(this.excludingLinks[n],"i").test(e)){t=!0;break}return t}isExcludingLink(e){for(let t=0;t<this.excludingSelectors.length;t++)if(e.matches(this.excludingSelectors[t]))return!0;return!1}isInternal(e){if(!e)return!1;const t=e.getAttribute("href");let n=e.hostname===location.hostname;return(t&&t.startsWith("#")||e.getAttribute("target")&&"_self"!==e.getAttribute("target"))&&(n=!1),n}initLinks(e){e||(e=document);const n=[];"A"===e.tagName?n.push(e):e.querySelectorAll("a:not(.ajax-page)").forEach((e=>{this.isInternal(e)&&!this.isExcludingLink(e)&&n.push(e)})),n.forEach((e=>{e.classList.add("ajax-page"),this.isValidLink(e)&&e.addEventListener("click",(n=>{if(n.defaultPrevented)return!0;this.isExcludingURL(e.href)||this.isExcludingURL(location.href)?this.beforeGetPage(!1):(n.preventDefault(),this.navigate(e.href,!0)),t.emit("singlePage.linkClick",e,this)}))})),t.emit("singlePage.afterInitLinks",n,this)}navigate(e,n){t.emit("singlePage.beforeNavigate",e),this.router.get(e,n),t.emit("singlePage.afterNavigate",e)}initSearchForm(e){this.isExcludingURL(location.href)||(e||(e=document),e.querySelectorAll(".search-form").forEach((e=>{e.addEventListener("submit",(t=>{t.preventDefault();const n=e.getAttribute("action")||window.location.href,r=new i(n);new s(e).forEach(((e,t)=>{r.searchParams.set(t,e)})),this.navigate(r,!0)}))})))}initMainContent(e){document.body.classList.contains("singular")&&this.initComments(),this.initLinks(e)}initComments(){this.isExcludingURL(location.href)||(void 0!==window.addComment&&window.addComment.init(),document.querySelectorAll(".comment-form").forEach((e=>{e.addEventListener("submit",(t=>{t.preventDefault();const{FormData:n}=window,i=new n(e),s={};s.post=i.get("comment_post_ID"),s.parent=i.get("comment_parent"),s.author_email=i.get("email"),s.author_name=i.get("author"),s.author_url=i.get("url"),s.content=i.get("comment");let r=!0;s.content||(r=!1),null!==document.querySelector(".logged-in-as")||s.author_email&&s.author_name||(r=!1),!0===r&&this.addComment(s)}))})))}updateUrlParam(e,t,n){return e.replace(new RegExp("([?&]"+t+"(?=[=&#]|$)[^#&]*|(?=#|$))"),"&"+t+"="+encodeURIComponent(n)).replace(/^([^?&]+)&/,"$1?")}getQuery(e){return e||(e={}),"/"===e.path&&(e.path=""),e}beforeGetPage(e){if(t.emit("singlePage.beforeGetPage",this),this.container.classList.remove("is-loaded"),this.container.classList.add("is-loading"),!e)return;this.container.classList.add("partial-content");const n=this.placeholders.join(",");n&&this.container.querySelectorAll(n).forEach((e=>{e.classList.add("has-content-placeholder")})),this.pageReady=!1,this.scrollTarget?t.scrollTo(this.scrollTarget,(()=>{this.pageContent?(this.updatePage(this.pageContent),this.pageContent=null):this.pageReady=!0})):this.pageContent?(this.updatePage(this.pageContent),this.pageContent=null):this.pageReady=!0}getPage(e,t){return this.query=this.getQuery(t),this.beforeGetPage(!0),this.restPage(e,this.query)}restPage(t,n){return e.api.get("/tripp-xt/v1/page-renderer",n,null,{referrer:t}).then((e=>{!0===this.pageReady?this.updatePage(e):this.pageContent=e})).catch((()=>{location.reload()})).finally((()=>{this.afterGetPage()}))}ajaxPage(e){return window.fetch(e).then((e=>e.text())).then((e=>{const t=(new n).parseFromString(e,"text/html"),i=[];t.querySelectorAll(".main-menu li").forEach((e=>{i.push(e.getAttribute("class"))}));const s=t.querySelector("#flextension-extensions-inline-css"),r={title:t.title,bodyClass:t?t.body.getAttribute("class"):"",editMenu:t.querySelector("#wp-admin-bar-edit > .ab-item"),menuClasses:i,customStyles:null!==s?s.innerHTML:"",rendered:t.querySelector(this.settings.container)};!0===this.pageReady?this.updatePage(r):this.pageContent=r})).catch((()=>{location.reload()})).finally((()=>{this.afterGetPage()}))}afterGetPage(){const e=this.placeholders.join(",");e&&this.container.querySelectorAll(e).forEach((e=>{e.classList.remove("has-content-placeholder")})),this.container.classList.remove("partial-content","is-loading"),this.container.classList.add("is-loaded"),t.emit("singlePage.afterGetPage",this)}beforeUpdatePage(){t.emit("singlePage.beforeUpdatePage",this)}updatePage(e){this.beforeUpdatePage(),this.updatePageInfo(e),this.container.innerHTML=e.rendered,this.initMainContent(this.container),this.sendPageView(),this.afterUpdatePage()}afterUpdatePage(){this.updateContentStyles(),this.container.classList.add("is-loaded"),t.emit("singlePage.afterUpdatePage",this.container,this)}updatePageInfo(e){if(e.title){const t=document.querySelector("title");null!==t?t.innerHTML=e.title:document.title=e.title}this.updateBodyClass(e.bodyClass),this.updateCustomStyles(e.customStyles),this.updateAdminBar(e.editMenu),this.updateMenuClass(e.menuClasses)}updateBodyClass(e){if(e){const n=(e=e.replace("no-customize-support","customize-support")).split(" ").map((e=>e.trim())),i=n.indexOf("has-scheme-auto");if(i>-1&&n.splice(i,1),t.isDarkMode){const e=n.indexOf("has-scheme-light");e>-1&&n.splice(e,1),n.includes("has-scheme-dark")||n.push("has-scheme-dark")}else{const e=n.indexOf("has-scheme-dark");e>-1&&n.splice(e,1),n.includes("has-scheme-light")||n.push("has-scheme-light")}document.body.setAttribute("class",[...new Set(n)].join(" "))}}updateCustomStyles(e){let t=document.querySelector("#flextension-extensions-inline-css");null===t&&(t=document.createElement("style"),t.setAttribute("id","flextension-extensions-inline-css"),document.head.append(t)),t.innerHTML=e||""}updateContentStyles(){document.querySelectorAll("body > style").forEach((e=>{if(e&&e.sheet){const t=e.sheet.cssRules;for(let n=0;n<t.length;n++)if(t[n].selectorText&&t[n].selectorText.indexOf(".wp-container-")>-1)return void e.remove()}})),document.querySelectorAll("#content-footer > link, #content-footer > style, #content-footer > script").forEach((e=>{const t=document.head.querySelector("#"+e.getAttribute("id"));(e&&null!==t||null!==document.body.querySelector("#"+e.getAttribute("id")))&&e.remove()}))}updateAdminBar(e){if(null===document.getElementById("wpadminbar"))return;let t=document.getElementById("wp-admin-bar-edit");if(e){if(null===t){t=document.createElement("li"),t.setAttribute("id","wp-admin-bar-edit"),t.innerHTML='<a class="ab-item" href="#">Edit Post</a>';const e=document.getElementById("wp-admin-bar-root-default");null!==e&&e.append(t)}t.style.display="";const n=t.querySelector(".ab-item");null!==n&&(n.setAttribute("href",decodeURI(e.href)),n.innerHTML=e.title)}else null!==t&&t.remove();const n=document.querySelector("#wp-admin-bar-customize .ab-item");if(null!==n){const e=n.getAttribute("href");n.setAttribute("href",this.updateUrlParam(e,"url",document.URL))}}updateMenuClass(e){e&&e.forEach((e=>{const t=e.match(/menu-item-(\d+)/g);t&&t.length&&t[0]&&document.querySelectorAll("."+t[0]).forEach((t=>{t.classList.contains("is-visible")&&(e+=" is-visible"),t.classList.contains("is-sub-menu-visible")&&(e+=" is-sub-menu-visible"),t.setAttribute("class",e)}))}))}sendPageView(){"function"==typeof window.ga&&window.ga("send","pageview",location.pathname)}addComment(t,n){e.api.post("/tripp-xt/v1/comments",t,(e=>{this.updateCommentsCount(e.headers.get("X-WP-Total"))}),{referrer:n}).then((e=>{e.message?this.setCommentStatus(e.message):this.showComment(t.parent,e)}))}updateCommentsCount(e){const t=this.container.querySelector(".toggle-comments > span");null!==t&&(t.innerText=t.innerText.replace(/\(.+\)/g,`(${e})`))}setCommentStatus(e){let t=document.querySelector(".comment-form .status-text");if(null===t){t=document.createElement("p"),t.classList.add("status-text");const e=document.querySelector(".comment-form .form-submit");null!==e&&e.parentElement.insertBefore(t,e)}t.style.display="",t.innerHTML=e}showComment(e,i){const s=document.querySelector(".comment-form textarea");null!==s&&(s.value="");const r=document.getElementById("cancel-comment-reply-link");null!==r&&"none"!==r.style.display&&r.click();const o=document.querySelector(".comment-form .status-text");null!==o&&(o.innerHTML="",o.style.display="none");const l=(new n).parseFromString(i,"text/html"),c=l?l.body.firstChild:null;if(null!==c){if(c.classList.add("new-comment-hidden","new-comment-active"),e&&0!==parseInt(e,10)){const t=document.getElementById("comment-"+e);if(null!==t){let e=t.querySelector(".children");null===e&&(e=document.createElement("ol"),e.classList.add("children"),t.append(e)),e.append(c)}}else{let e=this.container.querySelector(".comment-list");if(null===e){e=document.createElement("ol"),e.classList.add("comment-list");const t=this.container.querySelector("#respond");null!==t&&t.parentElement.insertBefore(e,t)}e.append(c)}t.scrollTo(c),c.classList.remove("new-comment-hidden"),a((()=>{c.classList.remove("new-comment-active")}),3e3),this.initLinks(c)}}parseLinkHeader(e){if(0===e.length)return!1;const t=e.split(","),n={};return t.forEach((e=>{const t=e.split(";");if(2!==t.length)return!1;const i=t[0].replace(/<(.*)>/,"$1").trim(),s=t[1].replace(/rel="(.*)"/,"$1").trim();n[s]=i})),n}initWidgets(e){this.isExcludingURL(location.href)||(e.querySelectorAll('select[name="archive-dropdown"]').forEach((e=>{e.removeAttribute("onchange"),e.onchange=null,e.addEventListener("change",(()=>{e.value&&this.navigate(e.value,!0)}))})),e.querySelectorAll('.widget_categories select[name="cat"]').forEach((e=>{let n=t.router.root.href;const i=e.closest("form");null!==i&&(n=i.getAttribute("action")),n&&(e.removeAttribute("onchange"),e.onchange=null,e.addEventListener("change",(()=>{if("-1"!==e.value){let i="";i=!0===t.router.settings.permalink?n+"/"+t.router.settings.taxonomies.category_name+"/"+e.value:this.updateUrlParam(n,"cat",e.value),this.navigate(i,!0)}return!0})))})))}}})();