// Author: Edwin Doughty // Modified: 2020 / 06 / 09 // Código jquery personalizado de Tucan Home 1.7 // Copy to themes/classic/assets/js/tucanhome.js /* Event Handlers and browser compatibility*/ var lang = "en"; var domainRoot = "https://www.tucanhome.es/tucanhome/"; var userlogged = false; $(window).load(function () { // full load }); $(document).ready(function () { setLanguage(); cssAdjustments(); changeTransportToEnglish(); insertGoogleAnalytics(); doMobile(); insertMetaTags(); bugFixes(); attachRecycleLink(); dropDown(); setLogoLinkLanguage(); fixCartShippingTxt(); cifObligatorio(); attachSampleText(); setTxtEncimeraMuebles(); insertarLogosDePago(); // Ajustes para alfombras a medida de Keplan y geometrika // Ajustes para muebles personalizados if ($('ul#group_16') !== null) { setCustomSize(); } if (lang == "es") $("span.new i").text('Novedad'); $("span.new i").css("padding", "2px"); }); $(window).resize(function () { var h = $(window).height(), w = $(window).width(); if (w < 480) $(" .pb-left-column #image-block #view_full_size .span_link").css('display', 'none'); }); function orientationChanged() { const timeout = 120; return new window.Promise(function (resolve) { const go = (i, height0) => { window.innerHeight != height0 || i >= timeout ? resolve() : window.requestAnimationFrame(() => go(i + 1, height0)); }; go(0, window.innerHeight); }); } window.addEventListener('orientationchange', function () { orientationChanged().then(function () { // Profit ($('#index .iosSliderBanner_image').length > 0) { // Simply reload page to readjust width and height location.reload(); } }); }); /* Source: https://github.com/jserz/js_piece/blob/master/DOM/ParentNode/append()/append().md */ (function (arr) { arr.forEach(function (item) { if (item.hasOwnProperty('append')) { return; } Object.defineProperty(item, 'append', { configurable: true, enumerable: true, writable: true, value: function append() { var argArr = Array.prototype.slice.call(arguments), docFrag = document.createDocumentFragment(); argArr.forEach(function (argItem) { var isNode = argItem instanceof Node; docFrag.appendChild(isNode ? argItem : document.createTextNode(String(argItem))); }); this.appendChild(docFrag); } }); }); })([Element.prototype, Document.prototype, DocumentFragment.prototype]); /* END OF IMPLEMENT --- Event Handlers and browser compatibility */ /* ************************************************************* */ // !!!!!! Prestashop BUG Fixes: function bugFixes() { /* Corrección de BUG prestashop del carrito de la compra */ if (document.getElementById('mobile_bar_cart_tri')) { document.getElementById('mobile_bar_cart_tri').setAttribute('href', domainRoot + 'es/pedido'); } /* Correccion de BUG prestashop cuando en modo dispositivo movil*/ var h = $(window).height(), w = $(window).width(); if (w < 480) $(" .pb-left-column #image-block #view_full_size .span_link").css('display', 'none'); // Fix prestashop bug that takes user to wrong home page. $("ul._copyright_tucan a").attr("href", domainRoot); } // onready sub calls: function setLanguage() { if ( $('body.lang-es').length > 0 ) { lang = "es"; } else if ( $('body.lang-en').length > 0 ) { lang = "en"; } } function attachRecycleLink() { if (window.matchMedia("(max-width: 767px)").matches) { // si es dispositivo movil, insertamos enlace en el menu /* var oSection = document.createElement('section'); var oLink = document.createElement('a'); var oImg = document.createElement('img'); oSection.id = "seccion_eco"; $(oSection).addClass("block column_block informations_block_left"); $(oLink).css('color', '#929d80'); if (lang == 'es') { $(oLink).attr("href", domainRoot + "index.php?id_category=138&controller=category&id_lang=3"); $(oLink).append('Artículos Ecológicos '); } else if (lang == 'en') { $(oLink).attr("href", domainRoot + "index.php?id_category=138&controller=category&id_lang=6"); $(oLink).append('Eco-friendly items '); } $(oImg).attr("src", "/tucanhome/img/reciclado.jpg"); $(oLink).append($(oImg)); $(oSection).append(oLink); $(oSection).css('display', 'block'); $(oLink).css('margin-left', '.6rem'); $(oLink).css('font-size', '16pt'); $(oSection).insertBefore($('#mobile_top_menu_wrapper div.js-top-menu-bottom #_mobile_currency_selector'));*/ } else { // si no es dispositivo movil, el componente está creado en ps_categorytree.tpl var vHREF = domainRoot + 'index.php?id_category=138&controller=category&id_lang=3'; var vText = 'Artículos Ecológicos '; var vSrc = '/tucanhome/img/reciclado.jpg'; if (lang == 'en') { vHREF = domainRoot + 'index.php?id_category=138&controller=category&id_lang=6'; vText = 'Eco-friendly items '; } $("div#seccion_eco a").attr('href', vHREF); $("div#seccion_eco a span").text(vText); $("img#img_eco").attr('src', vSrc); } } function showSubMenu(menuSelection) { /*Neutralize on first finger press of ipad*/ var x = "#top-menu li#category-" + menuSelection + " a[data-depth='0']"; if ($(x).attr("href_temp") != '' ) $(x).attr("href", $(x).attr("href_temp")); } function cssAdjustments() { /* Menu adaptation to tablets and IPads*/ if (!window.matchMedia("(max-width: 767px)").matches) { if ($("#top-menu li#category-56 a").length > 0) { $("#top-menu li#category-56 a[data-depth='0']").append("expand_more"); } if ($("#top-menu li#category-90 a").length > 0) { $("#top-menu li#category-90 a[data-depth='0']").append("expand_more"); } if ($("#top-menu li#category-78 a").length > 0) { $("#top-menu li#category-78 a[data-depth='0']").append("expand_more"); } if ($("#top-menu li#category-81 a").length > 0) { $("#top-menu li#category-81 a[data-depth='0']").append("expand_more"); } if ($("#top-menu li#category-12 a").length > 0) { $("#top-menu li#category-12 a[data-depth='0']").append("expand_more"); } if ($("#top-menu li#category-57 a").length > 0) { $("#top-menu li#category-57 a[data-depth='0']").append("expand_more"); } } var is_iPad = window.matchMedia("(max-width: 1024px)").matches || navigator.userAgent.match(/iPad/i) != null; if (is_iPad) { if ($("#top-menu li#category-56 div").length > 0) { $("#top-menu li#category-56 a[data-depth='0']").attr("href_temp", $("#top-menu li#category-56 a[data-depth='0']").attr("href")); $("#top-menu li#category-56 a[data-depth='0']").attr("href", "javascript:showSubMenu('56');"); } if ($("#top-menu li#category-90 div").length > 0) { $("#top-menu li#category-90 a[data-depth='0']").attr("href_temp", $("#top-menu li#category-90 a[data-depth='0']").attr("href")); $("#top-menu li#category-90 a[data-depth='0']").attr("href", "javascript:showSubMenu('90');"); } if ($("#top-menu li#category-78 div").length > 0) { $("#top-menu li#category-78 a[data-depth='0']").attr("href_temp", $("#top-menu li#category-78 a[data-depth='0']").attr("href")); $("#top-menu li#category-78 a[data-depth='0']").attr("href", "javascript:showSubMenu('78');"); } if ($("#top-menu li#category-81 div").length > 0) { $("#top-menu li#category-81 a[data-depth='0']").attr("href_temp", $("#top-menu li#category-81 a[data-depth='0']").attr("href")); $("#top-menu li#category-81 a[data-depth='0']").attr("href", "javascript:showSubMenu('81');"); } if ($("#top-menu li#category-12 div").length > 0) { $("#top-menu li#category-12 a[data-depth='0']").attr("href_temp", $("#top-menu li#category-12 a[data-depth='0']").attr("href")); $("#top-menu li#category-12 a[data-depth='0']").attr("href", "javascript:showSubMenu('12');"); } if ($("#top-menu li#category-57 div").length > 0) { $("#top-menu li#category-57 a[data-depth='0']").attr("href_temp", $("#top-menu li#category-57 a[data-depth='0']").attr("href")); $("#top-menu li#category-57 a[data-depth='0']").attr("href", "javascript:showSubMenu('57');"); } } $("h2").removeClass('text-uppercase'); /*Si es movil, reubicar opciones de informacion*/ if (window.matchMedia("(max-width: 767px)").matches) { jQuery("div.links").detach().appendTo('#mobile_top_menu_wrapper'); $("div.links span.h3").css('margin-left', '-10px'); } // category-depth-level-3 // category-depth-level-3 if ($("body.category-depth-level-3").length > 0 || $("body.category-depth-level-4").length > 0) { $("#js-product-list-header").css('display', 'none'); } if ($("#left-column").length > 0) { $("#left-column ul.category-top-menu li:first-child a").removeClass('text-uppercase'); } $("#gdpr_consent span a").attr('target', '_blank'); if (lang == 'es') $("#_subscribe_email input:first-child").attr('placeholder', 'Tu e-mail'); else $("#_subscribe_email input:first-child").attr('placeholder', 'Your email'); if ($("body#product").length > 0) { $("div.product-information div.blockreassurance_product").insertAfter($("div.product-information div.tabs")); $("div.product-information div.blockreassurance_product").css("display", "none"); } // Fix contact us text if (lang == "en") { $("div#contact-link a").html("mail_outlineAsk us"); $("#submitNewsletter").attr('value', 'Subscribe'); } // Visualizar titulo en las variantes de combinacion de los productos // ETD caracteristica no incluida en Prestashop 1.7 if ($("span.sr-only").length > 0) { for (var i = 0; i < $("span.sr-only").length; i++) { $("div.product-variants span.sr-only").eq(i).parent().attr('title', $("div.product-variants span.sr-only").eq(i).text()); } } // ps_linklist if ($("body#my-account").length == 0 && $("#mobile_top_menu_wrapper div.links").length > 1) { $("#mobile_top_menu_wrapper div.links:last-child").css('display', 'none'); } } function fixCartShippingTxt(){ if (lang == 'es') { $("body#cart div#cart-subtotal-shipping span.label").text("Gastos de envío estimado:"); $("body#cart div#cart-subtotal-shipping span.value").text("0,00 €"); if ($("body#checkout section#checkout-personal-information-step div").css('display') == 'block' || $("body#checkout section#checkout-addresses-step div").css('display') == 'block') { $("body#checkout div#cart-subtotal-shipping span.label").text("Gastos de envío estimado:"); $("body#checkout div#cart-subtotal-shipping span.value").text("0,00 €"); } } else if (lang == 'en') { $("body#cart div#cart-subtotal-shipping span.label").text("Estimated cost of shipping:"); $("body#cart div#cart-subtotal-shipping span.value").text("0.00 €"); if ($("body#checkout section#checkout-personal-information-step div").css('display') == 'block' || $("body#checkout section#checkout-addresses-step div").css('display') == 'block') { $("body#checkout div#cart-subtotal-shipping span.label").text("Estimated cost of shipping:"); $("body#checkout div#cart-subtotal-shipping span.value").text("0.00 €"); } } } function setLogoLinkLanguage() { //Prestashop bug fix. Make logo language sensitive. if (lang == 'es') { $("#_desktop_logo a").attr("href", domainRoot + "index.php?controller=prices-drop&id_lang=3"); $("#_mobile_logo a").attr("href", domainRoot + "index.php?controller=prices-drop&id_lang=3"); } else if (lang == 'en') { $("#_desktop_logo a").attr("href", domainRoot + "index.php?controller=prices-drop&id_lang=6"); $("#_mobile_logo a").attr("href", domainRoot + "index.php?controller=prices-drop&id_lang=6"); } } function doMobile() { if (window.matchMedia("(max-width: 767px)").matches) { // The viewport is less than 768 pixels wide $('#footer div.container div.row div.block-social').css("margin-top", "1rem") $('#search_widget').insertBefore($('#footer div.container div.row div.block-social ul')); $('#search_widget').css('margin-left', '1rem'); $('#footer div.footer-container #search_widget').remove(); } else { // The viewport is at least 768 pixels wide // $('#left-column').append($('#search_widget')); } } function changeTransportToEnglish() { var titleT = ""; if (lang == "en" && $("#order").length > 0) { titleT = $("div.alternate_item td.white_space_normal strong").text(); if (titleT == "Tucan Home - Recogida en tienda. ") { $("div.alternate_item td.white_space_normal strong").text("Tucan Home - Pick merchandise up at shop."); } else if (titleT == "Tucan Home - Recogida de muebles en tienda") { $("div.alternate_item td.white_space_normal strong").text("Tucan Home - Pick furniture up at shop."); } } } function insertGoogleAnalytics() { if ($('head').length) { var script = document.createElement("script"); var script2 = document.createElement("script"); var comNode = document.createComment(' Global Site Tag (gtag.js) - Google Analytics '); script.setAttribute('async', ''); script.setAttribute('src', 'https://www.googletagmanager.com/gtag/js?id=UA-102315232-1'); script2.innerHTML = "window.dataLayer = window.dataLayer || [];" + "function gtag(){dataLayer.push(arguments)};" + "gtag('js', new Date());" + "gtag('config', 'UA-102315232-1');"; $('head').append(comNode); $('head').first().append(script); $('head').first().append(script2); } } function insertMetaTags() { var metaK = document.createElement("meta"); metaK.setAttribute("name", "keywords"); metaK.setAttribute("content", "lámparas, de, cerámica, diseño, modernas, alfombras, ecólogicas, cojines, mantas, loza, ecológico, muebles, Alcobendas, Madrid, bolsos, lamps, ceramic, rugs, ecological, cushions, blankets, furniture, wallpaper"); $('head').append(metaK); } function setTxtEncimeraMuebles() { /* Se modifica el texto original MDF o marmol cuando solo es MDF*/ var objLabel = $("div.product-variants div.product-variants-item:eq(1) span.control-label"); var txtLabel = objLabel.text(); /*Mesas de centro y comedor con encimera dsponible solo MDF*/ if ($('body.product-id-1231').length > 0 || /*HAY*/ $('body.product-id-1230').length > 0 || /*FERM*/ $('body.product-id-1236').length > 0 || /*MOI*/ $('body.product-id-768').length > 0 || /*Cuba*/ $('body.product-id-1287').length > 0 || /*Comedor*/ $('body.product-id-1288').length > 0) /*Comedor*/ { txtLabel = (lang == "en") ? 'MDF tabletop' : 'Encimera MDF'; } else if ($('body.product-id-1249').length > 0) { /*HAY II disponible solo hierro - no es ni MDF ni Marmol*/ txtLabel = (lang == "en") ? 'Iron tabletop (forged)' : 'Encimera de Hierro (forjado)'; } objLabel.text(txtLabel); } function trimField(fname) { $(fname).val($.trim($(fname).val())); } function cifObligatorio() { // Si el campo empresa tiene valor, preparar que campo CIF sea obligatorio: // Obligar el cliente a introducir numero de móvil if ($("body#address").length > 0) { var sup = document.createElement('sup'); var txtAst = document.createTextNode(' *'); sup.appendChild(txtAst); $("section.form-fields div.form-group:eq(5) label").append(sup); $('input#vat_number').addClass('is_required'); validateNumIVA(); $("#company").blur(function () { validateNumIVA(); }); /* $('input#phone_mobile').attr('required', 'required'); $('input#phone_mobile').addClass('is_required'); var $label = $('label[for="phone_mobile"]'); var txt = $label.text() + ' *'; $label.text(txt);*/ } $('#dni').blur(function () { trimField('#dni'); }); $('#postcode').blur(function () { trimField('#postcode'); }); } function validateNumIVA() { // div id="vat-number" to locate label with text "Su número de IVA" // div class="form-group" is child of div id="vat-number" and is changed to class "required form-group //form-ok" // if input#company has data // input id="vat-number" if becomes mandatory add class "is_required" we know it is mandatory // if div id="vat-number" style="display:block", otherwise style="display:none" // this function should be fired onblur event of input id="company" if ($('section.form-fields div.form-group:eq(5)').css('display') == 'block') { $('input#vat_number').attr('required', 'required'); } else { $('input#vat_number').removeAttr('required'); $('input#vat_number').removeAttr('value'); } } function attachSampleText() { //Para lamparas, y cajas de ceramica var mushroomLamp = $("body.product-id-1436").length + $("body.product-id-1437").length + $("body.product-id-1438").length; if (lang == "es") { // Lámparas de ceramica con pantalla if ($("body.product-id-category-73").length > 0) { $("div.product-variants div.clearfix:eq(0)").prepend("
Pulsa sobre los colores en los muestrarios de abajo para personalizar tu lámpara:
"); if (mushroomLamp == 0) { $("div.product-variants div.clearfix:eq(0)").prepend("Busca la combinación que más te guste de color de cerámica y pantalla.
"); } } // lamparas de ceramica sin pantalla y cajas de ceramica else if ($("body.product-id-category-72").length > 0 || $("body.product-id-category-118").length > 0) { $("div.product-variants div.clearfix:eq(0)").prepend("Pulse sobre el color deseado en el muestrario de abajo:
"); $("div.product-variants div.clearfix:eq(0)").prepend("Elige el color de cerámica que más te guste.
"); } //Lámparas de techo else if ($("body.product-id-category-88").length > 0) { if ($("body.product-id-752").length > 0 || $("body.product-id-541").length > 0 || $("body.product-id-956").length > 0 || $("body.product-id-1385").length > 0 || $("body.product-id-1193").length > 0 || $("body.product-id-1429").length > 0 || $("body.product-id-954").length > 0 || $("body.product-id-546").length > 0) $("div.product-variants div.clearfix:eq(0)").prepend("Pulse sobre el color deseado en el muestrario de abajo:
"); else $("div.product-variants div.clearfix:eq(0)").prepend("Selecciona el tamaño deseado (el precio puede variar):
"); } } else if (lang == "en") { // Lámparas de ceramica con pantalla if ($("body.product-id-category-73").length > 0) { $("div.product-variants div.clearfix:eq(0)").prepend("Click on the desired colors in the samples below:
"); if (mushroomLamp == 0) { $("div.product-variants div.clearfix:eq(0)").prepend("Choose the combination you'd like for the ceramic color and shade fabric.
"); } } // lamparas de ceramica sin pantalla y cajas de ceramica else if ($("body.product-id-category-72").length > 0 || $("body.product-id-category-118").length > 0) { $("div.product-variants div.clearfix:eq(0)").prepend("Click on the desired color in the sample below:
"); $("div.product-variants div.clearfix:eq(0)").prepend("Choose the ceramic color that you like the most.
"); } //Lámparas de techo else if ($("body.product-id-category-88").length > 0) { if ($("body.product-id-752").length > 0 || $("body.product-id-541").length > 0 || $("body.product-id-956").length > 0 || $("body.product-id-1385").length > 0 || $("body.product-id-1193").length > 0 || $("body.product-id-1429").length > 0 || $("body.product-id-954").length > 0 || $("body.product-id-546").length > 0) $("div.product-variants div.clearfix:eq(0)").prepend("Click on the desired color in the sample below:
"); else $("div.product-variants div.clearfix:eq(0)").prepend("Select the desired size (the price may vary accordingly):
"); } } } function setCustomSize() { // var prodDescription = $('#short_description_content p').text(); var prodDescription = $('div.product-reference span').text(); prodDescription = prodDescription + ' ' + $('section#main div.col-md-6 h1').text(); if ($('body.product-mesa-auxiliar-alvin').length > 0 || $('body.product-alvin-side-table').length > 0 || $('body.product-mesa-centro-cuba').length > 0 || $('body.product-cuba-center-table').length > 0 || $('body.product-mesa-rectangular-comedor-mediana').length > 0 || $('body.product-dining-table-medium-sized').length > 0 || $('body.product-mesa-rectangular-comedor-grande').length > 0 || $('body.product-dining-table-large-sized').length > 0 || $('body.product-consola').length > 0 || $('body.product-console').length > 0 || $('body.product-consola-belgravia').length > 0 || $('body.product-belgravia-console').length > 0 || $('body.product-consola-nimes').length > 0 || $('body.product-nimes-console').length > 0 || $('body.category-79').length > 0 || $('body.category-97').length > 0 || $('body.category-98').length > 0 || $('body.category-99').length > 0 || $('body.category-100').length > 0 || $('body.category-101').length > 0 || $('body.category-157').length > 0 ) { var p = document.createElement("p"); if ($("ul#group_16").length > 0) $("ul#group_16").parent().append(p); else if ($("ul#group_16").length > 0) $("ul#group_16").parent().append(p); $(p).css('display', 'inline-block'); $(p).css('margin-top', '1.5rem'); $(p).text('For a different size, please contact us. '); if (lang == "es") $(p).text('Para otra medida, contacta con nosotros. '); var aHref = document.createElement("a"); p.append(aHref); var href = domainRoot + 'index.php?controller=contact&id_lang=3?message=Reference: ' + prodDescription; if (lang == "es") href = domainRoot + 'index.php?controller=contact&id_lang=6?message=Referencia: ' + prodDescription; $(aHref).attr('href', href); $(aHref).attr('target', '_blank'); $(aHref).attr('style', 'text-decoration:none;padding:6px 4px 3px 4px;font-weight:500;font-size:10pt;color:#929d80;border:2px solid #929d80;background-color:#e2f3c6;'); $(aHref).text('CONTACT US'); if (lang == "es") $(aHref).text('CONTACTAR'); } } function insertarLogosDePago() { // On checkout, logos missing. This function creates and inserts missing logos if ($('#checkout').length > 0) { var imgLogoRS = document.createElement('img'); // RedSys Logo var imgLogoBW = document.createElement('img'); // Bankwire logo $(imgLogoRS).attr('src', "/tucanhome/img/imgRedSys.jpg"); $(imgLogoRS).css('max-width', '100px'); $("div#payment-option-3-container label").append(imgLogoRS); $(imgLogoBW).attr('src', "/tucanhome/img/imgBankWire.jpg"); $(imgLogoBW).css('max-width', '75px'); $("div#payment-option-1-container label").append(imgLogoBW); } } /* Custom Links menu */ function dropDown() { $('.dropdown_wrap').hover(function () { $(this).addClass('open'); }, function () { $(this).removeClass('open'); }); } function isPlaceholer() { var input = document.createElement('input'); return "placeholder" in input; }