1 line
2.8 KiB
JavaScript
1 line
2.8 KiB
JavaScript
theme.StickyHeader=function(){function t(){}t.prototype=$.extend({},t.prototype,{init:function(t,i){t.attr("data-sticky-effect");if(t.length){var e={_create:function(){var e=this,t=this.bindings,i=t.find(this.options.mobile&&this.options.mobile.sticky?this.options.mobile.sticky:""),s=t.find(this.options.desktop&&this.options.desktop.sticky?this.options.desktop.sticky:""),o=$("<div>").addClass("header__spacer header__spacer--m").insertBefore(i),n=$("<div>").addClass("header__spacer header__spacer--d").insertBefore(s);function c(){var t=theme.current.is_desktop;e.bp=t?"desktop":"mobile",e.$sticky=t?s:i,e.$spacer=t?n:o,e.$sticky.length&&(t?(o.removeClass("header__spacer--visible"),n.addClass("header__spacer--visible"),i.hasClass(e.sticky_class)&&(e._unfix(i,o),e._return(e.options.mobile))):(n.removeClass("header__spacer--visible"),o.addClass("header__spacer--visible"),s.hasClass(e.sticky_class)&&(e._unfix(s,n),e._return(e.options.desktop))))}function a(){if(e.$sticky.length){var t=e.options[e.bp].limit?e.options[e.bp].limit:0,i=e.$spacer[0].getBoundingClientRect();"bottom"===t&&(t=e.$sticky.hasClass(e.sticky_class)?e.$spacer.innerHeight():e.$sticky.innerHeight()),t*=-1,i.top<t?(e.$sticky.hasClass(e.sticky_class)||(e._fix(e.$sticky,e.$spacer),e._move(e.options[e.bp])),ie||e._check_height(e.$sticky,e.options[e.bp])):e.$sticky.hasClass(e.sticky_class)&&(e._unfix(e.$sticky,e.$spacer),e._return(e.options[e.bp]))}}this.sticky_class="header__content--sticky",c(),a(),$window.on({"theme.resize.stickyHeader":function(){c(),a()},"scroll.stickyHeader":a})},_fix:function(t,i){var e=t.innerHeight();i.height(e),this.options[this.bp].fade&&t.css({opacity:0}).velocity({opacity:theme.animations.sticky_header.opacity},this.options[this.bp].duration()),t.addClass(this.sticky_class)},_unfix:function(t,i){i.removeAttr("style"),this.options[this.bp].fade&&t.velocity("stop",!0),t.removeAttr("style").removeClass(this.sticky_class)},_move:function(t){t.move&&$.each(t.move,function(){var t=$(this.elem),i=$(this.to),e=this.method||"append";this.$elem=t,this.$parent=t.parent(),i[e](t)})},_return:function(t){t.move&&$.each(t.move,function(){var t=this.method||"append";this.$parent[t](this.$elem),this.$elem=null,this.$parent=null})},_check_height:function(t,i){if(i.height){var e=this.$spacer[0].getBoundingClientRect(),s=e.bottom<=i.height?i.height:e.bottom;t.css({"min-height":s})}},getStickyHeight:function(){return this.options[this.bp]?this.options[this.bp].height||$(this.options[this.bp].sticky).innerHeight():0},destroy:function(){$(window).unbind("resize.stickyHeader scroll.stickyHeader"),$.Widget.prototype.destroy.call(this)}};return $.widget("ui.stickyHeader",e),t.stickyHeader(i),this.$sticky=t,{destroy:function(){t.stickyHeader("destroy")}}}}}),theme.StickyHeader=new t},$(function(){theme.StickyHeader()}); |