//"use strict"; var App; /* ***** */ (function($,sr){ // debouncing function from John Hann // http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/ var debounce = function (func, threshold, execAsap) { var timeout; return function debounced () { var obj = this, args = arguments; function delayed () { if (!execAsap) func.apply(obj, args); timeout = null; }; if (timeout) clearTimeout(timeout); else if (execAsap) func.apply(obj, args); timeout = setTimeout(delayed, threshold || 50); }; } // smartresize jQuery.fn[sr] = function(fn){ return fn ? this.bind('resize', debounce(fn)) : this.trigger(sr); }; })(jQuery,'smartresize'); /* ***** */ // remap jQuery to $ (function ($) { /*-----------------------------*/ var MobileMenu = { $menu: null, $menu_inner: null, $mobile_nav_btn : null, $mobile_nav : null, init: function () { this.$mobile_nav_btn = $('.mobile-nav-btn'); this.$mobile_nav = $('.mobile-nav-wrapper'); this.initAction(); }, toggleOpen: function () { var $self = this; if (!this.isOpened()) { //$('html').addClass('jsMobileNavOpened'); $self.$mobile_nav.slideUp(); } else { //$('html').removeClass('jsMobileNavOpened'); $self.$mobile_nav.slideDown(); } }, isOpened: function () { //return $('html').hasClass('jsMobileNavOpened'); return this.$mobile_nav_btn.hasClass('opened'); }, initAction: function () { var $self = this; $self.$mobile_nav_btn.on('click', function (e) { $(this).toggleClass('opened'); $self.toggleOpen(); }); }, /*initAccordionMobileMenu: function(){ var $self = this; $('.close-menu').on('click', function(e){ $self.toggleOpen(); }) // $('.sub-menu a').on('click', function(e){ $self.toggleOpen(); }) // this.$menu_inner.find('.mn').each(function(){ if($(this).find('ul').size() > 0){ $(this).addClass('has-submenu'); } }); // $('.mobile-nav-main ul.main-menu li.active').addClass('open').children('ul').show(); $('.mobile-nav-main ul.main-menu li.has-submenu > a').on('click', function () { $(this).removeAttr('href'); var element = $(this).parent('li'); if (element.hasClass('open')) { element.removeClass('open'); element.find('li').removeClass('open'); element.find('ul').slideUp(400); } else { element.addClass('open'); element.children('ul').slideDown(500); element.siblings('li').children('ul').slideUp(500); element.siblings('li').removeClass('open'); element.siblings('li').find('li').removeClass('open'); element.siblings('li').find('ul').slideUp(500); } }); // }*/ } /*-----------------------------*/ var ShopMenu = { $menu: null, $menu_inner: null, $mobile_nav_btn : null, $mobile_nav : null, init: function () { this.$mobile_nav_btn = $('.mobile-shop-nav-btn'); this.$mobile_nav = $('.shop-nav'); this.initAction(); this.initAccordionMobileMenu(); }, toggleOpen: function () { var $self = this; if (!this.isOpened()) { //$('html').addClass('jsMobileShopNavOpened'); $self.$mobile_nav.slideUp(); } else { //$('html').removeClass('jsMobileShopNavOpened'); $self.$mobile_nav.slideDown(); } }, isOpened: function () { return this.$mobile_nav_btn.hasClass('opened'); }, initAction: function () { var $self = this; $self.$mobile_nav_btn.on('click', function (e) { $(this).toggleClass('opened'); $self.toggleOpen(); }); }, initAccordionMobileMenu: function(){ var $self = this; /*$('.close-menu').on('click', function(e){ $self.toggleOpen(); }) // $('.sub-menu a').on('click', function(e){ $self.toggleOpen(); })*/ // $('.shop-nav ul.shop-menu').find('.mn').each(function(){ if($(this).find('ul').size() > 0){ $(this).addClass('has-submenu'); } }); // $('.shop-nav ul.shop-menu li.active, .main-menu li.active').addClass('open').children('ul').show(); $('.shop-nav ul.shop-menu li.has-submenu > a, .main-menu li.has-submenu > a').on('click', function (e) { if($(window).width <= 768) return; //$(this).removeAttr('href'); e.preventDefault(); e.stopPropagation(); var element = $(this).parent('li'); if (element.hasClass('open')) { element.removeClass('open'); element.find('li').removeClass('open'); element.find('ul').slideUp(300); } else { element.addClass('open'); element.children('ul').slideDown(200); element.siblings('li').children('ul').slideUp(400); element.siblings('li').removeClass('open'); element.siblings('li').find('li').removeClass('open'); element.siblings('li').find('ul').slideUp(400); } }); } } /*-----------------------------*/ var GallerySlider = { init : function(){ } } /*-----------------------------*/ var RecommendedListSlider = { init : function(){ if( $('#recommendedList').size()){ var slider = $('#recommendedList') slider .on('initialize.owl.carousel initialized.owl.carousel changed.owl.carousel refreshed.owl.carousel', function (event) { if (!event.namespace) return; var carousel = event.relatedTarget, element = event.target, current = carousel.current(); $('.owl-next', element).toggleClass('disabled', current === carousel.maximum()); $('.owl-prev', element).toggleClass('disabled', current === carousel.minimum()); }) .owlCarousel({ loop:false, margin:0, items: 4, nav: true, dots: false, responsive:{ 0:{ items:1, nav:true }, 480:{ items:2, nav:true }, 620:{ items:3, nav:true, mouseDrag: true, touchDrag: true }, 992:{ items:4, nav:false, mouseDrag: false, touchDrag: false } } }); } } } /*-----------------------------*/ var TopSlider = { init : function(){ if( $('#topSlider').size() && $('#topSlider .item').size() > 1 ){ var slider = $('#topSlider') slider .on('initialize.owl.carousel initialized.owl.carousel changed.owl.carousel refreshed.owl.carousel', function (event) { if (!event.namespace) return; var carousel = event.relatedTarget, element = event.target, current = carousel.current(); $('.owl-next', element).toggleClass('disabled', current === carousel.maximum()); $('.owl-prev', element).toggleClass('disabled', current === carousel.minimum()); }) .owlCarousel({ loop: true, items:1, nav: $('#topSlider').hasClass('show-nav'), dots: $('#topSlider').hasClass('show-dots'), //animateOut: 'fadeOut', //autoplay: true, //autoplayTimeout: 5000, }); } } } /*-----------------------------*/ var ProductDetails = { init:function(){ this.createSlider(); }, createSlider : function(){ if( $('#productSlider').size()){ var slider = $('#productSlider') slider .on('initialize.owl.carousel initialized.owl.carousel changed.owl.carousel refreshed.owl.carousel', function (event) { if (!event.namespace) return; var carousel = event.relatedTarget, element = event.target, current = carousel.current(); $('.owl-next', element).toggleClass('disabled', current === carousel.maximum()); $('.owl-prev', element).toggleClass('disabled', current === carousel.minimum()); }) .owlCarousel({ loop: false, items:1, nav: true, dots: false, //animateOut: 'fadeOut', }); } if ($('.gallery-item').size()) { $('.gallery-item').magnificPopup({ delegate: 'span', type: 'image', gallery: { enabled: true, preload: [0, 2], tPrev: 'Poprzednie', tNext: 'Następne', }, zoom: { enabled: true, duration: 300, easing: 'ease-in-out', opener: function (openerElement) { return openerElement.is('img') ? openerElement : openerElement.find('img'); } }, removalDelay: 300, mainClass: 'mfp-fade', }); } if ($('.open-info-link').size()) { $('.open-info-link').magnificPopup({ type:'inline', closeBtnInside:true, /*midClick: true,*/ removalDelay: 300, mainClass: 'mfp-fade', }); }; if($('.open-popup-link').size()){ $('.open-popup-link').magnificPopup({ type:'inline', closeBtnInside:true, removalDelay: 300, mainClass: 'mfp-fade', }); } } } /*-----------------------------*/ var Order = { init: function(){ if( $('.page-order').length > 0 ){ $('#userAddress').on('change', function(){ var data = $(this).find(':selected').data('address').split('###'); $('input[name="customer_address_1"]').val( data[0] ); $('input[name="customer_address_2"]').val( data[1] ); $('input[name="customer_city"]').val( data[2] ); $('input[name="customer_postal"]').val( data[3] ); $('select[name="customer_country"]').val( data[5] ).trigger('change'); $('input[name="customer_phone"]').val( data[6] ); }); $('#invoice').on('change', function(){ $('input[name="invoice_address_1"]').val( $('input[name="customer_address_1"]').val() ); $('input[name="invoice_address_2"]').val( $('input[name="customer_address_2"]').val() ); $('input[name="invoice_city"]').val( $('input[name="customer_city"]').val() ); $('input[name="invoice_postal"]').val( $('input[name="customer_postal"]').val() ); $('select[name="invoice_country"]').val( $('select[name="customer_country"]').val() ); }); $('#userFirm').on('change', function(){ var data = $(this).find(':selected').data('address').split('###'); $('input[name="invoice_address_1"]').val( data[0] ); $('input[name="invoice_address_2"]').val( data[1] ); $('input[name="invoice_city"]').val( data[2] ); $('input[name="invoice_postal"]').val( data[3] ); $('select[name="invoice_country"]').val( data[5] ).trigger('change'); $('input[name="invoice_firm"]').val( data[7] ); $('input[name="invoice_vat"]').val( data[8] ); }); $('#other-address').on('change', function(){ $('input[name="delivery_name"]').val( $('input[name="customer_name"]').val() ); $('input[name="delivery_surname"]').val( $('input[name="customer_surname"]').val() ); $('select[name="delivery_country"]').val( $('select[name="customer_country"]').val() ).trigger('change'); $('input[name="delivery_phone"]').val( $('input[name="customer_phone"]').val() ); }); $('.warning').each(function(){ $(this).parent().addClass('warning'); }); $('select[name="customer_country"]').on('change', function(){ if( !$('#other-address').is(':checked') ){ var cid = $(this).val(); $('select[name="delivery_method"]').val(0); $('select[name="delivery_method"] option').each(function(){ if( $(this).val() != 0 && $(this).val() != '' ){ $(this).remove(); } }); if( cid != 0 && cid != "" ){ $(document).trigger('lock'); var cName = $(this).find(':selected').html(); $(document).trigger( 'sendAjax', { target: Order, action: 'getDeliveryOptions', params: { country: cid, countryName: cName } } ); } } }); $('select[name="delivery_country"]').on('change', function(){ var cid = $(this).val(); $('select[name="delivery_method"]').val(0); $('select[name="delivery_method"] option').each(function(){ if( $(this).val() != 0 && $(this).val() != '' ){ $(this).remove(); } }); if( cid != 0 && cid != "" ){ $(document).trigger('lock'); var cName = $(this).find(':selected').html(); $(document).trigger( 'sendAjax', { target: Order, action: 'getDeliveryOptions', params: { country: cid, countryName: cName } } ); } }); if( $('#other-address').length > 0 ){ var cid = ""; var cName = ""; if( $('#other-address').is(':checked') ){ cid = $('select[name="delivery_country"]').val(); cName = $('select[name="delivery_country"] :selected').html(); }else{ cid = $('select[name="customer_country"]').val(); cName = $('select[name="customer_country"] :selected').html(); } if( cid != 0 && cid != "" ){ $(document).trigger('lock'); $(document).trigger( 'sendAjax', { target: Order, action: 'getDeliveryOptions', params: { country: cid, countryName: cName } } ); } } setTimeout(function(){ $('select[name="customer_country"]').trigger('change'); }, 10 ); } }, retriveAjax: function(data){ if( data.action ){ switch( data.action ){ case 'getDeliveryOptions': if( data.data.length == 0 ){ $(document).trigger( 'showPopup', { title: '', txt: data.errorMsg, type: 'info' } ); }else{ var i = 0; var l = data.data.length; var html = ''; for( i; i' + data.data[i].name + ' - ' + data.data[i].cost + ' ' + data.data[i].currency + ''; } $('select[name="delivery_method"]').append(html); } $(document).trigger('unlock'); break; } } } } var Cart = { init: function(){ if( $('main > .shopping-cart').length > 0 ){ Cart.initList(); } }, retriveAjax: function(data){ if( data.action == 'setQuantity' ){ $('header .cartCnt').html( data.data.quantity ); $('.summary .price-val').html( data.data.summary.totalPrice ); if( $.isArray( data.data.products ) ){ var i = 0; var l = data.data.products.length; for( i; i 0 ){ SingleProduct.initAttr(); SingleProduct.initAddCart(); $('.product-cart input[type="hidden"]').on('change', function(){ $(document).trigger( 'lock' ); var params = {}; $('.product-cart input[type="hidden"]').each(function(){ params[ $(this).attr('name').substr(5) ] = $(this).val(); }); $(document).trigger( 'sendAjax', {target: SingleProduct, action: 'getQuantity', params: params } ); }); } }, retriveAjax: function(data){ if( data.action == 'getQuantity' ){ data = data.data; $('.price').html( data.price ); $('.price-old').html( data.priceOld ); if( data.quantity == 0 ){ $('#notify').addClass('show'); $('#addToCart').removeClass('show'); $('#addToCart').addClass('hide'); }else{ $('#notify').removeClass('show'); $('#addToCart').removeClass('hide'); $('#addToCart').addClass('show'); } $('.prod-attribiutes.rozmiar input:not([name^="attr_"])').parent().css( { opacity: 0 } ); if( typeof data.attributes != "undefined" ){ //$('.other-colors span').css({opacity: 0.5}); i = 0; l = data.attributes.length; var j = 0; var k = 0; for( i; i= 768 ){ MobileMenu.$mobile_nav.css({display: 'block'}); ShopMenu.$mobile_nav.css({display: 'block'}); }else{ MobileMenu.$mobile_nav.css({display: 'none'}); ShopMenu.$mobile_nav.css({display: 'none'}); } //FIX about-me-image height if($('.about-me-image').size()){ if($('.about-me-image').css('position') == 'absolute'){ $('.about-me-image-wrapper').height( Math.max( $('.about-me-image').height(), $('.about-me-txt').height())); }else{ $('.about-me-image-wrapper').height('auto'); } } } } /*-----------------------------*/ $(document).ready(function () { FastClick.attach(document.body); // ---- App.init(); // ---- //$('html').addClass('is-preloader'); $('html').waitForImages(function() { //$('html').removeClass('is-preloader'); }); }); $(window).load(function () { }); /*$(window).resize(function () { App.pageResize(); });*/ // usage: $(window).smartresize(function(){ App.pageResize(); }); })(jQuery);