/*
 # -----------------------------------------------------------------------------
 # ~/assets/themes/j1/modules/fam/js/fam.js
 # MODIFIED FAM JS from project Materialize
 # Provides JS Core funtions for the J1 FAM Module (Floating Button Menu)
 #
 # Product/Info:
 # https://jekyll.one
 # https://github.com/Dogfalo/materialize
 #
 # Copyright (C) 2023 Juergen Adams
 #
 # J1 Template is licensed under the MIT License.
 # See: https://github.com/jekyll-one-org/j1-template/blob/main/LICENSE.md
 # -----------------------------------------------------------------------------
 # TODO:
 # jadams, 2020-10-11: module needs to be rewitten to PURE jQuery
 # -----------------------------------------------------------------------------
*/
"use strict";!function(t,e){var s={direction:"top",hoverEnabled:!0,toolbarEnabled:!1};t.fn.reverse=[].reverse;class i{constructor(t,e,s){e instanceof Element||console.error(Error(e+" is not an HTML Element"));var i=t.getInstance(e);i&&i.destroy(),this.el=e,this.$el=cash(e)}static init(t,e,s){var i=null;if(e instanceof Element)i=new t(e,s);else if(e&&(e.jquery||e.cash||e instanceof NodeList)){for(var n=[],o=0;o<e.length;o++)n.push(new t(e[o],s));i=n}return i}}j1.initializeJqueryWrapper=function(t,e,s){jQuery.fn[e]=function(i){if(t.prototype[i]){var n=Array.prototype.slice.call(arguments,1);if("get"===i.slice(0,3)){var o=this.first()[0][s];return o[i].apply(o,n)}return this.each(function(){var t=this[s];t[i].apply(t,n)})}if("object"==typeof i||!i)return t.init(this,arguments[0]),this;jQuery.error("Method "+i+" does not exist on jQuery."+e)}};class n extends i{constructor(e,s){super(n,e,s),this.el.M_FloatingActionButton=this,this.options=t.extend({},n.defaults,s),this.isOpen=!1,this.$anchor=this.$el.children("a").first(),this.$menu=this.$el.children("ul").first(),this.$floatingBtns=this.$el.find("ul .btn-fab-floating"),this.$floatingBtnsReverse=this.$el.find("ul .btn-fab-floating").reverse(),this.offsetY=0,this.offsetX=0,this.$el.addClass(`direction-${this.options.direction}`),"top"===this.options.direction?this.offsetY=40:"right"===this.options.direction?this.offsetX=-40:"bottom"===this.options.direction?this.offsetY=-40:this.offsetX=40,this._setupEventHandlers()}static get defaults(){return s}static init(t,e){return super.init(this,t,e)}static getInstance(t){return(t.jquery?t[0]:t).M_FloatingActionButton}destroy(){this._removeEventHandlers(),this.el.M_FloatingActionButton=void 0}_setupEventHandlers(){this._handleFABClickBound=this._handleFABClick.bind(this),this._handleOpenBound=this.open.bind(this),this._handleCloseBound=this.close.bind(this),this.options.hoverEnabled&&!this.options.toolbarEnabled?(this.el.addEventListener("mouseenter",this._handleOpenBound),this.el.addEventListener("mouseleave",this._handleCloseBound)):this.el.addEventListener("click",this._handleFABClickBound)}_removeEventHandlers(){this.options.hoverEnabled&&!this.options.toolbarEnabled?(this.el.removeEventListener("mouseenter",this._handleOpenBound),this.el.removeEventListener("mouseleave",this._handleCloseBound)):this.el.removeEventListener("click",this._handleFABClickBound)}_handleFABClick(){this.isOpen?this.close():this.open()}_handleDocumentClick(e){t(e.target).closest(this.$menu).length||this.close()}open(){this.isOpen||(this.options.toolbarEnabled?this._animateInToolbar():this._animateInFAB(),this.isOpen=!0)}close(){this.isOpen&&(this.options.toolbarEnabled?(window.removeEventListener("scroll",this._handleCloseBound,!0),document.body.removeEventListener("click",this._handleDocumentClickBound,!0),this._animateOutToolbar()):this._animateOutFAB(),this.isOpen=!1)}_animateInFAB(){this.$el.addClass("active");var t=0;this.$floatingBtnsReverse.each(s=>{e({targets:s,opacity:1,scale:[.4,1],translateY:[this.offsetY,0],translateX:[this.offsetX,0],duration:275,delay:t,easing:"easeInOutQuad"}),t+=40})}_animateOutFAB(){this.$floatingBtnsReverse.each(t=>{e.remove(t),e({targets:t,opacity:0,scale:.4,translateY:this.offsetY,translateX:this.offsetX,duration:175,easing:"easeOutQuad",complete:()=>{this.$el.removeClass("active")}})})}_animateInToolbar(){var e,s=window.innerWidth,i=window.innerHeight,n=this.el.getBoundingClientRect(),o=t('<div class="fam-btn-backdrop"></div>'),a=this.$anchor.css("background-color");this.$anchor.append(o),this.offsetX=n.left-s/2+n.width/2,this.offsetY=i-n.bottom,e=s/o[0].clientWidth,this.btnBottom=n.bottom,this.btnLeft=n.left,this.btnWidth=n.width,this.$el.addClass("active"),this.$el.css({"text-align":"center",width:"100%",bottom:0,left:0,transform:"translateX("+this.offsetX+"px)",transition:"none"}),this.$anchor.css({transform:"translateY("+-this.offsetY+"px)",transition:"none"}),o.css({"background-color":a}),setTimeout(()=>{this.$el.css({transform:"",transition:"transform .2s cubic-bezier(0.550, 0.085, 0.680, 0.530), background-color 0s linear .2s"}),this.$anchor.css({overflow:"visible",transform:"",transition:"transform .2s"}),setTimeout(()=>{this.$el.css({overflow:"hidden","background-color":a}),o.css({transform:"scale("+e+")",transition:"transform .2s cubic-bezier(0.550, 0.055, 0.675, 0.190)"}),this.$menu.children("li").children("a").css({opacity:1}),this._handleDocumentClickBound=this._handleDocumentClick.bind(this),window.addEventListener("scroll",this._handleCloseBound,!0),document.body.addEventListener("click",this._handleDocumentClickBound,!0)},100)},0)}_animateOutToolbar(){var t=window.innerWidth,e=window.innerHeight,s=this.$el.find(".fam-btn-backdrop"),i=this.$anchor.css("background-color");this.offsetX=this.btnLeft-t/2+this.btnWidth/2,this.offsetY=e-this.btnBottom,this.$el.removeClass("active"),this.$el.css({"background-color":"transparent",transition:"none"}),this.$anchor.css({transition:"none"}),s.css({transform:"scale(0)","background-color":i}),this.$menu.children("li").children("a").css({opacity:""}),setTimeout(()=>{s.remove(),this.$el.css({"text-align":"",width:"",bottom:"",left:"",overflow:"","background-color":"",transform:"translate3d("+-this.offsetX+"px,0,0)"}),this.$anchor.css({overflow:"",transform:"translate3d(0,"+this.offsetY+"px,0)"}),setTimeout(()=>{this.$el.css({transform:"translate3d(0,0,0)",transition:"transform .2s"}),this.$anchor.css({transform:"translate3d(0,0,0)",transition:"transform .2s cubic-bezier(0.550, 0.055, 0.675, 0.190)"})},20)},200)}}j1.fab=n,j1.jQueryLoaded=!!window.jQuery,j1.jQueryLoaded&&j1.initializeJqueryWrapper(n,"floatingActionButton","M_FloatingActionButton")}(cash,j1.anime);