/* JS content (all pages) */ var responsiveflag = false; $(document).ready(function() { highdpiInit(); responsiveResize(); $(window).resize(responsiveResize); /* if (navigator.userAgent.match(/Android/i)) { var viewport = document.querySelector('meta[name="viewport"]'); viewport.setAttribute('content', 'initial-scale=1.0,maximum-scale=1.0,user-scalable=0,width=device-width,height=device-height'); window.scrollTo(0, 1); } */ blockHover(); if (typeof quickView !== 'undefined' && quickView) { quick_view(); } dropDown(); if (typeof page_name != 'undefined' && !in_array(page_name, ['index', 'product'])) { bindGrid(); $(document).on('change', '.selectProductSort', function(e) { console.log("change .selectProductSort"); if (typeof request != 'undefined' && request) var requestSortProducts = request; var splitData = $(this).val().split(':'); if (typeof requestSortProducts != 'undefined' && requestSortProducts){ var newUrl = new URL(requestSortProducts); newUrl.searchParams.set('orderby', splitData[0]); newUrl.searchParams.set('orderway', splitData[1]); document.location.href = newUrl; //document.location.href = requestSortProducts + ((requestSortProducts.indexOf('?') < 0) ? '?' : '&') + 'orderby=' + splitData[0] + '&orderway=' + splitData[1]; } }); $(document).on('change', 'select[name="n"]', function() { console.log("change .selectn"); var urlToPaginate = request; urlToPaginate = new URL(urlToPaginate); urlToPaginate.searchParams.set('n', $(this).val()); document.location.href = urlToPaginate; //$(this.form).submit(); }); $(document).on('change', 'select[name="manufacturer_list"], select[name="supplier_list"]', function() { console.log("change .selectmansup"); if (this.value != '') location.href = this.value; }); $(document).on('change', 'select[name="currency_payement"]', function() { console.log("change .selectcurr"); setCurrency($(this).val()); }); /*$(document).on('click', 'ul.pagination li a', function() { console.log($(this).text()); var urlPagination = request; var newUrl = new URL(urlPagination); console.log(newUrl); newUrl.searchParams.set('p', $(this).text()); console.log(newUrl); window.location.href = newUrl; return false; });*/ $(document).on('click', 'ul.pagination li a', function(e) { console.log("click ulpaginationlia"); e.preventDefault(); var $this = $(this); var pageNo = null; if ($this.parent().hasClass('disabled')) { return false; } if ($this.parent().hasClass('pagination_previous')) { var href = $this.attr('href'); if (href) { var urlParams = new URLSearchParams(href); pageNo = urlParams.get('p'); } } else if ($this.parent().hasClass('pagination_next')) { var href = $this.attr('href'); if (href) { var urlParams = new URLSearchParams(href); pageNo = urlParams.get('p'); } } else { pageNo = $this.text(); } if (pageNo) { var urlPagination = request; var newUrl = new URL(urlPagination); newUrl.searchParams.set('p', pageNo); window.location.href = newUrl; } return false; }); $(document).on('submit', '.showall', function() { console.log("submit showall"); var urlPagination = request; var newUrl = new URL(urlPagination); var n_value = $(".showall #nb_item").val(); newUrl.searchParams.set('n', n_value); window.location.href = newUrl; return false; }); } $(document).on('click', '.back', function(e) { console.log("click back"); e.preventDefault(); history.back(); }); jQuery.curCSS = jQuery.css; if (!!$.prototype.cluetip) { console.log("prototype cluetip"); $('a.cluetip').cluetip({ local: true, cursor: 'pointer', dropShadow: false, dropShadowSteps: 0, showTitle: false, tracking: true, sticky: false, mouseOutClose: true, fx: { open: 'fadeIn', openSpeed: 'fast' } }).css('opacity', 0.8); } if (!!$.prototype.fancybox) { console.log("prototype fancybox"); $.extend($.fancybox.defaults.tpl, { closeBtn: '', next: '', prev: '' }); } }); function highdpiInit() { /* if ($('.replace-2x').css('font-size') == "1px") { var els = $("img.replace-2x").get(); for (var i = 0; i < els.length; i++) { src = els[i].src; src = src.replace("&extname=_small", ""); var img = new Image(); img.src = src; img.height != 0 ? els[i].src = src : els[i].src = els[i].src; } } */ } function scrollCompensate() { var inner = document.createElement('p'); inner.style.width = "100%"; inner.style.height = "200px"; var outer = document.createElement('div'); outer.style.position = "absolute"; outer.style.top = "0px"; outer.style.left = "0px"; outer.style.visibility = "hidden"; outer.style.width = "200px"; outer.style.height = "150px"; outer.style.overflow = "hidden"; outer.appendChild(inner); document.body.appendChild(outer); var w1 = inner.offsetWidth; outer.style.overflow = 'scroll'; var w2 = inner.offsetWidth; if (w1 == w2) w2 = outer.clientWidth; document.body.removeChild(outer); return (w1 - w2); } function responsiveResize() { compensante = scrollCompensate(); if (($(window).width() + scrollCompensate()) <= 767 && responsiveflag == false) { accordion('enable'); accordionFooter('enable'); responsiveflag = true; } else if (($(window).width() + scrollCompensate()) >= 768) { accordion('disable'); accordionFooter('disable'); responsiveflag = false; } if (typeof page_name != 'undefined' && in_array(page_name, ['category'])) resizeCatimg(); } function blockHover(status) { $(document).off('mouseenter').on('mouseenter', '.product_list.grid li.ajax_block_product .product-container', function(e) { console.log("mouseenter product_list"); if ($('body').find('.container').width() == 1170) { var pcHeight = $(this).parent().outerHeight(); var pcPHeight = $(this).parent().find('.button-container').outerHeight()/* + $(this).parent().find('.comments_note').outerHeight() + $(this).parent().find('.functional-buttons').outerHeight()*/; //alert($(this).parent().find('.button-container').outerHeight()); $(this).parent().addClass('hovered').css({ 'height': pcHeight + pcPHeight, 'margin-bottom': pcPHeight * (-1), 'z-index': 1 }); } }); $(document).off('mouseleave').on('mouseleave', '.product_list.grid li.ajax_block_product .product-container', function(e) { console.log("click mouseleave"); if ($('body').find('.container').width() == 1170) $(this).parent().removeClass('hovered').css({ 'height': 'auto', 'margin-bottom': '0', 'z-index': 0 }); }); } function quick_view() { $(document).on('click', '.quick-view:visible, .quick-view-mobile:visible', function(e) { console.log("click quick view"); e.preventDefault(); var url = this.rel; if (url.indexOf('?') != -1) url += '&'; else url += '?'; if (!!$.prototype.fancybox) $.fancybox({ 'padding': 0, 'width': 1087, 'height': 610, 'type': 'iframe', 'href': url + 'content_only=1' }); }); } function bindGrid() { var view = display; if (!view && (typeof displayList != 'undefined') && displayList) view = 'list'; if (view && view != 'grid') Display(view); else $('.display').find('li#grid').addClass('selected'); // Unbind and re-bind events to avoid duplicate listeners $('.display').off('click', '#grid').on('click', '#grid', function(e) { console.log("click grid"); e.preventDefault(); Display('grid'); }); $('.display').off('click', '#list').on('click', '#list', function(e) { console.log("click list"); e.preventDefault(); Display('list'); }); } function Display(view) { if (view == 'list') { $('ul.product_list').removeClass('grid').addClass('list row'); $('.product_list > li').removeClass('col-xs-12 col-sm-6 col-sm-4 col-md-3').addClass('col-xs-12'); $('.product_list > li').each(function(index, element) { html = ''; html = '
' + $(element).find('.product-desc').html() + '
'; var colorList = $(element).find('.color-list-container').html(); if (colorList != null) { html += '' + $(element).find('.product-desc').html() + '
'; var price = $(element).find('.content_price').html(); if (price != null) { html += 'Click to close
' + '" + msg + "
"; msg += "" + question + "
"; msg += ""; var i = 0; for (var caption in buttons) { if (!buttons.hasOwnProperty(caption)) continue; funcName = buttons[caption]; if (typeof otherParams == 'undefined') otherParams = 0; otherParams = escape(JSON.stringify(otherParams)); action = funcName ? "$.fancybox.close();window['" + funcName + "'](JSON.parse(unescape('" + otherParams + "')), " + i + ")" : "$.fancybox.close()"; msg += '' i++; } msg += "
"; if (!!$.prototype.fancybox) { $.fancybox(msg, { 'autoDimensions': false, 'width': 500, 'height': 'auto', 'openEffect': 'none', 'closeEffect': 'none' }); } } function toggleLayer(whichLayer, flag) { if (!flag) $(whichLayer).hide(); else $(whichLayer).show(); } function openCloseLayer(whichLayer, action) { if (!action) { if ($(whichLayer).css('display') == 'none') $(whichLayer).show(); else $(whichLayer).hide(); } else if (action == 'open') $(whichLayer).show(); else if (action == 'close') $(whichLayer).hide(); } function updateTextWithEffect(jQueryElement, text, velocity, effect1, effect2, newClass) { if (jQueryElement.text() !== text) { if (effect1 === 'fade') jQueryElement.fadeOut(velocity, function() { $(this).addClass(newClass); if (effect2 === 'fade') $(this).text(text).fadeIn(velocity); else if (effect2 === 'slide') $(this).text(text).slideDown(velocity); else if (effect2 === 'show') $(this).text(text).show(velocity, function() {}); }); else if (effect1 === 'slide') jQueryElement.slideUp(velocity, function() { $(this).addClass(newClass); if (effect2 === 'fade') $(this).text(text).fadeIn(velocity); else if (effect2 === 'slide') $(this).text(text).slideDown(velocity); else if (effect2 === 'show') $(this).text(text).show(velocity); }); else if (effect1 === 'hide') jQueryElement.hide(velocity, function() { $(this).addClass(newClass); if (effect2 === 'fade') $(this).text(text).fadeIn(velocity); else if (effect2 === 'slide') $(this).text(text).slideDown(velocity); else if (effect2 === 'show') $(this).text(text).show(velocity); }); } } function dbg(value) { var active = false; var firefox = true; if (active) if (firefox) console.log(value); else alert(value); } function print_r(element, limit, depth) { depth = depth ? depth : 0; limit = limit ? limit : 1; returnString = '' +
element[property].replace(//g, '>') + '' + returnString + ''); winpop.document.close(); } return returnString; } function in_array(value, array) { for (var i in array) if ((array[i] + '') === (value + '')) return true; return false; } function isCleanHtml(content) { var events = 'onmousedown|onmousemove|onmmouseup|onmouseover|onmouseout|onload|onunload|onfocus|onblur|onchange'; events += '|onsubmit|ondblclick|onclick|onkeydown|onkeyup|onkeypress|onmouseenter|onmouseleave|onerror|onselect|onreset|onabort|ondragdrop|onresize|onactivate|onafterprint|onmoveend'; events += '|onafterupdate|onbeforeactivate|onbeforecopy|onbeforecut|onbeforedeactivate|onbeforeeditfocus|onbeforepaste|onbeforeprint|onbeforeunload|onbeforeupdate|onmove'; events += '|onbounce|oncellchange|oncontextmenu|oncontrolselect|oncopy|oncut|ondataavailable|ondatasetchanged|ondatasetcomplete|ondeactivate|ondrag|ondragend|ondragenter|onmousewheel'; events += '|ondragleave|ondragover|ondragstart|ondrop|onerrorupdate|onfilterchange|onfinish|onfocusin|onfocusout|onhashchange|onhelp|oninput|onlosecapture|onmessage|onmouseup|onmovestart'; events += '|onoffline|ononline|onpaste|onpropertychange|onreadystatechange|onresizeend|onresizestart|onrowenter|onrowexit|onrowsdelete|onrowsinserted|onscroll|onsearch|onselectionchange'; events += '|onselectstart|onstart|onstop'; var script1 = /<[\s]*script/im; var script2 = new RegExp('(' + events + ')[\s]*=', 'im'); var script3 = /.*script\:/im; var script4 = /<[\s]*(i?frame|embed|object)/im; if (script1.test(content) || script2.test(content) || script3.test(content) || script4.test(content)) return false; return true; } function getStorageAvailable() { test = 'foo'; storage = window.localStorage || window.sessionStorage; try { storage.setItem(test, test); storage.removeItem(test); return storage; } catch (error) { return null; } } $(document).ready(function() { $('form').submit(function() { console.log("submit form"); $(this).find('.hideOnSubmit').hide(); }); $.fn.checkboxChange = function(fnChecked, fnUnchecked) { console.log("checkboxChange"); if ($(this).prop('checked') && fnChecked) fnChecked.call(this); else if (fnUnchecked) fnUnchecked.call(this); if (!$(this).attr('eventCheckboxChange')) { $(this).on('change', function() { $(this).checkboxChange(fnChecked, fnUnchecked); }); $(this).attr('eventCheckboxChange', true); } }; $('a._blank, a.js-new-window').attr('target', '_blank'); }); /*============================= tools ==================================*/ /*============================= cart ==================================*/ // Shopping Cart jQuery & AJAX $(document).ready(function(){ var cart_block = new HoverWatcher('#header .cart_block'); var shopping_cart = new HoverWatcher('#header .shopping_cart'); if ('ontouchstart' in document.documentElement) { $('.shopping_cart > a:first').on('click', function(e) { console.log("click shopping_cart"); e.preventDefault(); }); } $(document).on('touchstart', '#header .shopping_cart a:first', function(e) { console.log("touchstart header"); if ($(this).next('.cart_block:visible').length) $("#header .cart_block").stop(true, true).slideUp(100); else $("#header .cart_block").stop(true, true).slideDown(100); e.preventDefault(); e.stopPropagation(); }); $("#header .shopping_cart a:first").hover(function() { $("#header .cart_block").stop(true, true).slideDown(100); }, function() { setTimeout(function() { if (!shopping_cart.isHoveringOver() && !cart_block.isHoveringOver()) $("#header .cart_block").stop(true, true).slideUp(100); }, 200); }); $("#header .cart_block").hover(function() {}, function() { setTimeout(function() { if (!shopping_cart.isHoveringOver()) $("#header .cart_block").stop(true, true).slideUp(100); }, 200); }); $(document).on('click', '#layer_cart .cross, #layer_cart .continue, .layer_cart_overlay', function(e) { console.log("click document layer_cart..."); e.preventDefault(); $('.layer_cart_overlay').hide(); $('#layer_cart').fadeOut('fast'); }); $(document).on('click', '.product_quantity_up', function(e) { console.log("click product_quantity_up"); e.preventDefault(); fieldName = $(this).data('field-qty'); var currentVal = parseInt($('input[name=' + fieldName + ']').val()); if (!isNaN(currentVal)){ $('input[name=' + fieldName + ']').val(currentVal + 1).trigger('keyup'); var qtyProduct = currentVal + 1; } if($(this).data('ref')){ var refProduct = $(this).data('ref'); var thumbProduct = $("#product_img_"+refProduct).attr("src"); var priceProductOrig = $("#product_price_orig_"+refProduct).text(); var priceProduct = $("#product_price_"+refProduct).text(); /* Note: Only the qty and product id should be usefull, others are for information */ var formData = { product_quantity: qtyProduct, product_id: refProduct, product_thumb: thumbProduct, product_price_orig: priceProductOrig, product_price: priceProduct, }; updateOrderTable(formData); } }); $(document).on('click', '.product_quantity_down', function(e) { console.log("click product_quantity_down"); e.preventDefault(); fieldName = $(this).data('field-qty'); var currentVal = parseInt($('input[name=' + fieldName + ']').val()); if (!isNaN(currentVal) && currentVal > 1){ $('input[name=' + fieldName + ']').val(currentVal - 1).trigger('keyup'); var qtyProduct = currentVal - 1; }else{ if(!$(this).data('additionalproduct')){ $('input[name=' + fieldName + ']').val(1); var qtyProduct = 1; } else { $('input[name=' + fieldName + ']').val(0); var qtyProduct = 0; } } if($(this).data('ref')){ var refProduct = $(this).data('ref'); var thumbProduct = $("#product_img_"+refProduct).attr("src"); var priceProduct = $("#product_price_"+refProduct).text(); var formData = { product_quantity: qtyProduct, product_id: refProduct, product_thumb: thumbProduct, product_price: priceProduct }; updateOrderTable(formData); } }); //$('.addtocart').submit(function(e){ $(document).on('submit', '.addtocart', function(e) { console.log("submit addtocart"); var form_data = $(this).serialize(); var button_content = $(this).find('button[type=submit]'); if (!button_content.data('original-text')) { button_content.data('original-text', button_content.html()); } button_content.html('' + (button_content.data('loading-text') || 'Loading...') + ''); $.ajax({ //make ajax request url: shopping_cart_url, type: "POST", dataType:"json", //expect json value from server data: form_data }).done(function(data){ //on Ajax success // If additional product we ignore all other actions and only we set qty if (data.additional_product_id && data.additional_product_qty) { $('input[name="quantity_' + data.additional_product_id + '"]').val(data.additional_product_qty); $('input[name="quantity_' + data.additional_product_id + '_hidden"]').val(data.additional_product_qty); button_content.html(button_content.data('original-text')); return; } $('.ajax_cart_no_product').html(data.items); //total items in cart-info element $('.cart_block_list').load( shopping_cart_url, { load_cart : 1}); $('.layer_cart_product').html(data.popup_product_html); $('.layer_cart_cart').load( shopping_cart_url, { load_popup_products_html : 1}); $('.ajax_cart_quantity').html(data.items); if(data.items == 1){ $('.ajax_cart_product_txt_s').addClass( "unvisible" ); }else{ $('.ajax_cart_product_txt').addClass( "unvisible" ); } $('.ajax_block_products_total').html(data.items); var top = parseInt($(window).scrollTop()) + 'px'; $('.layer_cart_overlay').css('width', '100%'); $('.layer_cart_overlay').css('height', '100%'); $('.layer_cart_overlay').show(); /*$('#layer_cart').css({ 'top': n, 'position': 'fixed' }).fadeIn('fast');*/ $('#layer_cart').css({ 'position': 'fixed', 'top': '150px', 'max-height': '80vh', 'overflow-y': 'auto' }).fadeIn('fast'); $("#layer_cart").css("display", "block"); button_content.html(button_content.data('original-text')); if($('.shopping-cart-box').css('display') == 'block'){ //if cart box is still visible $('.cart-box').trigger( 'click' ); //trigger click to update the cart box. } }) .fail(function() { alert( 'error' ); }); e.preventDefault(); }); // Remove items from cart $('body').on('click', '.ajax_cart_block_remove_link', function(e) { console.log("click ajax_cart_block_remove_link"); e.preventDefault(); var pcode = $(this).attr('data-code'); //get product code $(this).parent().fadeOut(); //remove item element from box $.getJSON( shopping_cart_url, {remove_code : pcode} , function(data){ //get Item count from Server $('.ajax_cart_no_product').html(data.items); $('.ajax_cart_quantity').html(data.items); if(data.items == 1){ $('.ajax_cart_product_txt_s').addClass( "unvisible" ); }else{ $('.ajax_cart_product_txt').addClass( "unvisible" ); } $('.ajax_block_products_total').html(data.items); $('.cart_block_list').load( shopping_cart_url, { load_cart : 1}); $('#product_'+ pcode).remove(); calc_total(); /* This update also additional line */ }); }); }); function updateOrderTable(formData) { $(".cart_quantity").css("pointer-events","none"); $.ajax({ //make ajax request url: shopping_cart_url, type: "POST", dataType:"json", //expect json value from server data: formData }).done(function(data){ //on Ajax success $('.ajax_cart_no_product').html(data.items); //total items in cart-info element $('.cart_block_list').load( shopping_cart_url, { load_cart : 1}); $('.layer_cart_product').html(data.popup_product_html); $('.layer_cart_cart').load( shopping_cart_url, { load_popup_products_html : 1}); $('.ajax_cart_quantity').html(data.items); if(data.items == 1){ $('.ajax_cart_product_txt_s').addClass( "unvisible" ); }else{ $('.ajax_cart_product_txt').addClass( "unvisible" ); } $('.ajax_block_products_total').html(data.items); var subtotal = parseFloat(formData.product_quantity) * parseFloat(formData.product_price.replace(',', '.')); $("#total_product_price_"+ formData.product_id).text(subtotal.toFixed(2)); calc_total(); /* This update also the additional line */ }) .fail(function() { alert( 'error' ); }); $(".cart_quantity").css("pointer-events","auto"); } function calc_total() { var sumbrut = 0; $(".total_brut_line").each(function(){ var id = $(this).attr("id"); if (id !== "total_brut_additional_line" && id !== "total_brut_shipping_fees_line") { var val = parseFloat($(this).text()); if (!isNaN(val)) { sumbrut += val; } } }); console.log("calc_total sumbrut="+sumbrut); var sum = 0; $(".total_line").each(function(){ var id = $(this).attr("id"); if (id !== "total_additional_line" && id !== "total_shipping_fees_line") { var val = parseFloat($(this).text()); if (!isNaN(val)) { sum += val; } } }); console.log("calc_total sum="+sum); if (sum === 0) { $("#cart_summary").fadeOut(400, function() { $(this).remove(); }); return; } var percent = parseFloat($('#total_additional_line').data('percent')) || 0; var qty = parseFloat($('#additionalProductQty').val()) || 0; var unitPriceOfAdditionalProduct = sumbrut * (percent / 100); var additional = unitPriceOfAdditionalProduct * qty; var shippingFees = parseFloat($('#total_shipping_fees_line').data('shipping-fees')) || 0; $('#total_additional_line').text(additional.toFixed(2)); $('#total_product').text((sum + additional + shippingFees).toFixed(2)); $('#total_price').text((sum + additional + shippingFees).toFixed(2)); $('#price_additional_product').text(unitPriceOfAdditionalProduct.toFixed(2)); } function HoverWatcher(selector) { this.hovering = false; var self = this; this.isHoveringOver = function() { return self.hovering; } $(selector).hover(function() { self.hovering = true; }, function() { self.hovering = false; }) } /*============================= cart ==================================*/ $(document).ready(function() { /*var thumbnails = $('.lightbox_trigger img').map(function() { return $(this).attr('src'); }).get();*/ var thumbnails = [...new Set($('.lightbox_trigger img').map(function() { return $(this).attr('src'); }).get())]; var currentIndex = 0; // Open lightbox when clicking on a thumbnail $('.lightbox_trigger').click(function(e) { console.log("click lightbox trigger"); console.log(thumbnails); e.preventDefault(); //currentIndex = thumbnails.indexOf($(this).find('img').attr('src')); currentIndex = thumbnails.indexOf($(this).find('img').attr('src') || $(this).attr('src')); updateLightboxContent(); $('#lightbox').show(); updateNavigationVisibility(); $('body').css('overflow', 'hidden'); // Disable scrolling on body }); // Close lightbox when clicking outside content $('#lightbox').click(function(e) { console.log("click lightbox"); if (!$(e.target).is('#lightbox-prev, #lightbox-next, #content img')) { console.log("we are outside content"); $('#lightbox').hide(); $('body').css('overflow', 'auto'); // Re-enable scrolling when lightbox is closed } }); // Navigate through lightbox $('#lightbox-prev, #lightbox-next').click(function(e) { console.log("click lightbox prev next"); e.stopPropagation(); navigateLightbox($(this).attr('id') === 'lightbox-next' ? 1 : -1); }); // Update lightbox content function updateLightboxContent() { //console.log($('#content').html()); //console.log(thumbnails[currentIndex]); //$('#content').html('