HEX
Server: Apache/2.2.22 (Debian)
System: Linux ns382018.ip-46-105-97.eu 3.14.32-xxxx-grs-ipv6-64 #9 SMP Thu Oct 20 14:53:52 CEST 2016 x86_64
User: web279 (5281)
PHP: 5.4.45-0+deb7u8
Disabled: NONE
Upload Files
File: /var/www/clients/client0/web279/web/MTDrubik/themes/twentyseventeen/js/tmstickup.js
(function($,undefined){
	var 
		def={
			stuckClass:'isStuck'			
		}
		,doc=$(document),anim = false;

	$.fn.TMStickUp=function(opt){
		opt=$.extend(true,{},def,opt)

		$(this).each(function(){
			var $this=$(this)
				,posY//=$this.offset().top+$this.outerHeight()
				,isStuck=false
				,clone=$this.clone().appendTo($this.parent()).addClass(opt.stuckClass)
				,height//=$this.outerHeight()
				,stuckedHeight=clone.outerHeight()
				,opened//=$.cookie&&$.cookie('panel1')==='opened'
				,tmr

			$(window).resize(function(){
				clearTimeout(tmr)				
				clone.css({top:isStuck?0:-stuckedHeight,visibility:isStuck?'visible':'hidden'})
				tmr=setTimeout(function(){
					posY=$this.offset().top//+$this.outerHeight()				
					height=$this.outerHeight()
					stuckedHeight=clone.outerHeight()
					opened=$.cookie&&$.cookie('panel1')==='opened'

					clone.css({top:isStuck?0:-stuckedHeight})
				},40)
			}).resize()

			clone.css({
				position:'fixed'				
				,width:'100%'
			})

			$this
				.on('rePosition',function(e,d){
					if(isStuck)
						clone.animate({marginTop:d},{easing:'linear'})
					if(d===0)
						opened=false
					else
						opened=true
				})
			
			doc
				.on('scroll',function(){
					var scrollTop=doc.scrollTop()

					if(scrollTop>=posY&&!isStuck){						
						clone
							.stop()
							.css({visibility:'visible'})
							.animate({
								top:0
								,marginTop:opened?50:0
							},{

							})
							
						isStuck=true
					}
					
					if(scrollTop<posY+height&&isStuck){
						if ($('.search-form-toggle').length > 0) {
							var o_stuck = $('.search-form-toggle'),
							f_stuck = $('.search-form');

							if (!anim && o_stuck.hasClass('active')) {
								anim = true;
								o_stuck.removeClass('active');
								f_stuck.slideUp(300, function () {
									setTimeout(function () {
										anim = false;
									}, 1000);
								});
							}
						}

						$('.sf-menu ul').css('display', 'none');

						clone
							.stop()
							.animate({
								top:-stuckedHeight
								,marginTop:0
							},{
								duration:200
								,complete:function(){
									clone.css({visibility:'hidden'})
								}
							});
						
						isStuck=false;

					}			
				})				
				.trigger('scroll')
		})
	}
})(jQuery)