| 1 |
window.fluentComPortalGeneral={init(){let e=localStorage.getItem("fcom_global_storage");e?this.globalStates=JSON.parse(e):e={},this.initColorSwitch(),this.initSidebarCollapseToggle(),this.initSidebarCollapsedTips(),document.addEventListener("DOMContentLoaded",()=>{this.initDocReady(),window.fcom_portal_general.scope=="wp"&&this.maybeSetActiveLink()})},initSidebarCollapseToggle(){var e,n;if((n=(e=window.fluentComAdmin)==null?void 0:e.features)!=null&&n.enable_sidebar_toggle&&document.cookie.indexOf("fcom_sidebar_collapsed=")===-1){const i=localStorage.getItem("fcom_sidebar_collapsed")==="true";document.cookie=`fcom_sidebar_collapsed=${i}; path=/; max-age=31536000; SameSite=Lax`,i&&document.documentElement.classList.add("fcom_sidebar_collapsed_desktop")}},initSidebarCollapsedTips(){let e=null;const n=()=>{e&&(e.style.display="none")},i=t=>{if(!document.documentElement.classList.contains("fcom_sidebar_collapsed_desktop")||!t.closest(".fcom_sidebar_wrap"))return;const o=t.getAttribute("data-fcom-tip");if(!o)return;e||(e=document.createElement("div"),e.className="fcom_sidebar_tip",document.body.appendChild(e)),e.textContent=o;const l=t.getBoundingClientRect();e.style.top=l.top+l.height/2+"px",e.style.left=l.right+10+"px",e.style.display="block"};document.addEventListener("mouseover",t=>{const o=t.target.closest("[data-fcom-tip]");o&&i(o)}),document.addEventListener("mouseout",t=>{const o=t.target.closest("[data-fcom-tip]");o&&!o.contains(t.relatedTarget)&&n()}),document.addEventListener("focusin",t=>{const o=t.target.closest("[data-fcom-tip]");o&&i(o)}),document.addEventListener("focusout",t=>{t.target.closest("[data-fcom-tip]")&&n()}),document.addEventListener("scroll",n,!0)},initDocReady(){var e=this;if(document.querySelector(".fcom_top_menu")){const l=document.querySelector(".fcom_top_menu").offsetHeight;document.body.style.setProperty("--fcom-header-height",l+"px");let c=0;const r=document.querySelector(".fcom_mobile_menu");if(r&&(c=r.offsetHeight),document.body.style.setProperty("--fcom-mobile-menu-height",c+"px"),r&&window.visualViewport){var n=window.visualViewport.height;window.visualViewport.addEventListener("resize",function(){var s=window.visualViewport.height<n*.75;document.documentElement.classList.toggle("fcom_keyboard_open",s),document.body.style.setProperty("--fcom-mobile-menu-height",s?"0px":c+"px")})}}this.initMobileSidebar();const i=document.getElementById("fluent_community_sidebar_menu");i&&(i.addEventListener("click",function(l){const c=l.target.closest(".space_section_title");if(!c)return;let r=c.getAttribute("data-group_id"),s=c.closest(".fcom_communities_menu");s&&s.classList.toggle("fcom_group_collapsed");let d=s&&s.classList.contains("fcom_group_collapsed");c.setAttribute("aria-expanded",String(!d)),e.setGroupCollapsed(r,d)}),i.addEventListener("keydown",function(l){if(l.key!=="Enter"&&l.key!==" ")return;const c=l.target.closest(".space_section_title");c&&(l.preventDefault(),c.click())}),this.applySidebarGroupStates());let t=document.querySelector(".feeds_main");if(t){let l=function(c){let r=c.offsetWidth;document.body.style.setProperty("--fcom-main-content-width",r+"px")};var o=l;l(t),window.addEventListener("resize",function(){l(t)})}this.profileMenuInit(),this.watchSpaceCreateLink(),this.initLayoutRef(),this.initScrollEvents(),this.initHideOnScroll(),document.addEventListener("sidebar_menu_reloaded",()=>{this.watchSpaceCreateLink(),this.applySidebarGroupStates()}),document.dispatchEvent(new CustomEvent("fluentComPortalGeneral",{}))},maybeSetActiveLink(){let e=document.querySelectorAll("li a.fcom_custom_link");e.length&&e.forEach(n=>{let i=n.getAttribute("href");window.location.origin+window.location.pathname===i?n.classList.add("router-link-exact-active"):n.classList.remove("router-link-exact-active")})},setCookie(e,n,i=30){let t="";if(i){const o=new Date;o.setTime(o.getTime()+i*24*60*60*1e3),t="; expires="+o.toUTCString()}document.cookie=e+"="+encodeURIComponent(n)+t+"; path=/; SameSite=Lax"},getCookie(e){const n=e+"=",i=document.cookie.split(";");for(let t of i)if(t=t.trim(),t.indexOf(n)===0)return decodeURIComponent(t.substring(n.length));return null},getFromStorage(e,n=""){return this.globalStates&&this.globalStates[e]||n},setToStorage(e,n){this.globalStates||(this.globalStates={}),this.globalStates[e]=n,localStorage.setItem("fcom_global_storage",JSON.stringify(this.globalStates))},getGroupStates(){const e={};return(this.getCookie("fcom_sidebar_group_states")||"").split("|").forEach(n=>{const i=n.indexOf(":");if(i===-1)return;const t=n.slice(0,i);t!=="c"&&t!=="e"||n.slice(i+1).split(",").filter(Boolean).forEach(o=>{e[o]=t==="c"?"collapsed":"expanded"})}),e},setGroupCollapsed(e,n){const i=this.getGroupStates();i[e]=n?"collapsed":"expanded";const t=[],o=[];Object.keys(i).forEach(c=>{i[c]==="collapsed"?t.push(c):i[c]==="expanded"&&o.push(c)});const l=[];t.length&&l.push("c:"+t.join(",")),o.length&&l.push("e:"+o.join(",")),this.setCookie("fcom_sidebar_group_states",l.join("|"),365)},applySidebarGroupStates(){const e=window.location.pathname.replace(/\/$/,""),n=this.getGroupStates(),i=!!(window.fcom_portal_general&&window.fcom_portal_general.collapse_sidebar_groups);document.querySelectorAll(".space_section_title").forEach(t=>{let o=t.closest(".fcom_communities_menu");if(!o)return;if(this.groupHasActiveLink(o,e)){o.classList.remove("fcom_group_collapsed"),t.setAttribute("aria-expanded","true");return}const l=n[t.getAttribute("data-group_id")];l==="collapsed"?o.classList.add("fcom_group_collapsed"):l==="expanded"?o.classList.remove("fcom_group_collapsed"):o.classList.toggle("fcom_group_collapsed",i),t.setAttribute("aria-expanded",String(!o.classList.contains("fcom_group_collapsed")))})},groupHasActiveLink(e,n){if(e.querySelector("a.router-link-exact-active, a.router-link-active"))return!0;const i=e.querySelectorAll("a[href]");for(let t=0;t<i.length;t++){let o=i[t].pathname;if(o.length>1&&o.endsWith("/")&&(o=o.slice(0,-1)),o===n)return!0}return!1},initMobileSidebar(){let e=document.querySelectorAll(".fcom_space_opener_btn");if(!e.length)return;function n(i){i.target.closest(".fcom_group_title")||i.target.closest(".fcom_space_opener_btn")||(document.querySelector(".space_opened")&&document.querySelector(".space_opened").classList.remove("space_opened"),document.removeEventListener("click",n))}e.forEach(i=>{i.addEventListener("click",function(){document.querySelector(".feed_layout")&&document.querySelector(".feed_layout").classList.toggle("space_opened"),document.querySelector(".feed_layout").classList.contains("space_opened")?setTimeout(()=>{document.addEventListener("click",n)},0):document.removeEventListener("click",n)})})},initColorSwitch(){var i;if(!window.fcom_portal_general||!window.fcom_portal_general.has_color_scheme||document.body.classList.contains("fcom_disable_dark_mode"))return document.querySelectorAll(".fcom_mode_switch").forEach(o=>{o.style.display="none"}),!1;var e=this;document.querySelectorAll(".fcom_mode_switch").forEach(t=>{t.addEventListener("click",function(){var o=document.documentElement.classList.contains("dark")?"light":"dark";e.fcomSetColorMode(o),document.querySelector(".feed_layout")&&document.querySelector(".feed_layout").classList.remove("space_opened")})});let n=e.getFromStorage("fcom_color_mode","");if((i=window.fcom_portal_general)!=null&&i.color_switch_cookie_name){let t=this.getCookie(window.fcom_portal_general.color_switch_cookie_name);(t=="dark"||t=="light")&&(n=t)}n&&this.fcomSetColorMode(n)},fcomSetColorMode(e){var t;if(!["dark","light"].includes(e))return!1;let i="dark";e=="dark"&&(i="light"),document.documentElement.classList.remove(i),e&&(document.documentElement.classList.add(e),document.documentElement.setAttribute("data-color-mode",e),(t=window.fcom_portal_general)!=null&&t.color_switch_cookie_name&&this.setCookie(window.fcom_portal_general.color_switch_cookie_name,e)),this.setToStorage("fcom_color_mode",e)},profileMenuInit(){const e=document.getElementsByClassName("fcom_profile_extend");e.length&&[...e].forEach(n=>{let i=n.querySelector(".fcom_profile_menu"),t=n.querySelector(".fcom_profile_sub_menu");if(!i||!t)return;function o(l){n.classList.remove("fcom_extend_menu"),document.removeEventListener("click",o)}i.addEventListener("click",function(l){n.classList.toggle("fcom_extend_menu"),n.classList.contains("fcom_extend_menu")&&setTimeout(()=>{document.addEventListener("click",o)},0)})})},initLayoutRef(){window.fcomLayoutRef={wrapRef:{get scrollTop(){return window.scrollY},get scrollHeight(){return document.documentElement.scrollHeight},get clientHeight(){return window.innerHeight},getBoundingClientRect(){return{top:0,bottom:window.innerHeight,height:window.innerHeight,left:0,right:window.innerWidth,width:window.innerWidth}}},scrollTo:e=>window.scrollTo(e),setScrollTop:e=>window.scrollTo({top:e,behavior:"instant"})}},initScrollEvents(){const e=document.querySelector(".fcom_fallback_wp_content"),n=e||window,i=e?()=>e.scrollTop:()=>window.scrollY,t=e?()=>e.scrollHeight:()=>document.documentElement.scrollHeight,o=e?()=>e.clientHeight:()=>window.innerHeight;let l=!1;n.addEventListener("scroll",()=>{l||(l=!0,requestAnimationFrame(()=>{const c=i(),r=t(),s=o(),d=r-c-s<=1,m=r-s>100;document.dispatchEvent(new CustomEvent("fcom_layout_scroll",{detail:{scrollTop:c,atBottom:d,pageScrollable:m}})),l=!1}))},{passive:!0})},initHideOnScroll(){const n="down",i="up",t=window.matchMedia("(max-width: 768px)"),o=document.body.classList;let l=0,c=0,r=null;const s=()=>{o.remove("fcom_scrolling-down","fcom_scrolling-down_mbl")},d=()=>{o.add("fcom_scrolling-down"),!!(window.fcom_portal_general&&window.fcom_portal_general.hide_header_on_scroll)&&t.matches&&o.add("fcom_scrolling-down_mbl")},m=a=>{r!==a&&(r=a,c=l)};document.addEventListener("fcom_layout_scroll",a=>{const{scrollTop:u,atBottom:_,pageScrollable:g}=a.detail;if(u<=0||!g)s(),r=null,c=u;else{const p=u-l;p>0?(m(n),u-c>=100&&d()):p<0&&!_&&(m(i),c-u>=100&&s())}l=Math.max(0,u)}),t.addEventListener("change",a=>{a.matches||o.remove("fcom_scrolling-down_mbl")}),window.addEventListener("popstate",s);const f=()=>{o.contains("fcom_scrolling-down_mbl")&&s()};document.addEventListener("keydown",a=>{a.key==="Tab"&&f()}),document.addEventListener("focusin",a=>{a.target.matches(":focus-visible")&&f()})},watchSpaceCreateLink(){let e=document.querySelectorAll(".fcom_space_create_link");e.length&&e.forEach(n=>{n.addEventListener("click",function(i){const t=window.fluentFrameworkApp;if(!t||!t.$eventBus)return;const o=n.getAttribute("data-parent_id");o&&(i.stopPropagation(),i.preventDefault(),t.$eventBus.emit("createSpaceModal",{parent_id:o}))})})}};window.fluentComPortalGeneral.init(); |