File "bricksforge_elements.js"

Full path: /home/dora/public_html/wp-content/plugins/bricksforge/assets/js/bricksforge_elements.js
File size: 7.96 KB
MIME-type: --
Charset: utf-8

function brfFlipEverything(){gsap.utils.toArray(".brf-flip-wrapper").forEach((e=>{let t=e,n=t.querySelector(".brf-flip-box"),r=t.querySelector(".brf-flip-front"),a=t.querySelector(".brf-flip-back");a.style.height=r.getBoundingClientRect().height+"px";let o=t.getAttribute("data-type"),i=t.getAttribute("data-duration"),s=t.getAttribute("data-delay"),l=t.getAttribute("data-trigger"),c=t.getAttribute("data-oncomplete"),u=t.getAttribute("data-onstart"),d=t.getAttribute("data-onreversecomplete");o=o||"flip",i=i||1,s=s||0,l=l||"hover",c=c?new Function(c):"",u=u?new Function(u):"",d=d?new Function(d):"";const f=gsap.timeline({paused:!0,onStart:function(){"function"==typeof u&&u()},onComplete:function(){"function"==typeof c&&c()},onReverseComplete:function(){bricksIsFrontend||gsap.set(r,{clearProps:!0}),"function"==typeof d&&d()}});switch(gsap.set(t,{transformStyle:"preserve-3d",transformPerspective:1e3}),gsap.set(n,{transformStyle:"preserve-3d",transformOrigin:"50% 50%"}),gsap.set(a,{rotationY:180,rotationZ:180}),o){case"flip":f.to(r,{rotationX:180,duration:i},s),f.to(a,{rotationX:180,duration:i},s);break;case"fade":t.style.overflow="hidden",gsap.set(a,{width:a.getBoundingClientRect().width-1}),gsap.set(a,{rotationX:180}),f.to(r,{opacity:0,duration:i},s),f.to(a,{opacity:1,duration:i},s);break;case"fadeShrink":t.style.overflow="hidden",gsap.set(a,{width:a.getBoundingClientRect().width-1}),gsap.set(a,{rotationX:180}),f.to(r,{scale:.8,opacity:0,duration:i/2},s),f.to(a,{opacity:1,duration:i},s);break;case"fadeUp":t.style.overflow="hidden",gsap.set(a,{rotationX:180,translateY:a.offsetHeight,opacity:0}),f.to(r,{opacity:1,rotationX:180,duration:i},s),f.to(a,{translateY:0,opacity:1,duration:i},s);break;case"overlay":t.style.overflow="hidden",gsap.set(a,{rotationX:180,translateY:a.offsetHeight+50,zIndex:1}),f.to(a,{translateY:0,duration:i},s);break;case"overlayShrink":t.style.overflow="hidden",gsap.set(a,{rotationX:180,translateY:a.offsetHeight+50,zIndex:1,scale:.9}),f.to(a,{translateY:0,duration:i},s)}switch(l){case"hover":e.addEventListener("mouseenter",(e=>{f.play()})),e.addEventListener("mouseleave",(e=>{f.reverse()}));break;case"click":e.addEventListener("click",(t=>{e.classList.contains("active")?(f.reverse(),e.classList.remove("active")):(e.classList.add("active"),f.play())}))}}))}async function brfBeforeAndAfter(){for(let e of document.querySelectorAll(".brf-ba-wrapper")){let t=e.getBoundingClientRect().width,n=e.getBoundingClientRect().height;for(let r of e.querySelectorAll("img"))r.classList.remove("bricks-lazy-hidden"),r.getAttribute("data-src")&&r.setAttribute("src",r.getAttribute("data-src")),r.style.width=t+"px",r.style.height=n+"px",r.ondragstart=function(){return!1};let r=e.querySelector(".brf-ba-handle"),a=e.querySelector(".brf-ba-resize"),o=e;["mousedown","touchstart"].forEach((function(t){r.addEventListener(t,(function(t){t.preventDefault(),r.classList.add("draggable"),a.classList.add("resizable");let n=t.pageX?t.pageX:t.touches[0].pageX,i=r.getBoundingClientRect().width,s=r.offsetLeft+i-n,l=o.offsetLeft,c=o.getBoundingClientRect().width;minLeft=l+10,maxLeft=l+c-i-10,["mousemove","touchmove"].forEach((function(t){r.parentNode.addEventListener(t,(function(t){var n=t.pageX?t.pageX:t.touches[0].pageX;leftValue=n+s-i,leftValue<minLeft?leftValue=minLeft:leftValue>maxLeft&&(leftValue=maxLeft),widthValue=100*(leftValue+i/2-l)/c+"%",e.querySelector(".draggable")&&(e.querySelector(".draggable").style.left=widthValue,["mouseup","touchend"].forEach((function(t){e.querySelector(".draggable").addEventListener(t,(function(){this.classList.remove("draggable"),a.classList.remove("resizable")}))}))),e.querySelector(".resizable")&&(e.querySelector(".resizable").style.width=widthValue)}))})),r.parentNode.addEventListener("mouseup",(function(e){r.classList.remove("draggable"),a.classList.remove("resizable")})),r.parentNode.addEventListener("touchend",(function(e){r.classList.remove("draggable"),a.classList.remove("resizable")}))}))}))}}function brfMegaMenu(){if("undefined"==typeof MegaMenuSettings)return void console.warn("Bricksforge Mega Menu Warning: No Mega Menu data found.");let e=!!MegaMenuSettings&&MegaMenuSettings.data,t=MegaMenuSettings.headerData;if(!t||!t.length)return;let n=t.find((e=>"nav-menu"==e.name)).settings,r=!!n.activateMegaMenu&&n.activateMegaMenu,a=!!n.menu&&n.menu,o=n.megaMenuTrigger?n.megaMenuTrigger:"hover",i=!!n.megaMenuFullWidth&&n.megaMenuFullWidth,s=n.megaMenuTopSpacing?n.megaMenuTopSpacing:0,l=n.megaMenuCloseSelector?n.megaMenuCloseSelector:"main",c=n.megaMenuCloseEvent?n.megaMenuCloseEvent:"click";if(!1!==r)if(!1!==a)if(document.querySelector("header#brx-header")){for(let t of e){let e=document.createElement("template");e.innerHTML=t;let n=e.content.firstChild;i?document.querySelector("header#brx-header").appendChild(n):document.querySelector("header#brx-header .brxe-container").appendChild(n)}document.querySelectorAll(".bricks-nav-menu-wrapper li.menu-item").forEach((e=>{e.closest(".wpm-mega-menu")||e.addEventListener("mouseenter",(()=>{if("hover"==o){let e=document.querySelectorAll(".megamenu-open");for(let t of e)gsap.to(t,{duration:.5,opacity:0,display:"none"})}}))})),document.querySelectorAll(".bricks-nav-menu-wrapper li.menu-item").forEach((e=>{e.addEventListener("click"==o?"click":"mouseenter",(t=>{if(e.closest(".wpm-mega-menu"))return;let n=t.target.closest("li").getAttribute("id"),r=document.querySelectorAll(".wpm-mega-menu");for(let e of r){let r=e;if(i?r.style.top=r.closest("header").getBoundingClientRect().height+parseInt(s,10)+"px":(r.style.top=r.closest("header").getBoundingClientRect().height+parseInt(s,10)+"px",t.target.closest(".brxe-container").style.position="relative"),n==r.getAttribute("data-nav-item")){if(t.preventDefault(),r.classList.contains("megamenu-open")&&"click"==o)return gsap.to(r,{duration:.5,opacity:0,display:"none"}),void r.classList.remove("megamenu-open");gsap.set(r,{opacity:0}),gsap.to(r,{duration:.5,opacity:1,display:"block"}),r.classList.add("megamenu-open")}else gsap.to(r,{duration:.5,opacity:0,display:"none"}),r.classList.remove("megamenu-open")}document.querySelector(l).addEventListener("click"==c?"click":"mouseenter",(()=>{let e=document.querySelectorAll(".megamenu-open");for(let t of e)gsap.to(t,{duration:.5,opacity:0,display:"none"}),t.classList.remove("megamenu-open")}))}))}))}else console.warn("Bricksforge Mega Menu Warning: On this page no header seems to exist");else console.warn('Bricksforge Mega Menu Warning: You have to define a menu for the Nav Item element to use the mega menu. You find the control under: "Select Nav Menu".');else console.warn("Bricksforge Mega Menu Warning: The Mega Menu is not active.")}function brfToc(){let e=document.querySelector(".brf-toc-content");if(!e)return;if(!bricksIsFrontend)return;if(e.dataset.status&&"hidden"==e.dataset.status)return void document.querySelector("#brf-toc").closest(".brf-toc").remove();let t=document.createDocumentFragment();t.appendChild(e),document.getElementById("brf-toc").appendChild(t),e.style.display="block"}async function brfWaitForBuilder(e=500){return new Promise((async t=>{setTimeout((function(){t()}),e)}))}function brfIsParsable(e){try{JSON.parse(e)}catch(e){return!1}return!0}function brfGetParents(e,t){void 0===t&&(t=document);for(var n=[],r=e.parentNode;r!==t;){var a=r;n.push(a),r=a.parentNode}return n.push(t),n}window.onload=function(){bricksIsFrontend&&(document.querySelector(".brf-flip-wrapper")&&brfFlipEverything(),document.querySelector("#brf-toc")&&brfToc(),"undefined"!=typeof MegaMenuSettings&&MegaMenuSettings.megaMenuActivated&&brfMegaMenu()),document.querySelector(".brf-before-and-after")&&brfBeforeAndAfter()},window.addEventListener("resize",(function(){if(document.querySelector(".brf-ba-wrapper"))for(let e of document.querySelectorAll(".brf-ba-wrapper")){let t=e.getBoundingClientRect().width,n=e.getBoundingClientRect().height;for(let r of e.querySelectorAll("img"))r.classList.remove("bricks-lazy-hidden"),r.getAttribute("data-src")&&r.setAttribute("src",r.getAttribute("data-src")),r.style.width=t+"px",r.style.height=n+"px",r.ondragstart=function(){return!1}}}));