laipower/wp-content/plugins/gp-premium/menu-plus/functions/js/sticky.min.js

1 line
8.3 KiB
JavaScript

function generateStickyDebounce(s,n,a){var o;return function(){var t=this,e=arguments,i=a&&!o;clearTimeout(o),o=setTimeout(function(){o=null,a||s.apply(t,e)},n),i&&s.apply(t,e)}}!function(M,E,W){function e(t,e){var i=0,s=0,n="",a=0,o=!1,r=!1,l=!1,c=!1,d=0,p=0,h=0,m=0,u=M(),f=M("body"),g=0,b=0,k=0,v=M(t).clone().css({visibility:"hidden",display:"none"}).attr({id:"sticky-placeholder","aria-hidden":!0,itemtype:null,itemscope:null}),y=M(),w={top:0,bottom:0,custom:[]},C={scrollHide:!1,lazyHeight:0,topMargin:"auto",keepInWrapper:!1,wrapperSelector:"",zIndex:1e4,namespaceClass:"stuckElement",fixedClass:"isStuck",disableOn:function(){return!0},transition:"none"},I=function(){var t=0<jQuery("#wpadminbar").length&&"fixed"==jQuery("#wpadminbar").css("position")?jQuery("#wpadminbar").outerHeight():0;return"auto"===C.topMargin?parseInt(t+u.css("marginTop")):isNaN(C.topMargin)&&0<C.topMargin.search("px")?parseInt(t+C.topMargin.replace("px","")):isNaN(parseInt(C.topMargin))?0:parseInt(t+C.topMargin)},H=function(){v.remove(),u.removeClass(C.fixedClass).css({"max-width":"","margin-top":"","margin-left":"","margin-right":"",position:"",top:"",left:"",right:"",bottom:"",width:"",opacity:"",height:"",overflow:"","-webkit-transform":"","-ms-transform":"",transform:"","-webkit-transition":"","-ms-transition":"",transition:"",visibility:"","z-index":""}).removeClass("sticky-navigation-transition").removeClass("navigation-transition").removeClass("sticky-nav-scrolling-up"),"sticky-navigation"===u.attr("id")&&u.attr("id","site-navigation"),l=r=o=!1,u.trigger("stickUp:unStick")},x=function(t){M(v).insertAfter(u).show().addClass(C.fixedClass);var e,i=v.offsetParent();t&&(u.css({position:"absolute"}),e=y.offset().top+y.outerHeight()-i.offset().top-p-parseInt(y.css("paddingBottom"))),u.css({position:"absolute",marginTop:b,bottom:"",left:v.position().left,top:t?e:u.offset().top-i.offset().top-b}),u.trigger("stickUp:holdIt")},S=function(){o=!0,C.zIndex&&u.css("z-index",C.zIndex),"fade"==C.transition&&u.hide(),"slide"!=C.transition&&!C.scrollHide||u.css({height:"0",overflow:"hidden",visibility:"hidden"}),M(v).insertAfter(u).show().addClass(C.fixedClass),M(".gen-sidebar-nav").length&&v.css("height",u.outerHeight()),"left"!=u.css("float")&&"right"!=u.css("float")||(v.css("float",u.css("float")),v.attr("style",v.attr("style")+"width:auto !important;")),"slide"==C.transition&&"block"==v.css("display")&&u.css({"-webkit-transform":"translateY(-100%)","-ms-transform":"translateY(-100%)",transform:"translateY(-100%)","-webkit-transition":"transform 300ms ease-in-out","-ms-transition":"transform 300ms ease-in-out",transition:"transform 300ms ease-in-out"}),u.addClass(C.fixedClass),"site-navigation"===u.attr("id")&&u.attr("id","sticky-navigation");var t=-k;u.css({"margin-top":b,position:"fixed",top:t+"px",left:"",right:"",bottom:""}),u.trigger("stickUp:stickIt"),"fade"==C.transition&&u.fadeIn(300),"slide"==C.transition&&u.one("webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend",function(t){u.css({visibility:"",height:"",overflow:""}),setTimeout(function(){u.css({"-webkit-transform":"translateY(0)","-ms-transform":"translateY(0)",transform:"translateY(0)"})},10)}),C.scrollHide&&u.css({height:"",overflow:"",visibility:""})},U=function(){v&&v.width()!==u.outerWidth()&&u.outerWidth(v.outerWidth())},z=function(t){var e;C.disableOn()?(c=c&&!1,(!C.keepInWrapper||y.is(":visible"))&&(s=M(t.target).scrollTop(),n=i<=s?"down":"up",a=Math.abs(i-s),M(E).outerHeight(),i=s,h=u.offset().top,d=parseInt(u.outerHeight()+b)+parseInt(u.css("marginBottom")),o||l||r||(parseInt(u.outerHeight(!0)),r||l?(w.top=parseInt(v.offset().top),parseInt(u.offset().left)):w.top=parseInt(u.offset().top)),p=parseInt(u.outerHeight())+parseInt(u.css("margin-bottom"))+b,C.keepInWrapper?w.bottom=y.offset().top+y.outerHeight()-parseInt(y.css("paddingBottom")):w.bottom=M(W).outerHeight(),m=u.offset().top+p,k=C.scrollHide?d+C.lazyHeight:C.lazyHeight,"none"!==C.transition&&(g=2*u.outerHeight()),b=null!==C.topMargin?I():0,o&&b!==u.css("margin-top")&&u.css("margin-top",b),(!o&&!r&&s>=w.top-b+k+g||r&&l&&s<=h-b+k)&&(S(),l=r=!(o=!0)),o&&!r&&s>=w.top-b+k+u.outerHeight()/2&&(v.addClass("sticky-navigation-transition"),u.addClass("sticky-navigation-transition")),C.keepInWrapper&&parseInt(m-b)!==parseInt(w.bottom)&&s>=w.bottom-p+k&&(x(!0),l=r=!(o=!1)),o&&(t=parseInt(u.css("top")),"up"===n&&0!==t?(e=-t<a?0:t+a,u.css("top",e+"px"),u.addClass("sticky-nav-scrolling-up")):"down"===n&&-k<t&&(e=k+t<a?-k:t-a,u.css("top",e+"px"),u.removeClass("sticky-nav-scrolling-up"))),(o||l||r)&&s<=w.top-b&&H(),o||l||r)&&U()):c||(H(),c=!0)},T=function(t){l&&(x(),r=!1),z(t)};!function(t,e){(u=M(t)).addClass(C.namespaceClass),e&&M.extend(!0,C,e),b=null!==C.topMargin?I():0,C.lazyHeight&&(b+=C.lazyHeight),C.keepInWrapper?(y=""!==C.wrapperSelector?u.closest(C.wrapperSelector):y).length||(y=u.parent()):y=f,M(E).on("scroll.stickUp",z),M(E).on("resize.stickUp",T),z({target:W})}.call(this,t,e),M(t).on("stickUp:detach",function(t){(u=M(this)).removeClass(C.namespaceClass),v.remove(),u.removeClass(C.fixedClass).css({maxWidth:"",marginTop:"",marginLeft:"",marginRight:"",position:"",top:"",left:"",right:"",bottom:"",width:""}),c=!(l=r=o=!1),M(E).off("scroll.stickUp",z),M(E).off("resize.stickUp",T)})}M.fn.stickUp=function(t){return this.each(function(){new e(this,t)})}}(jQuery,window,document),function(s){s.fn.GenerateSimpleSticky=function(t){var t=s.extend({menu:s(this),parent:!1,scrollHide:!1,offsetElement:"#wpadminbar",disableOn:function(){return!0},transition:"none"},t),e=s("body"),i=null,i=t.parent||t.menu.parent(),e=((0<t.menu.parents(".site-header").length||0<t.menu.parents(".generate-page-header").length||0<t.menu.parents(".header-wrap").length||0<t.menu.parents(".site-wrapper").length)&&(i=e),!e.hasClass("nav-right-sidebar")&&!e.hasClass("nav-left-sidebar")||s(".menu-toggle").is(":visible")||(t.menu=s(".gen-sidebar-nav"),i=s(".site-content"),t.menu.children().hasClass("auto-hide-sticky")),0<jQuery(t.offsetElement).length&&"fixed"==jQuery(t.offsetElement).css("position")&&jQuery(t.offsetElement).outerHeight(),{scrollHide:t.scrollHide,keepInWrapper:!0,wrapperSelector:i,fixedClass:"is_stuck navigation-stick navigation-clone",topMargin:0,disableOn:t.disableOn,transition:t.transition});t.menu.stickUp(e)}}(jQuery),jQuery(function(s){0 in window;function e(t){var e=t.getAttribute("href");t.pathname===window.location.pathname&&"#"!==e&&t.closest("nav").classList.contains("toggled")&&(t.closest("nav").classList.remove("toggled"),s("html").hasClass("mobile-menu-open"))&&s("html").removeClass("mobile-menu-open")}var t,i,n,a,o=s("body"),r="none",l=(o.hasClass("sticky-enabled")&&(t=s("#site-navigation"),o.hasClass("sticky-menu-fade")&&(r="fade"),o.hasClass("sticky-menu-slide")&&(r="slide"),i=!!t.hasClass("auto-hide-sticky"),n={transition:r,scrollHide:i,disableOn:function(){var t=s("body"),e=s("#mobile-header"),i=s(".menu-toggle");return!(t.hasClass("desktop-sticky-menu")&&i.is(":visible")||t.hasClass("mobile-sticky-menu")&&!i.is(":visible")||t.hasClass("mobile-header")&&e.is(":visible"))}},s(t).GenerateSimpleSticky(n),o.on("generate_navigation_location_updated",function(){t.trigger("stickUp:detach"),setTimeout(function(){s(t).GenerateSimpleSticky(n)},250)})),o.hasClass("mobile-header")&&o.hasClass("mobile-header-sticky")&&(a=s("#mobile-header")).GenerateSimpleSticky({scrollHide:!(!a.data("auto-hide-sticky")&&""!==a.data("auto-hide-sticky")),disableOn:function(){return!!a.is(":visible")}}),s(".sidebar-nav-mobile")),c=s(".gen-sidebar-nav"),d=s(window).width(),r=generateStickyDebounce(function(){d!==s(window).width()&&(l.is(":visible")&&(c.trigger("stickUp:detach"),l.trigger("stickUp:detach"),l.GenerateSimpleSticky(n)),c.is(":visible"))&&(l.trigger("stickUp:detach"),c.trigger("stickUp:detach"),c.GenerateSimpleSticky(n))},250);s("body").hasClass("sticky-enabled")&&l.length&&(window.addEventListener("resize",r),window.addEventListener("orientationchange",r)),navigator.userAgent.match(/(iPod|iPhone|iPad)/)&&(o.hasClass("sticky-enabled")||o.hasClass("mobile-header")&&o.hasClass("mobile-header-sticky"))&&s(document).on("focus",".navigation-stick .search-field",function(){s("html, body").animate({scrollTop:0},"fast")});(o.hasClass("both-sticky-menu")||o.hasClass("mobile-sticky-menu"))&&s(".main-navigation:not(#mobile-header) ul a[href*=\\#]").on("click",function(t){e(this)}),o.hasClass("mobile-header-sticky")&&s("#mobile-header ul a[href*=\\#]").on("click",function(t){e(this)})});