/home/crealab/pueblito.brainware.com.co/wp-content/plugins/scroll_magic/assets/js/script.js
(function($) {
'use strict';
$('document').ready(function() {
// Megamenu
function wpsg_megamenu($self){
if ($self.closest('.wpsg-menu-mobile-container') && $self.closest('.wpsg-menu-mobile-container').length > 0) {
return true;
}
if ($self.hasClass('full-container') || $self.hasClass('full-width')) {
$self.closest('li').css({position: 'static'});
$self.css({width: '100%'});
}
if ($self.hasClass('full-width')) {
$self.closest('.wpsg-container').css({
position: 'static'
});
}
if(!$self.hasClass('custom-width')) {
return;
}
var $menuParent = $self.closest('li'),
$scrollmagic = $self.closest('.wpsg-scrollmagic-inside'),
sw = ($self.outerWidth() / 2) - ($menuParent.outerWidth() / 2);
var mrLeft = $menuParent.offset().left - $scrollmagic.offset().left;
//check left side
if (sw < mrLeft) {
mrLeft = sw;
}
// check right side
var rScrollmagic = $scrollmagic.offset().left + $scrollmagic.outerWidth(),
rMegamenu = $self.offset().left + $self.outerWidth();
if ((rMegamenu - mrLeft) > rScrollmagic) {
mrLeft = rMegamenu - rScrollmagic;
}
// set pos
if ($(window).width() < $self.outerWidth()) {
mrLeft += 5;
}
$self.css({
marginLeft: -(mrLeft)
});
}
$('.wpsg-mega-menu').each(function( index ) {
wpsg_megamenu($(this))
});
// Search
$('.wpsg-btn-search').on('click', function(){
var $target = $(this).next('.wpsg-search-box');
$target.addClass('wpsg-visible');
return false;
});
$('.wpsg-search-close').on('click', function(){
var $self = $( this );
var $target = $self.closest('.wpsg-search-box');
$target.removeClass('wpsg-visible');
return false;
});
// Minicart
var $wpsg_mini_cart = $('.wpsg-mini-cart');
$wpsg_mini_cart.on('click', function(e) {
$(this).closest('.wpsg-cart-container').addClass('open');
});
$('.wpsg-cart-container').on('click', function (e) {
$(this).addClass('open');
});
$(document).on('click', function(e) {
if ( (
$( e.target ).closest( '.wpsg-cart-container' ).length == 0
) && (
$( e.target ).closest( '.wpsg-mini-cart' ).length == 0
) ) {
if ( $('.wpsg-cart-container').hasClass( 'open' ) ) {
$('.wpsg-cart-container').removeClass('open');
}
}
});
// Menu canvas
$('.wpsg-slideout-sidebar-icon').on('click', function () {
var $self = $( this );
$self.closest('.wpsg-slideout-sidebar-container').addClass('open');
return false;
});
$('.wpsg-close-slideout-sidebar').on('click', function () {
var $self = $( this );
$self.closest('.wpsg-slideout-sidebar-container').removeClass('open');
return false;
});
$(document).on('click', function (e) {
if ((
$(e.target).closest('.wpsg-slideout-sidebar-container').length == 0
) && (
$(e.target).closest('.wpsg-slideout-sidebar-icon').length == 0
)) {
if ($('.wpsg-slideout-sidebar-container').hasClass('open')) {
$('.wpsg-slideout-sidebar-container').removeClass('open');
}
}
});
// Menu icon
$('.wpsg-menu-icon').not('.open').on('click', function () {
var $self = $( this );
$('div.wpsg-menu-icon.open').removeClass('open');
$self.closest('.wpsg-menu-icon').addClass('open');
return false;
});
$(document).not('.wpsg-menu-icon').on('click', function () {
var $self = $( this );
$self.closest('.wpsg-menu-icon').removeClass('open');
return false;
});
$(document).on('click', function (e) {
if ((
$(e.target).closest('.wpsg-menu-icon').length == 0
) && (
$(e.target).closest('.wpsg-link-icon').length == 0
)) {
if ($('.wpsg-menu-icon').hasClass('open')) {
$('.wpsg-menu-icon').removeClass('open');
}
}
});
$('.wpsg-menu-icon.open').on('click', function (e) {
$(this).removeClass('open');
});
// Menu mobile
var $wpsgMenu = $('.wpsg-menu-mobile-container');
$wpsgMenu.find('.wpsg-dropdown-menu-toggle').on('click', function (e) {
var subMenu;
if ($(this).closest('li').find('.sub-menu').length > 0) {
subMenu = $(this).closest('li').find('.sub-menu');
if (subMenu.css('display') == 'block') {
subMenu.css('display', 'block').slideUp().parent().removeClass('expand');
} else {
subMenu.css('display', 'none').slideDown().parent().addClass('expand');
}
}
e.stopPropagation();
});
;
$wpsgMenu.find('.wpsg-close-mm-mobile').on('click', function(e) {
$wpsgMenu.removeClass('open');
e.stopPropagation();
});
$wpsgMenu.find('.wpsg-menu-mobile-icon').on('click', function (e) {
$(this).closest('.wpsg-menu-mobile-container').addClass('open');
var $wpsg_menu_icon = $wpsgMenu.find('.wpsg-dropdown-menu-toggle').first();
$wpsgMenu.find('.wpsg-dropdown-menu-toggle').css({
lineHeight: $wpsg_menu_icon.closest('li > a').outerHeight(true) + 'px'
})
e.stopPropagation();
});
$('.wpsg-menu-mobile-container .wpsg-scrollmagic-menuside a').on('click', function(e) {
if($(this).attr('href').indexOf('#') != -1) {
$(this).closest('.wpsg-menu-mobile-container').removeClass('open');
e.stopPropagation();
}
});
// Sticky menu
var $wpsgSticky = 1;
if ($('.wpsg-scrollmagic-container').hasClass('wpsg-sticky')) {
$wpsgSticky = $('.wpsg-sticky .wpsg-scrollmagic-inside');
} else if ($('.wpsg-section.wpsg-sticky').length > 0) {
$wpsgSticky = $('.wpsg-section.wpsg-sticky');
}
if ($wpsgSticky !== 1) {
$wpsgSticky.each(function (index) {
var $self = $( this );
if($('#wpadminbar').length > 0 && $('#wpadminbar').css('position') == 'fixed') {
$self.sticky({
topSpacing: parseFloat($('html').css('marginTop')),
zIndex: 999,
});
}
else {
$self.sticky({
topSpacing: 0,
zIndex: 999,
});
}
if($self.hasClass('wpsg-overlay')) {
$self.closest('.sticky-wrapper').addClass('wpsg-overlay');
}
});
}
});
// scroll to id
$('.wpsg-item').on('click',function(){
var idToScroll = $(this).attr('scroll-to-id');
if( $( "#"+idToScroll ).length === 0) return;
TweenMax.to(window, 0.5, {scrollTo: {y: "#"+idToScroll}});
})
// scroll to id
$(document).on("click", "a.bb-dots[data-scroll^='']", function (e) {
var id = "#"+$(this).attr("data-scroll");
TweenMax.to(window, 1, {scrollTo: {y: id}});
});
$('.bb-scroll-dots').activescroll({
active: "active zoomIn animate__animated"
});
// Auto add scrollmagic
var $bb_scrollmagic = $('.wpsg-auto-add-scrollmagic');
if($bb_scrollmagic.length > 0) {
$('body').prepend($bb_scrollmagic);
}
// Preview frame
if ($(".wpsg-before-previewframe").length > 0 && $(".scrollmagic-after-previewframe").length > 0) {
$(".wpsg-before-previewframe").resizable({
handles: "s",
})
$(".scrollmagic-after-previewframe").resizable({
handles: "n",
})
setTimeout( function() {
$([document.documentElement, document.body]).animate(
{
scrollTop: $(".wpsg-preview-content-container").offset().top
}, 2000 )
}, 500)
}
})(jQuery);