/* Copyright (C) 2016 Extend Studio SRL (www.cloud-press.net) Licensed under the terms of the GPL3 license. */ (function() { jQuery(document).ready(function($) { var stickyElements = $('[data-cp-sticky]'); var instancesSelectors = jQuery.map(window.cpStickyElements || {}, function(value, key) { return key; }) var instanceStickyElements = []; for (var i = 0; i < instancesSelectors.length; i++) { var selector = instancesSelectors[i]; var $el = $(selector); var topValue = cpStickyElements[selector].top; var onMobile = (cpStickyElements[selector].mobile !== undefined) ? cpStickyElements[selector].mobile + "" : "0"; var useShrink = (cpStickyElements[selector].shrinked !== undefined) ? cpStickyElements[selector].shrinked + "" : "0"; $el.attr('data-cp-sticky', topValue); $el.attr('data-cp-sticky-mobile', onMobile); $el.attr('data-cp-sticky-shrinked', useShrink); instanceStickyElements.push($el); } stickyElements = stickyElements.add(instanceStickyElements); stickyElements.each(function(index, el) { var $el = $(el); if ($el.attr('reveal-fx')) { return; } var distance = parseInt($el.attr("data-cp-sticky")); var stickyOnMobile = $el.attr("data-cp-sticky-mobile") == "1"; var useShrink = $el.attr("data-cp-sticky-shrinked") == "1"; var toBottom = $el.attr("data-cp-sticky-to") == "bottom"; if (useShrink) { $el.attr('data-cp-shrink', "initial"); } var stickData = { center: true, responsiveWidth: true, zIndex: (10 + index), topSpacing: distance, stickyOnMobile: stickyOnMobile, useShrink: useShrink, toBottom: toBottom, useNativeSticky: false } if (useShrink) { return; } if (toBottom) { stickData.__defineGetter__('topSpacing', function() { return window.scrollY + window.innerHeight - $el.outerHeight() - distance; }) } else { stickData['topSpacing'] = distance; } stickData.__defineGetter__('top', function() { return this.topSpacing; }) $el.data('stickData', stickData); $el.fixTo('body', stickData); $el.bind('sticky-end sticky-start fixto-removed fixto-added', function(event) { $(this).find('.owl-carousel').each(function(index, el) { var owlCarouselInstance = $(this).data()['owlCarousel']; if (!owlCarouselInstance) { return; } owlCarouselInstance.updateVars(); }); }); }); $(window).bind('resize.cpsticky orientationchange.cpsticky', function(event) { var stickyElements = this.$els; if (window.innerWidth < 1024) { stickyElements.each(function(index, el) { var data = $(this).data(); var stickData = data.stickData; if(!stickData) return; var fixToInstance = data.fixtoInstance; if (!stickData.stickyOnMobile) { fixToInstance.stop(); } }); } else { stickyElements.each(function(index, el) { var data = $(this).data(); var fixToInstance = data.fixtoInstance; //fixToInstance.start(); }) } }.bind({ "$els": stickyElements })); $(window).trigger('resize.cpsticky'); }); })()