PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 2.5.0
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v2.5.0
2.11.0 2.10.0 2.10.01 2.9.1 2.9.0 2.8.1 2.8.0 2.7.7 2.7.5 2.7.0 2.6.01 2.6.0 2.5.0 2.4.01 trunk 1.0.90 1.0.91 1.0.92 1.0.93 1.0.94 1.0.95 1.0.96 1.0.97 1.0.98 1.0.99 All 78 releases
fluent-community / assets / portal_general.js

portal_general.js in FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses 2.5.0, at assets/portal_general.js

2 lines 8.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 window.fluentComPortalGeneral={init(){let e=localStorage.getItem("fcom_global_storage");e?this.globalStates=JSON.parse(e):e={},this.initColorSwitch(),document.addEventListener("DOMContentLoaded",()=>{this.initDocReady(),window.fcom_portal_general.scope=="wp"&&this.maybeSetActiveLink()})},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 r=0;const c=document.querySelector(".fcom_mobile_menu");if(c&&(r=c.offsetHeight),document.body.style.setProperty("--fcom-mobile-menu-height",r+"px"),c&&window.visualViewport){var t=window.visualViewport.height;window.visualViewport.addEventListener("resize",function(){var s=window.visualViewport.height<t*.75;document.documentElement.classList.toggle("fcom_keyboard_open",s),document.body.style.setProperty("--fcom-mobile-menu-height",s?"0px":r+"px")})}}this.initMobileSidebar();const n=document.getElementById("fluent_community_sidebar_menu");n&&(n.addEventListener("click",function(){const l=event.target.closest(".space_section_title");if(!l)return;let r=l.getAttribute("data-group_id"),c=l.closest(".fcom_communities_menu");c&&c.classList.toggle("fcom_group_collapsed");let s=c&&c.classList.contains("fcom_group_collapsed");e.setGroupState("fcom_group_"+r,s?"collapsed":"expanded")}),this.applySidebarGroupStates());let o=document.querySelector(".feeds_main");if(o){let l=function(r){let c=r.offsetWidth;document.body.style.setProperty("--fcom-main-content-width",c+"px")};var i=l;l(o),window.addEventListener("resize",function(){l(o)})}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(t=>{let n=t.getAttribute("href");window.location.origin+window.location.pathname===n?t.classList.add("router-link-exact-active"):t.classList.remove("router-link-exact-active")})},setCookie(e,t,n=30){let o="";if(n){const i=new Date;i.setTime(i.getTime()+n*24*60*60*1e3),o="; expires="+i.toUTCString()}document.cookie=e+"="+encodeURIComponent(t)+o+"; path=/"},getCookie(e){const t=e+"=",n=document.cookie.split(";");for(let o of n)if(o=o.trim(),o.indexOf(t)===0)return decodeURIComponent(o.substring(t.length));return null},getFromStorage(e,t=""){return this.globalStates&&this.globalStates[e]||t},setToStorage(e,t){this.globalStates||(this.globalStates={}),this.globalStates[e]=t,localStorage.setItem("fcom_global_storage",JSON.stringify(this.globalStates))},getGroupState(e){return this.getFromStorage("groupStates",{})[e]??""},setGroupState(e,t){let n=this.getFromStorage("groupStates",{});n[e]=t,this.setToStorage("groupStates",n)},applySidebarGroupStates(){const e=!!(window.fcom_portal_general&&window.fcom_portal_general.collapse_sidebar_groups),t=window.location.pathname.replace(/\/$/,"");document.querySelectorAll(".space_section_title").forEach(n=>{let o=n.getAttribute("data-group_id"),i=this.getGroupState("fcom_group_"+o),l=n.closest(".fcom_communities_menu");if(l){if(this.groupHasActiveLink(l,t)){l.classList.remove("fcom_group_collapsed");return}i==="collapsed"?l.classList.add("fcom_group_collapsed"):i==="expanded"?l.classList.remove("fcom_group_collapsed"):e&&l.classList.add("fcom_group_collapsed")}})},groupHasActiveLink(e,t){if(e.querySelector("a.router-link-exact-active, a.router-link-active"))return!0;const n=e.querySelectorAll("a[href]");for(let o=0;o<n.length;o++){let i=n[o].pathname;if(i.length>1&&i.endsWith("/")&&(i=i.slice(0,-1)),i===t)return!0}return!1},initMobileSidebar(){let e=document.querySelectorAll(".fcom_space_opener_btn");if(!e.length)return;function t(n){n.target.closest(".fcom_group_title")||n.target.closest(".fcom_space_opener_btn")||(document.querySelector(".space_opened")&&document.querySelector(".space_opened").classList.remove("space_opened"),document.removeEventListener("click",t))}e.forEach(n=>{n.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",t)},0):document.removeEventListener("click",t)})})},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(i=>{i.style.display="none"}),!1;var e=this;document.querySelectorAll(".fcom_mode_switch").forEach(o=>{o.addEventListener("click",function(){var i=document.documentElement.classList.contains("dark")?"light":"dark";e.fcomSetColorMode(i),document.querySelector(".feed_layout")&&document.querySelector(".feed_layout").classList.remove("space_opened")})});let t=e.getFromStorage("fcom_color_mode","");if((n=window.fcom_portal_general)!=null&&n.color_switch_cookie_name){let o=this.getCookie(window.fcom_portal_general.color_switch_cookie_name);(o=="dark"||o=="light")&&(t=o)}t&&this.fcomSetColorMode(t)},fcomSetColorMode(e){var o;if(!["dark","light"].includes(e))return!1;let n="dark";e=="dark"&&(n="light"),document.documentElement.classList.remove(n),e&&(document.documentElement.classList.add(e),document.documentElement.setAttribute("data-color-mode",e),(o=window.fcom_portal_general)!=null&&o.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(t=>{let n=t.querySelector(".fcom_profile_menu"),o=t.querySelector(".fcom_profile_sub_menu");if(!n||!o)return;function i(l){t.classList.remove("fcom_extend_menu"),document.removeEventListener("click",i)}n.addEventListener("click",function(l){t.classList.toggle("fcom_extend_menu"),t.classList.contains("fcom_extend_menu")&&setTimeout(()=>{document.addEventListener("click",i)},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"),t=e||window,n=e?()=>e.scrollTop:()=>window.scrollY,o=e?()=>e.scrollHeight:()=>document.documentElement.scrollHeight,i=e?()=>e.clientHeight:()=>window.innerHeight;let l=!1;t.addEventListener("scroll",()=>{l||(l=!0,requestAnimationFrame(()=>{const r=n(),c=o(),s=i(),m=c-r-s<=1,u=c-s>100;document.dispatchEvent(new CustomEvent("fcom_layout_scroll",{detail:{scrollTop:r,atBottom:m,pageScrollable:u}})),l=!1}))},{passive:!0})},initHideOnScroll(){const t="down",n="up",o=window.matchMedia("(max-width: 768px)"),i=document.body.classList;let l=0,r=0,c=null;const s=()=>{i.remove("fcom_scrolling-down","fcom_scrolling-down_mbl")},m=()=>{i.add("fcom_scrolling-down"),!!(window.fcom_portal_general&&window.fcom_portal_general.hide_header_on_scroll)&&o.matches&&i.add("fcom_scrolling-down_mbl")},u=a=>{c!==a&&(c=a,r=l)};document.addEventListener("fcom_layout_scroll",a=>{const{scrollTop:d,atBottom:p,pageScrollable:g}=a.detail;if(d<=0||!g)s(),c=null,r=d;else{const _=d-l;_>0?(u(t),d-r>=100&&m()):_<0&&!p&&(u(n),r-d>=100&&s())}l=Math.max(0,d)}),o.addEventListener("change",a=>{a.matches||i.remove("fcom_scrolling-down_mbl")}),window.addEventListener("popstate",s);const f=()=>{i.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(t=>{t.addEventListener("click",function(n){const o=window.fluentFrameworkApp;if(!o||!o.$eventBus)return;const i=t.getAttribute("data-parent_id");i&&(n.stopPropagation(),n.preventDefault(),o.$eventBus.emit("createSpaceModal",{parent_id:i}))})})}};window.fluentComPortalGeneral.init();
2