Files
masimmo.pl/modules/creativeelements/views/lib/sticky/jquery.sticky.min.js
2024-11-20 09:09:44 +01:00

4 lines
3.8 KiB
JavaScript

/*
* By Elementor & WebshopWorks Team
*/
!function(C){function i(t,o){function i(t,o,s){var e={},i=t[0].style;s.forEach(function(t){e[t]=void 0!==i[t]?i[t]:""}),t.data("css-backup-"+o,e)}function n(t,o,s){var e=getComputedStyle(t[0]),i=parseFloat(e[o]),n="height"===o?["top","bottom"]:["left","right"],t=[];return"border-box"!==e.boxSizing&&t.push("border","padding"),s&&t.push("margin"),t.forEach(function(o){n.forEach(function(t){i+=parseFloat(e[o+"-"+t])})}),i}var r,a,e=!1,c=!1,s=!1,f=pageYOffset,p={},d={to:"top",offset:0,effectsOffset:0,parent:!1,classes:{sticky:"sticky",stickyActive:"sticky-active",stickyEffects:"sticky-effects",spacer:"sticky-spacer"}},l=function(t,o){return t.data("css-backup-"+o)},m=function(){i(r,"unsticky",["position","width","margin-top","margin-bottom","top","bottom"]);var t={position:"fixed",width:n(r,"width"),marginTop:0,marginBottom:0};t[a.to]=a.offset,t["top"===a.to?"bottom":"top"]="",r.css(t).addClass(a.classes.stickyActive)},u=function(){r.css(l(r,"unsticky")).removeClass(a.classes.stickyActive)},y=function(t){var o=p.$window.scrollTop(),s=n(t,"height"),e=innerHeight,t=t.offset().top-o,o=t-e;return{top:{fromTop:t,fromBottom:o},bottom:{fromTop:t+s,fromBottom:o+s}}},h=function(){p.$spacer=r.clone().addClass(a.classes.spacer).css({visibility:"hidden",transition:"none",animation:"none"}),r.after(p.$spacer),m(),e=!0,r.find("input[checked]").prop("checked",!0),r.trigger("sticky:stick")},k=function(){u(),p.$spacer.remove(),e=!1,r.trigger("sticky:unstick")},g=function(){var t,o,s=y(r),e="top"===a.to;c?(e?s.top.fromTop>a.offset:s.bottom.fromBottom<-a.offset)&&(p.$parent.css(l(p.$parent,"childNotFollowing")),r.css(l(r,"notFollowing")),c=!1):(t=y(p.$parent),o=getComputedStyle(p.$parent[0]),o=parseFloat(o[e?"borderBottomWidth":"borderTopWidth"]),t=e?t.bottom.fromTop-o:t.top.fromBottom+o,(e?t<=s.bottom.fromTop:t>=s.top.fromBottom)&&(i(p.$parent,"childNotFollowing",["position"]),p.$parent.css("position","relative"),i(r,"notFollowing",["position","top","bottom"]),(o={position:"absolute"})[a.to]="",o["top"===a.to?"bottom":"top"]=0,r.css(o),c=!0))},v=function(t){s&&-t<a.effectsOffset?(r.removeClass(a.classes.stickyEffects),s=!1):!s&&-t>=a.effectsOffset&&(r.addClass(a.classes.stickyEffects),s=!0)},w=function(){var t,o,s=a.offset;e?(t=y(p.$spacer),t="top"===a.to?t.top.fromTop-s:-t.bottom.fromBottom-s,a.parent&&g(),0<t&&k()):(o=y(r),(t="top"===a.to?o.top.fromTop-s:-o.bottom.fromBottom-s)<=0&&(h(),a.parent&&g())),v(t)},b=function(){var t;e&&a.autoHide&&(t=a.autoHideOffset.size*("vh"===a.autoHideOffset.unit?C(window).height()/100:1),pageYOffset>=t&&pageYOffset>f+10&&!r.find(".elementor-cart--shown").length&&r.off("transitionend.ceSticky").css({transition:"transform "+a.autoHideDuration.size+"s",transform:"translateY(calc(-100% - "+a.offset+"px))"}).addClass(a.classes.stickyHide),(pageYOffset<t||pageYOffset<f-10)&&r.removeClass(a.classes.stickyHide).css("transform","").one("transitionend.ceSticky",function(){r.css("transition","")}),f=pageYOffset),w()},$=function(){e&&(u(),m(),a.parent&&(c=!1,g()))};this.destroy=function(){e&&k(),p.$window.off("scroll",b).off("resize",$),r.removeClass(a.classes.sticky).css("transform","").off("transitionend.ceSticky").removeClass(a.classes.stickyHide)},a=jQuery.extend(!0,d,o),r=C(t).addClass(a.classes.sticky),p.$window=C(window),a.parent&&("parent"===a.parent?p.$parent=r.parent():p.$parent=r.closest(a.parent)),p.$window.on({scroll:b,resize:$}),w()}C.fn.sticky=function(s){var e="string"==typeof s;return this.each(function(){var t=C(this);if(e){var o=t.data("sticky");if(!o)throw Error("Trying to perform the `"+s+"` method prior to initialization");if(!o[s])throw ReferenceError("Method `"+s+"` not found in sticky instance");o[s].apply(o,Array.prototype.slice.call(arguments,1)),"destroy"===s&&t.removeData("sticky")}else t.data("sticky",new i(this,s))}),this},window.Sticky=i}(jQuery);