(function ($) { "use strict"; var resize_timer; window.onresize = function (event) { clearTimeout(resize_timer); resize_timer = setTimeout(function () { adela_hover_item_dropdown_menu(); }, 250); }; function adela_masonry() { if( $('.masonry-grid').length){ var masonry = $('.masonry-grid').isotope({ // set itemSelector so .grid-sizer is not used in layout itemSelector: '.grid-item', percentPosition: true, layoutMode: 'masonry', masonry: { // set to the element columnWidth: '.grid-sizer' } }); masonry.imagesLoaded().progress(function() { masonry.isotope({ // set itemSelector so .grid-sizer is not used in layout itemSelector: '.grid-item', percentPosition: true, layoutMode: 'masonry', masonry: { // set to the element columnWidth: '.grid-sizer' } }) }); } } function adela_back_to_top_button() { $(window).scroll(function () { if ( $(this).scrollTop() >= 50 ) { $('#return-to-top').fadeIn(200); } else { $('#return-to-top').fadeOut(200); } }); $('#return-to-top').click(function () { $('body,html').animate({ scrollTop: 0 }, 500); }); } function adela_custom_scrollbar() { $('.header-minicart-contents .cart_list').mCustomScrollbar(); $('.header-minicart-contents .cart_list').change(function() { $('.header-minicart-contents .cart_list').mCustomScrollbar(); }); } function adela_mobile_block() { $(document).on('click', '.header-device-mobile .item.has-sub>a', function () { $(this).closest('.header-device-mobile').find('.item').removeClass('open'); $(this).closest('.item').addClass('open'); return false; }) $(document).on('click', '.header-device-mobile .item .close', function () { $(this).closest('.item').removeClass('open'); return false; }) $(document).on('click', '*', function (event) { if ( !$(event.target).closest(".header-device-mobile").length ) { $(".header-device-mobile").find('.item').removeClass('open'); } }) } function adela_searchform_widget_icon() { if ( $('.widget_search').length ) { var widget_search = $('.widget_search'); widget_search.find('.search-submit').after('').remove(); } } function adela_category_widget_toggle() { if ( $('.widget_categories').length > 0 ) { $('.widget_categories').each(function () { var target = $(this); target.find('.cat-item').each(function () { var cat_item = $(this); if ( cat_item.find('ul.children li').length ) { cat_item.addClass('close_sub').find('ul.children').slideUp('fast'); cat_item.addClass('has-submenu').children('a').after(''); } }); $(document).on('click', '.widget_categories .carets', function () { var current = $(this); var parent = current.parent(); var child = current.parent().children('.children'); if ( parent.hasClass('close_sub') ) { parent.removeClass('close_sub').addClass('open_sub'); child.slideDown('fast'); } else { parent.removeClass('open_sub').addClass('close_sub'); child.slideUp('fast'); } }); }); } } function adela_bootstrap_dropdown_menu() { $('ul.dropdown-menu [data-toggle=dropdown]').on('click', function (event) { event.preventDefault(); event.stopPropagation(); $(this).parent().toggleClass('open'); $(this).parent().find("ul").parent().find("li.dropdown").toggleClass('open'); }); adela_hover_item_dropdown_menu(); $('.navbar-nav ').on('click','.carets-togle', function (el) { var _this = $(this), _this_parent = $(this).parent(); if(_this_parent.hasClass('open')){ _this_parent.removeClass('open'); }else { _this.closest('ul.navbar-nav').find('.open').removeClass('open'); _this_parent.addClass('open'); } }); } function adela_hover_item_dropdown_menu() { var window_size = jQuery('body').innerWidth(); window_size += adela_get_scrollbar_width(); if ( window_size > 767 ) { $('.navbar-nav .dropdown').hover(function () { $(this).addClass('open'); }, function () { $(this).removeClass('open'); }); } } function adela_get_scrollbar_width() { var $inner = jQuery('
test
'), $outer = jQuery('
').append($inner), inner = $inner[ 0 ], outer = $outer[ 0 ]; jQuery('body').append(outer); var width1 = inner.offsetWidth; $outer.css('overflow', 'scroll'); var width2 = outer.clientWidth; $outer.remove(); return (width1 - width2); } function adela_single_product_move_expand_btn() { if ( $(document).find('.single-product .woocommerce-product-gallery__trigger').length > 0 ) { var this_btn = $(document).find('.single-product .woocommerce-product-gallery__trigger').detach(); $(document).find('.single-product .flex-viewport').append(this_btn); } } function adela_shop_display_mode_control() { $(document).on('click', '.display-mode', function () { if ( !$(this).hasClass("active") ) { var mode = $(this).data('mode'); $.ajax({ type: 'POST', url: adela_ajax_frontend.ajaxurl, data: { action: 'adela_ajax_change_shop_display_mode', security: adela_ajax_frontend.security, mode: mode }, beforeSend: function () { $('body').append('
'); }, success: function (response) { if ( response.success ) { location.reload(); } $('body').find('.ajax-loading-wrapper').remove(); }, }); } }); } function adela_single_product_thumbnail() { if ( $(document).find('.flex-control-thumbs').length == 1 ) { var flex_control = $(document).find('.flex-control-nav'); var _config = []; if ( $('body').hasClass('rtl') ) { _config.rtl = true; } _config.prevArrow = ''; _config.nextArrow = ''; _config.focusOnSelect = true; _config.cssEase = 'linear'; _config.vertical = true; _config.slidesToShow = 3; _config.responsive = [ { breakpoint: 991, settings: { vertical: false, slidesToShow: 3 } }, { breakpoint: 767, settings: { vertical: true, slidesToShow: 3 } }, { breakpoint: 480, settings: { vertical: false, slidesToShow: 4 } }, ]; flex_control.slick(_config); } } function adela_single_product_quantity_input() { var quantitiy = 1; $(document).on('click', '.adela-quantity-input .minus-btn', function (e) { e.preventDefault(); var parent = $(this).closest('.adela-quantity-input'); var target = parent.find('.adela-quantity'); var quantity = parseInt(target.val()); if ( quantity > 0 ) { target.val(quantity - 1).trigger('change'); } else { target.val(0).trigger('change'); } }); $(document).on('click', '.adela-quantity-input .plus-btn', function (e) { e.preventDefault(); var parent = $(this).closest('.adela-quantity-input'); var target = parent.find('.adela-quantity'); var quantity = parseInt(target.val()); target.val(quantity + 1).trigger('change'); }); } function adela_popup_modal() { $(document).on('change', '.adela_disabled_popup_by_user', function () { if ( $(this).is(":checked") ) { adela_set_cookie("adela_disabled_popup_by_user", 'true', 7); } else { adela_get_cookie("adela_disabled_popup_by_user", '', 0); } }); var popup_id = $('#adela-popup-modal'); if ( popup_id.length > 0 ) { var delay_time = parseInt(popup_id.attr('data-delay_time')); var window_size = jQuery('body').innerWidth(); window_size += adela_get_scrollbar_width(); if ( window_size < 768 ) { return false; } var disabled_popup_by_user = adela_get_cookie('adela_disabled_popup_by_user'); if ( disabled_popup_by_user == 'true' ) { return false; } else { if ( $('body').hasClass('home') ) { setTimeout(function () { popup_id.modal({ keyboard: false }) }, delay_time); } } } } function adela_set_cookie(cname, cvalue, exdays) { var d = new Date(); d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000)); var expires = "expires=" + d.toUTCString(); document.cookie = cname + "=" + cvalue + "; " + expires; } function adela_get_cookie(cname) { var name = cname + "="; var ca = document.cookie.split(';'); for ( var i = 0; i < ca.length; i++ ) { var c = ca[ i ]; while ( c.charAt(0) == ' ' ) { c = c.substring(1); } if ( c.indexOf(name) == 0 ) { return c.substring(name.length, c.length); } } return ""; } function adela_product_carousel() { $(".owl-carousel").each(function (index, el) { var owl = $(this); var ts_item = parseInt(owl.attr('data-ts')), xs_item = parseInt(owl.attr('data-xs')), sm_item = parseInt(owl.attr('data-sm')), md_item = parseInt(owl.attr('data-md')), lg_item = parseInt(owl.attr('data-lg')), get_margin = parseInt(owl.attr('data-margin')); var margin = 0; if ( typeof get_margin != 'undefined' && get_margin ) { margin = get_margin; } var configs = { margin: margin, loop: false, touchDrag: true, autoplay: false, smartSpeed: 600, nav: true, dots: false, navText: [ '', '' ], responsive: { 0: { items: ts_item }, 480: { items: xs_item }, 768: { items: sm_item }, 992: { items: md_item }, 1200: { items: lg_item } } }; if ( owl.hasClass('widget-carousel-slider') ) { configs.loop = true; //configs.autoplay = true, owl.owlCarousel(configs); owl.on('change.owl.carousel', function (event) { var $currentItem = $('.owl-item', owl).eq(event.item.index); var $elemsToanim = $currentItem.find("[data-animation-out]"); adela_owl_set_animation($elemsToanim, 'out'); }); var round = 0; owl.on('changed.owl.carousel', function (event) { var $currentItem = $('.owl-item', owl).eq(event.item.index); var $elemsToanim = $currentItem.find("[data-animation-in]"); adela_owl_set_animation($elemsToanim, 'in'); }); owl.on('translated.owl.carousel', function (event) { console.log(event.item.index, event.page.count); if ( event.item.index == (event.page.count - 1) ) { if ( round < 1 ) { round++ console.log(round); } else { owl.trigger('stop.owl.autoplay'); var owlData = owl.data('owl.carousel'); owlData.settings.autoplay = false; owlData.options.autoplay = false; owl.trigger('refresh.owl.carousel'); } } }); } else { owl.owlCarousel(configs); } }); } function adela_owl_set_animation(element, in_out) { var animationEndEvent = 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend'; element.each(function () { var $elem = $(this); var $animationType = 'animated ' + $elem.data('animation-' + in_out); $elem.addClass($animationType).one(animationEndEvent, function () { $elem.removeClass($animationType); }); }); } function adela_currency_switcher() { $(document).on('click', '.currency-list-item .currency-item', function () { var select_value = $(this).attr('data-value'); var target = $(this).closest('.woocommerce-currency-switcher-form').find('.woocommerce-currency-switcher'); target.val(select_value).trigger('change'); }); } function adela_single_product_actions() { $(document).on('click', '.print-button-label', function (e) { e.preventDefault(); window.print(); return false; }); } function adela_single_product_mailto() { $(document).on('click', '#mailto-submit', function () { var email_to = $('#mail-to-elements #mailto-email').val(); var subject = ''; var email_body = ''; // if ( $('#mail-to-elements #mailto-subject').val() != '' ) { subject = $('#mail-to-elements #mailto-subject').val(); } if ( $('#mail-to-elements #mailto-body').val() != '' ) { subject = $('#mail-to-elements #mailto-body').val(); } if ( !adela_validate_email(email_to) ) { $('#mail-to-elements #mailto-result').html('').append('

Please enter a valid email.

'); $('#mail-to-elements #mailto-email').focus(); } else { window.location = 'mailto:' + email_to + '?subject=' + subject + '&body=' + email_body; $('#send_mail_to_friend').modal('hide'); } }); } function adela_validate_email($email) { var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/; return emailReg.test($email); } window.addEventListener('load', function (ev) { adela_shop_display_mode_control(); adela_single_product_thumbnail(); adela_single_product_quantity_input(); adela_product_carousel(); adela_currency_switcher(); adela_single_product_actions(); adela_single_product_mailto(); adela_bootstrap_dropdown_menu(); adela_popup_modal(); //adela_category_widget_toggle(); adela_searchform_widget_icon(); adela_mobile_block(); adela_back_to_top_button(); adela_custom_scrollbar(); adela_masonry(); }, false); $(document).ready(function () { adela_custom_scrollbar(); adela_masonry(); }); $(document).scroll(function () { adela_custom_scrollbar(); adela_masonry(); }); $(document).resize(function () { adela_custom_scrollbar(); adela_masonry(); }); })(jQuery);