|
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(); |
|
1
|
+window.fluentComPortalGeneral={init(){let e=localStorage.getItem("fcom_global_storage");if(!e)e={};else try{this.globalStates=JSON.parse(e)}catch{this.globalStates={}}this.initColorSwitch(),this.initSidebarCollapseToggle(),this.initSidebarCollapsedTips(),this.initIosPwaPullToRefresh(),this.initPwa(),document.addEventListener("DOMContentLoaded",()=>{this.initDocReady(),this.initSidebarToggleButton(),window.fcom_portal_general.scope=="wp"&&this.maybeSetActiveLink()})},isSidebarToggleEnabled(){var e;return!!((e=window.fcom_portal_general)!=null&&e.enable_sidebar_toggle)},initSidebarCollapseToggle(){if(this.isSidebarToggleEnabled()&&document.cookie.indexOf("fcom_sidebar_collapsed=")===-1){const e=localStorage.getItem("fcom_sidebar_collapsed")==="true";document.cookie=`fcom_sidebar_collapsed=${e}; path=/; max-age=31536000; SameSite=Lax`,e&&document.documentElement.classList.add("fcom_sidebar_collapsed_desktop")}},initSidebarToggleButton(){var t;if(!this.isSidebarToggleEnabled())return;const e=document.querySelector(".feed_layout .spaces");if(!e||e.querySelector(".fcom_sidebar_float_toggle"))return;const o=!document.documentElement.classList.contains("fcom_sidebar_collapsed_desktop"),i=document.createElement("button");i.type="button",i.className="fcom_sidebar_float_toggle fcom_desktop_only",i.setAttribute("aria-label",((t=window.fcom_portal_general)==null?void 0:t.sidebar_toggle_label)||"Toggle sidebar"),i.setAttribute("aria-controls","fcom_sidebar_wrap"),i.setAttribute("aria-expanded",String(o)),i.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polyline points="15 6 9 12 15 18"/></svg>',i.addEventListener("click",()=>this.toggleSidebarCollapsed()),e.appendChild(i)},toggleSidebarCollapsed(){const e=document.documentElement.classList.toggle("fcom_sidebar_collapsed_desktop");document.cookie=`fcom_sidebar_collapsed=${e}; path=/; max-age=31536000; SameSite=Lax`;try{localStorage.setItem("fcom_sidebar_collapsed",String(e))}catch{}document.querySelectorAll(".fcom_sidebar_float_toggle").forEach(o=>o.setAttribute("aria-expanded",String(!e)))},initSidebarCollapsedTips(){let e=null;const o=()=>{e&&(e.style.display="none")},i=t=>{if(!document.documentElement.classList.contains("fcom_sidebar_collapsed_desktop")||!t.closest(".fcom_sidebar_wrap"))return;const n=t.getAttribute("data-fcom-hint");if(!n)return;e||(e=document.createElement("div"),e.className="fcom_sidebar_tip",document.body.appendChild(e)),e.textContent=n;const s=t.getBoundingClientRect();e.style.top=s.top+s.height/2+"px",e.style.left=s.right+10+"px",e.style.display="block"};document.addEventListener("mouseover",t=>{const n=t.target.closest("[data-fcom-hint]");n&&i(n)}),document.addEventListener("mouseout",t=>{const n=t.target.closest("[data-fcom-hint]");n&&!n.contains(t.relatedTarget)&&o()}),document.addEventListener("focusin",t=>{const n=t.target.closest("[data-fcom-hint]");n&&i(n)}),document.addEventListener("focusout",t=>{t.target.closest("[data-fcom-hint]")&&o()}),document.addEventListener("scroll",o,!0)},isPwaPage(){var e;return!!((e=window.fcom_portal_general)!=null&&e.pwa&&document.querySelector('link[rel="manifest"][href*="fcom_pwa=manifest"]'))},initPwa(){var c,u;if(!this.isPwaPage())return;const e=window.fcom_portal_general.pwa;if(this.syncPwaThemeColor(),e.install_entry!=="yes"||!document.querySelector(".fcom_pwa_install_row")||window.matchMedia("(display-mode: standalone)").matches||window.navigator.standalone===!0)return;const i=e.install_dismissible==="yes",t=this.getFromStorage("fcom_pwa_install_dismissed",0);if(i&&t&&new Date().getTime()<t)return;let n=null;const s=r=>{var m;if(!r&&((m=document.activeElement)!=null&&m.closest(".fcom_pwa_install_row"))){const p=document.querySelector("#fcom_sidebar_wrap");p&&(p.setAttribute("tabindex","-1"),p.focus())}document.querySelectorAll(".fcom_pwa_install_row").forEach(p=>{p.classList.toggle("fcom_pwa_available",r)})},a=navigator.userAgent||"",d=/iP(hone|ad|od)/.test(a)||/Macintosh/.test(a)&&navigator.maxTouchPoints>1;let l=null;/Android/.test(a)&&/Firefox/.test(a)?l=((c=e.install_instructions)==null?void 0:c.android)||null:d&&(l=((u=e.install_instructions)==null?void 0:u.ios)||null),l&&s(!0),window.addEventListener("beforeinstallprompt",r=>{r.preventDefault(),n=r,s(!0)}),window.addEventListener("appinstalled",()=>{n=null,s(!1)}),document.addEventListener("click",r=>{if(i&&r.target.closest(".fcom_pwa_install_dismiss")){this.setToStorage("fcom_pwa_install_dismissed",new Date().getTime()+7*24*60*60*1e3),s(!1);return}r.target.closest(".fcom_pwa_install_btn")&&(n?(n.prompt(),n.userChoice.finally(()=>{n=null,s(!1)})):l&&this.showPwaInstallInstructions(l))})},showPwaInstallInstructions(e){const o=this;o._closePwaInstruct&&o._closePwaInstruct();const i=document.activeElement,t=document.createElement("div");t.className="fcom_pwa_instruct_overlay";const n=document.createElement("div");n.className="fcom_pwa_instruct_modal",n.setAttribute("role","dialog"),n.setAttribute("aria-modal","true"),n.setAttribute("aria-labelledby","fcom_pwa_instruct_title");const s=document.createElement("div");s.className="fcom_pwa_instruct_header";const a=document.createElement("div");a.className="fcom_pwa_instruct_heading";const d=document.createElement("h3");d.id="fcom_pwa_instruct_title",d.textContent=e.title||"",a.appendChild(d);const l=document.createElement("button");l.type="button",l.className="fcom_pwa_instruct_close",l.setAttribute("aria-label",e.close_label||"Close"),l.innerHTML='<svg viewBox="0 0 1024 1024" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M764.288 214.592 512 466.88 259.712 214.592a31.936 31.936 0 0 0-45.12 45.12L466.752 512 214.528 764.224a31.936 31.936 0 1 0 45.12 45.12L512 557.184l252.288 252.288a31.936 31.936 0 0 0 45.12-45.12L557.12 512l252.288-252.224a31.936 31.936 0 1 0-45.12-45.184z"/></svg>',s.append(a,l);const c=e.app||{},u=document.createElement("div");if(u.className="fcom_pwa_instruct_app",c.icon){const f=document.createElement("img");f.className="fcom_pwa_instruct_icon",f.src=c.icon,f.alt="",u.appendChild(f)}const r=document.createElement("div");r.className="fcom_pwa_instruct_app_meta";const m=document.createElement("span");m.className="fcom_pwa_instruct_app_name",m.textContent=c.name||"";const p=document.createElement("span");p.className="fcom_pwa_instruct_app_host",p.textContent=c.host||"",r.append(m,p),u.appendChild(r);const h=document.createElement("div");h.className="fcom_pwa_instruct_steps",(e.steps||[]).forEach((f,v)=>{const w=document.createElement("div");w.className="fcom_pwa_instruct_step";const b=document.createElement("span");b.className="fcom_pwa_instruct_num",b.textContent=String(v+1);const y=document.createElement("span");y.className="fcom_pwa_instruct_text",y.innerHTML=f,w.append(b,y),h.appendChild(w)}),n.append(s),(c.name||c.icon)&&n.append(u),n.append(h),t.appendChild(n),document.body.appendChild(t),l.focus();function g(f){f.key==="Escape"?_():f.key==="Tab"&&(f.preventDefault(),l.focus())}function _(){var f;t.remove(),document.removeEventListener("keydown",g),o._closePwaInstruct===_&&(o._closePwaInstruct=null),(f=i==null?void 0:i.focus)==null||f.call(i)}t.addEventListener("click",f=>{f.target===t&&_()}),l.addEventListener("click",_),document.addEventListener("keydown",g),o._closePwaInstruct=_},initDocReady(){var e=this;if(document.querySelector(".fcom_top_menu")){const s=document.querySelector(".fcom_top_menu").offsetHeight;document.body.style.setProperty("--fcom-header-height",s+"px");let a=0;const d=document.querySelector(".fcom_mobile_menu");if(d&&(a=d.offsetHeight),document.body.style.setProperty("--fcom-mobile-menu-height",a+"px"),d&&window.visualViewport){var o=window.visualViewport.height;window.visualViewport.addEventListener("resize",function(){var l=window.visualViewport.height<o*.75;document.documentElement.classList.toggle("fcom_keyboard_open",l),document.body.style.setProperty("--fcom-mobile-menu-height",l?"0px":a+"px")})}}this.initMobileSidebar();const i=document.getElementById("fluent_community_sidebar_menu");i&&(i.addEventListener("click",function(s){const a=s.target.closest(".space_section_title");if(!a)return;let d=a.getAttribute("data-group_id"),l=a.closest(".fcom_communities_menu");l&&l.classList.toggle("fcom_group_collapsed");let c=l&&l.classList.contains("fcom_group_collapsed");a.setAttribute("aria-expanded",String(!c)),e.setGroupCollapsed(d,c)}),i.addEventListener("keydown",function(s){if(s.key!=="Enter"&&s.key!==" ")return;const a=s.target.closest(".space_section_title");a&&(s.preventDefault(),a.click())}),this.applySidebarGroupStates());let t=document.querySelector(".feeds_main");if(t){let s=function(a){let d=a.offsetWidth;document.body.style.setProperty("--fcom-main-content-width",d+"px")};var n=s;s(t),window.addEventListener("resize",function(){s(t)})}this.profileMenuInit(),this.initSkipLink(),this.watchSpaceCreateLink(),this.initLayoutRef(),this.initScrollEvents(),this.initHideOnScroll(),document.addEventListener("sidebar_menu_reloaded",()=>{this.watchSpaceCreateLink(),this.applySidebarGroupStates(),this.initSidebarToggleButton()}),document.dispatchEvent(new CustomEvent("fluentComPortalGeneral",{}))},maybeSetActiveLink(){let e=document.querySelectorAll("li a.fcom_custom_link");e.length&&e.forEach(o=>{let i=o.getAttribute("href");window.location.origin+window.location.pathname===i?o.classList.add("router-link-exact-active"):o.classList.remove("router-link-exact-active")})},setCookie(e,o,i=30){let t="";if(i){const n=new Date;n.setTime(n.getTime()+i*24*60*60*1e3),t="; expires="+n.toUTCString()}document.cookie=e+"="+encodeURIComponent(o)+t+"; path=/; SameSite=Lax"},getCookie(e){const o=e+"=",i=document.cookie.split(";");for(let t of i)if(t=t.trim(),t.indexOf(o)===0)return decodeURIComponent(t.substring(o.length));return null},getFromStorage(e,o=""){return this.globalStates&&this.globalStates[e]||o},setToStorage(e,o){this.globalStates||(this.globalStates={}),this.globalStates[e]=o,localStorage.setItem("fcom_global_storage",JSON.stringify(this.globalStates))},getGroupStates(){const e={};return(this.getCookie("fcom_sidebar_group_states")||"").split("|").forEach(o=>{const i=o.indexOf(":");if(i===-1)return;const t=o.slice(0,i);t!=="c"&&t!=="e"||o.slice(i+1).split(",").filter(Boolean).forEach(n=>{e[n]=t==="c"?"collapsed":"expanded"})}),e},setGroupCollapsed(e,o){const i=this.getGroupStates();i[e]=o?"collapsed":"expanded";const t=[],n=[];Object.keys(i).forEach(a=>{i[a]==="collapsed"?t.push(a):i[a]==="expanded"&&n.push(a)});const s=[];t.length&&s.push("c:"+t.join(",")),n.length&&s.push("e:"+n.join(",")),this.setCookie("fcom_sidebar_group_states",s.join("|"),365)},applySidebarGroupStates(){const e=window.location.pathname.replace(/\/$/,""),o=this.getGroupStates(),i=!!(window.fcom_portal_general&&window.fcom_portal_general.collapse_sidebar_groups);document.querySelectorAll(".space_section_title").forEach(t=>{let n=t.closest(".fcom_communities_menu");if(!n)return;if(this.groupHasActiveLink(n,e)){n.classList.remove("fcom_group_collapsed"),t.setAttribute("aria-expanded","true");return}const s=o[t.getAttribute("data-group_id")];s==="collapsed"?n.classList.add("fcom_group_collapsed"):s==="expanded"?n.classList.remove("fcom_group_collapsed"):n.classList.toggle("fcom_group_collapsed",i),t.setAttribute("aria-expanded",String(!n.classList.contains("fcom_group_collapsed")))})},groupHasActiveLink(e,o){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 n=i[t].pathname;if(n.length>1&&n.endsWith("/")&&(n=n.slice(0,-1)),n===o)return!0}return!1},closeMobileSidebar(){const e=document.querySelector(".space_opened");e&&e.classList.remove("space_opened");const o=document.querySelector(".fcom_space_opener_btn");o&&o.setAttribute("aria-expanded","false"),this._onOutsideClose&&(document.removeEventListener("click",this._onOutsideClose),document.removeEventListener("fcom_layout_scroll",this._onOutsideClose))},initMobileSidebar(){const e=document.querySelector(".fcom_space_opener_btn");e&&(this._onOutsideClose||(this._onOutsideClose=o=>{var i,t;(t=(i=o==null?void 0:o.target)==null?void 0:i.closest)!=null&&t.call(i,".fcom_group_title, .fcom_space_opener_btn")||this.closeMobileSidebar()},e.addEventListener("click",()=>{const o=document.querySelector(".feed_layout");o&&(o.classList.toggle("space_opened")?(e.setAttribute("aria-expanded","true"),setTimeout(()=>{document.addEventListener("click",this._onOutsideClose),document.addEventListener("fcom_layout_scroll",this._onOutsideClose)},0)):this.closeMobileSidebar())})))},initColorSwitch(){var n;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(a=>{a.style.display="none"}),!1;var e=this;document.querySelectorAll(".fcom_mode_switch").forEach(s=>{s.addEventListener("click",function(){var a=document.documentElement.classList.contains("dark")?"light":"dark";e.fcomSetColorMode(a),document.querySelector(".feed_layout")&&document.querySelector(".feed_layout").classList.remove("space_opened")})});let o=["dark","light"];if((n=window.fcom_portal_general)!=null&&n.color_switch_cookie_name){let s=this.getCookie(window.fcom_portal_general.color_switch_cookie_name);if(o.includes(s)){this.fcomSetColorMode(s);return}}let i=e.getFromStorage("fcom_color_mode","");if(o.includes(i)){this.fcomSetColorMode(i);return}let t=window.fcom_portal_general.default_theme_mode||"light";t==="system"?this.applyColorModeDom(this.getSystemColorMode()):o.includes(t)&&this.applyColorModeDom(t)},applyColorModeDom(e){if(e!=="dark"&&e!=="light")return!1;let o=e==="dark"?"light":"dark";document.documentElement.classList.remove(o),document.documentElement.classList.add(e),document.documentElement.setAttribute("data-color-mode",e),this.syncPwaThemeColor(e)},syncPwaThemeColor(e){if(!this.isPwaPage())return;const o=window.fcom_portal_general.pwa;e!=="dark"&&e!=="light"&&(e=document.documentElement.classList.contains("dark")?"dark":"light");const i=e==="dark"?o.theme_color_dark:o.theme_color;if(!i)return;let t=document.querySelector('meta[name="theme-color"]');t||(t=document.createElement("meta"),t.setAttribute("name","theme-color"),document.head.appendChild(t)),t.setAttribute("content",i)},getSystemColorMode(){return window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"},fcomSetColorMode(e){var i;if(!["dark","light"].includes(e))return!1;this.applyColorModeDom(e),(i=window.fcom_portal_general)!=null&&i.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(o=>{let i=o.querySelector(".fcom_profile_menu"),t=o.querySelector(".fcom_profile_sub_menu"),n=o.querySelector(".user_avatar");if(!i||!t)return;function s(c){n&&n.setAttribute("aria-expanded",c?"true":"false")}function a(c){o.classList.remove("fcom_extend_menu"),s(!1),document.removeEventListener("click",a)}function d(){o.classList.remove("fcom_extend_menu"),s(!1),document.removeEventListener("click",a)}function l(){o.classList.toggle("fcom_extend_menu");let c=o.classList.contains("fcom_extend_menu");s(c),c?setTimeout(()=>{var u;document.addEventListener("click",a),(u=t.querySelector("a"))==null||u.focus()},0):document.removeEventListener("click",a)}i.addEventListener("click",l),i.addEventListener("keydown",function(c){(c.key==="Enter"||c.key===" "||c.key==="Spacebar")&&c.target.closest(".user_avatar")?(c.preventDefault(),l()):c.key==="Escape"&&o.classList.contains("fcom_extend_menu")&&(d(),n&&n.focus())}),o.addEventListener("focusout",function(c){c.relatedTarget&&o.classList.contains("fcom_extend_menu")&&!o.contains(c.relatedTarget)&&d()})})},initSkipLink(){const e=document.querySelector(".screen-reader-shortcut");e&&e.addEventListener("click",function(o){const i=document.getElementById("fluent_com_portal");i&&(o.preventDefault(),i.focus())})},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"),o=e||window,i=e?()=>e.scrollTop:()=>window.scrollY,t=e?()=>e.scrollHeight:()=>document.documentElement.scrollHeight,n=e?()=>e.clientHeight:()=>window.innerHeight;let s=!1;o.addEventListener("scroll",()=>{s||(s=!0,requestAnimationFrame(()=>{const a=i(),d=t(),l=n(),c=d-a-l<=1,u=d-l>100;document.dispatchEvent(new CustomEvent("fcom_layout_scroll",{detail:{scrollTop:a,atBottom:c,pageScrollable:u}})),s=!1}))},{passive:!0})},initIosPwaPullToRefresh(){const e=navigator.standalone===!0||matchMedia("(display-mode: standalone)").matches;if(!this.isPwaPage()||!e)return;window.addEventListener("load",()=>document.documentElement.classList.add("fcom_pwa_loaded"),{once:!0});const o=navigator.userAgent||"";if(!(/iP(hone|ad|od)/.test(o)||/Macintosh/.test(o)&&navigator.maxTouchPoints>1))return;const t=document.body.appendChild(Object.assign(document.createElement("div"),{className:"fcom_pwa_ptr",innerHTML:'<svg class="fcom_pwa_ptr_spinner" viewBox="0 0 24 24" fill="none" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12a9 9 0 1 1-2.64-6.36"/><path d="M21 3v6h-6"/></svg>'}));t.setAttribute("aria-hidden","true");const n=t.firstElementChild;let s=0,a=0,d=!1,l=null;const c=()=>{for(let r=l;r instanceof Element;r=r.parentElement)if(r.scrollTop>0)return!1;return window.scrollY<=0},u=()=>{t.className="fcom_pwa_ptr",t.style.transform=n.style.transform="",s=a=0};window.addEventListener("touchstart",r=>{if(d||document.body.classList.contains("el-popup-parent--hidden")||r.target.closest(".el-dialog, .milkdown, [data-fcom-no-ptr]")||(l=r.target,!c()||r.touches.length!==1))return u();s=r.touches[0].clientY,a=0},{passive:!0}),window.addEventListener("touchmove",r=>{if(!s)return;if(r.touches.length!==1||(a=r.touches[0].clientY-s,a<=0||!c()))return u();r.preventDefault();const m=Math.min(a,120);t.classList.add("fcom_pwa_ptr_visible"),t.classList.toggle("fcom_pwa_ptr_ready",a>=80),t.style.transform=`translateX(-50%) translateY(${m*.5}px)`,n.style.transform=`rotate(${m*3}deg)`},{passive:!1}),window.addEventListener("touchend",()=>{if(s){if(a<80)return u();d=!0,n.style.transform="",t.classList.add("fcom_pwa_ptr_spinning"),t.style.transform="translateX(-50%) translateY(54px)",setTimeout(()=>location.reload(),400)}},{passive:!0}),window.addEventListener("touchcancel",u,{passive:!0})},initHideOnScroll(){const o="down",i="up",t=window.matchMedia("(max-width: 768px)"),n=document.body.classList;let s=0,a=0,d=null;const l=()=>{n.remove("fcom_scrolling-down","fcom_scrolling-down_mbl")},c=()=>{n.add("fcom_scrolling-down"),!!(window.fcom_portal_general&&window.fcom_portal_general.hide_header_on_scroll)&&t.matches&&n.add("fcom_scrolling-down_mbl")},u=m=>{d!==m&&(d=m,a=s)};document.addEventListener("fcom_layout_scroll",m=>{const{scrollTop:p,atBottom:h,pageScrollable:g}=m.detail;if(p<=0||!g)l(),d=null,a=p;else{const _=p-s;_>0?(u(o),p-a>=100&&c()):_<0&&!h&&(u(i),a-p>=100&&l())}s=Math.max(0,p)}),t.addEventListener("change",m=>{m.matches||n.remove("fcom_scrolling-down_mbl")}),window.addEventListener("popstate",l);const r=()=>{n.contains("fcom_scrolling-down_mbl")&&l()};document.addEventListener("keydown",m=>{m.key==="Tab"&&r()}),document.addEventListener("focusin",m=>{m.target.matches(":focus-visible")&&r()})},watchSpaceCreateLink(){let e=document.querySelectorAll(".fcom_space_create_link");e.length&&e.forEach(o=>{o.addEventListener("click",function(i){const t=window.fluentFrameworkApp;if(!t||!t.$eventBus)return;const n=o.getAttribute("data-parent_id");n&&(i.stopPropagation(),i.preventDefault(),window.fluentComPortalGeneral.closeMobileSidebar(),t.$eventBus.emit("createSpaceModal",{parent_id:n}))})})}};window.fluentComPortalGeneral.init(); |