1OFFSET = 100 2document.addEventListener('DOMContentLoaded', () => { 3 4 5 6 7 8 9 "use strict"; 10 11 /** 12 * Preloader 13 */ 14 const preloader = document.querySelector('#preloader'); 15 if (preloader) { 16 window.addEventListener('load', () => { 17 preloader.setAttribute('style', 'display:none'); 18 }); 19 } 20 21 /** 22 * Sticky header on scroll 23 */ 24 const selectHeader = document.querySelector('#header_test'); 25 if (selectHeader) { 26 document.addEventListener('scroll', () => { 27 window.scrollY > OFFSET ? selectHeader.classList.add('sticked') : selectHeader.classList.remove('sticked'); 28 }); 29 } 30 31 /** 32 * Navbar links active state on scroll 33 */ 34 let navbarlinks = document.querySelectorAll('#navbar .scrollto'); 35 36 function navbarlinksActive() { 37 navbarlinks.forEach(navbarlink => { 38 39 if (!navbarlink.hash) 40 return; 41 42 let section = document.querySelector(navbarlink.hash); 43 if (!section) 44 return; 45 46 let position = window.scrollY; 47 if (navbarlink.hash != '#header_test') 48 position += 100; 49 50 if (position >= section.offsetTop && position <= (section.offsetTop + section.offsetHeight)) { 51 navbarlink.classList.add('active'); 52 } else { 53 navbarlink.classList.remove('active'); 54 } 55 }) 56 } 57 // window.addEventListener('load', navbarlinksActive); 58 // document.addEventListener('scroll', navbarlinksActive); 59 60 /** 61 * Function to scroll to an element with top ofset 62 */ 63 function scrollto(el) { 64 const selectHeader = document.querySelector('#header_test'); 65 let offset = 0; 66 67 if (selectHeader.classList.contains('sticked')) { 68 offset = document.querySelector('#header_test.sticked').offsetHeight; 69 } else if (selectHeader.hasAttribute('data-scrollto-offset')) { 70 offset = selectHeader.offsetHeight - parseInt(selectHeader.getAttribute('data-scrollto-offset')); 71 } 72 window.scrollTo({ 73 top: document.querySelector(el).offsetTop - offset, 74 behavior: 'smooth' 75 }); 76 } 77 78 /** 79 * Fires the scrollto function on click to links .scrollto 80 */ 81 let selectScrollto = document.querySelectorAll('.scrollto'); 82 selectScrollto.forEach(el => el.addEventListener('click', function(event) { 83 if (document.querySelector(this.hash)) { 84 event.preventDefault(); 85 86 let mobileNavActive = document.querySelector('.mobile-nav-active'); 87 if (mobileNavActive) { 88 mobileNavActive.classList.remove('mobile-nav-active'); 89 90 let navbarToggle = document.querySelector('.mobile-nav-close'); 91 } 92 // scrollto(this.hash); 93 } 94 })); 95 96 /** 97 * Scroll with ofset on page load with hash links in the url 98 */ 99 window.addEventListener('load', () => { 100 if (window.location.hash) { 101 if (document.querySelector(window.location.hash)) { 102 // scrollto(window.location.hash); 103 } 104 } 105 }); 106 107 /** 108 * Mobile nav toggle 109 */ 110 const mobileNavToogle = document.querySelector('.mobile-nav-close'); 111 if (mobileNavToogle) { 112 mobileNavToogle.addEventListener('click', function(event) { 113 event.preventDefault(); 114 115 document.querySelector('body').classList.toggle('mobile-nav-active'); 116 }); 117 } 118 119 const chiudiMobileNavToogle = document.querySelector('.chiudi-nav-close'); 120 if (chiudiMobileNavToogle) { 121 chiudiMobileNavToogle.addEventListener('click', function(event) { 122 event.preventDefault(); 123 124 document.querySelector('body').classList.toggle('mobile-nav-active'); 125 }); 126 } 127 128 /** 129 * Toggle mobile nav dropdowns 130 */ 131 const navDropdowns = document.querySelectorAll('.navbar .dropdown > a'); 132 133 /*navDropdowns.forEach(el => { 134 el.addEventListener('click', function (event) { 135 if (document.querySelector('.mobile-nav-active')) { 136 event.preventDefault(); 137 this.classList.toggle('active'); 138 this.nextElementSibling.classList.toggle('dropdown-active'); 139 140 let dropDownIndicator = this.querySelector('.dropdown-indicator'); 141 dropDownIndicator.classList.toggle('bi-chevron-up'); 142 dropDownIndicator.classList.toggle('bi-chevron-down'); 143 } 144 }) 145 });*/ 146 147 /** 148 * Auto generate the hero carousel indicators 149 */ 150 let heroCarouselIndicators = document.querySelector('#hero .carousel-indicators'); 151 if (heroCarouselIndicators) { 152 let heroCarouselItems = document.querySelectorAll('#hero .carousel-item') 153
154 heroCarouselItems.forEach((item, index) => { 155 if (index === 0) { 156 heroCarouselIndicators.innerHTML += `<li data-bs-target="#hero" data-bs-slide-to="${index}" class="active"></li>`; 157 } else { 158 heroCarouselIndicators.innerHTML += `<li data-bs-target="#hero" data-bs-slide-to="${index}"></li>`; 159 } 160 }); 161 } 162 163 /** 164 * Scroll top button 165 */ 166 const scrollTop = document.querySelector('.scroll-top'); 167 if (scrollTop && false) { 168 const togglescrollTop = function() { 169 window.scrollY > OFFSET ? scrollTop.classList.add('active') : scrollTop.classList.remove('active'); 170 } 171 // window.addEventListener('load', togglescrollTop); 172 document.addEventListener('scroll', togglescrollTop); 173 174 scrollTop.addEventListener('click', window.scrollTo({ 175 top: 0, 176 behavior: 'smooth' 177 })); 178 } 179 180 /** 181 * Initiate glightbox 182 */ 183 const glightbox = GLightbox({ 184 selector: '.glightbox' 185 }); 186 187 /** 188 * Porfolio isotope and filter 189 */ 190 let portfolionIsotope = document.querySelector('.portfolio-isotope'); 191 192 if (portfolionIsotope) { 193 194 let portfolioFilter = portfolionIsotope.getAttribute('data-portfolio-filter') ? portfolionIsotope.getAttribute('data-portfolio-filter') : '*'; 195 let portfolioLayout = portfolionIsotope.getAttribute('data-portfolio-layout') ? portfolionIsotope.getAttribute('data-portfolio-layout') : 'masonry'; 196 let portfolioSort = portfolionIsotope.getAttribute('data-portfolio-sort') ? portfolionIsotope.getAttribute('data-portfolio-sort') : 'original-order'; 197 198 window.addEventListener('load', () => { 199 let portfolioIsotope = new Isotope(document.querySelector('.portfolio-container'), { 200 itemSelector: '.portfolio-item', 201 layoutMode: portfolioLayout, 202 filter: portfolioFilter, 203 sortBy: portfolioSort 204 }); 205 206 let menuFilters = document.querySelectorAll('.portfolio-isotope .portfolio-flters li'); 207 menuFilters.forEach(function(el) { 208 el.addEventListener('click', function() { 209 document.querySelector('.portfolio-isotope .portfolio-flters .filter-active').classList.remove('filter-active'); 210 this.classList.add('filter-active'); 211 portfolioIsotope.arrange({ 212 filter: this.getAttribute('data-filter') 213 }); 214 if (typeof aos_init === 'function') { 215 var aos_inizializza = aos_init(); 216 } 217 }, false); 218 }); 219 220 }); 221 222 } 223 224 /** 225 * Clients Slider 226 */ 227 new Swiper('.clients-slider', { 228 speed: 400, 229 loop: true, 230 autoplay: { 231 delay: 5000, 232 disableOnInteraction: false 233 }, 234 slidesPerView: 'auto', 235 breakpoints: { 236 320: { 237 slidesPerView: 2, 238 spaceBetween: 40 239 }, 240 480: { 241 slidesPerView: 3, 242 spaceBetween: 60 243 }, 244 640: { 245 slidesPerView: 4, 246 spaceBetween: 80 247 }, 248 992: { 249 slidesPerView: 6, 250 spaceBetween: 120 251 } 252 } 253 }); 254 255 256 257 /** 258 * Scelti Home Slider 259 */ 260 // new Swiper('.scelti-home-slider', { 261 // speed: 600, 262 // loop: false, 263 // autoplay: false, 264 // slidesPerView: 'auto', 265 // pagination: { 266 // el: '.swiper-pagination', 267 // type: 'bullets', 268 // clickable: true 269 // }, 270 // navigation: { 271 // nextEl: '.scelti-home-slider-next', 272 // prevEl: '.scelti-home-slider-prev' 273 // }, 274 // breakpoints: { 275 // 320: { 276 // slidesPerView: 1, 277 // spaceBetween: 20 278 // }, 279 // 480: { 280 // slidesPerView: 2, 281 // spaceBetween: 20 282 // }, 283 // 640: { 284 // slidesPerView: 2, 285 // spaceBetween: 20 286 // }, 287 // 992: { 288 // slidesPerView: 5, 289 // spaceBetween: 0 290 // } 291 // } 292 // }); 293 294 /** 295 * Scelti Home Slider 296 */ 297 new Swiper('.scelti-filtri-home-slider', { 298 speed: 600,
299 loop: false, 300 autoplay: false, 301 slidesPerView: 'auto', 302 pagination: { 303 el: '.swiper-pagination', 304 type: 'bullets', 305 clickable: true 306 }, 307 navigation: { 308 nextEl: '.scelti-home-slider-next', 309 prevEl: '.scelti-home-slider-prev' 310 }, 311 breakpoints: { 312 320: { 313 slidesPerView: 1, 314 spaceBetween: 20 315 }, 316 480: { 317 slidesPerView: 2, 318 spaceBetween: 20 319 }, 320 640: { 321 slidesPerView: 2, 322 spaceBetween: 20 323 }, 324 992: { 325 slidesPerView: 5, 326 spaceBetween: 0 327 } 328 } 329 }); 330 /** 331 * Header Categoria Slider 332 */ 333 new Swiper('.header-categoria-slider', { 334 speed: 600, 335 loop: false, 336 autoplay: false, 337 slidesPerView: 'auto', 338 pagination: { 339 el: '.swiper-pagination', 340 type: 'bullets', 341 clickable: true 342 }, 343 navigation: { 344 nextEl: '.header-categoria-slider-next', 345 prevEl: '.header-categoria-slider-prev' 346 }, 347 breakpoints: { 348 320: { 349 slidesPerView: 1, 350 spaceBetween: 20 351 }, 352 480: { 353 slidesPerView: 2, 354 spaceBetween: 20 355 }, 356 640: { 357 slidesPerView: 2, 358 spaceBetween: 20 359 }, 360 992: { 361 slidesPerView: 5, 362 spaceBetween: 0 363 } 364 } 365 }); 366 367 /** 368 * Categoria Voci Slider 369 */ 370 new Swiper('.categoria-voci-slider', { 371 speed: 600, 372 loop: false, 373 autoplay: false, 374 slidesPerView: 'auto', 375 pagination: { 376 el: '.swiper-pagination', 377 type: 'bullets', 378 clickable: true 379 }, 380 navigation: { 381 nextEl: '.categoria-voci-slider-next', 382 prevEl: '.categoria-voci-slider-prev' 383 }, 384 breakpoints: { 385 320: { 386 slidesPerView: 1, 387 spaceBetween: 20 388 }, 389 480: { 390 slidesPerView: 2, 391 spaceBetween: 20 392 }, 393 640: { 394 slidesPerView: 2, 395 spaceBetween: 20 396 }, 397 992: { 398 slidesPerView: 5, 399 spaceBetween: 0 400 } 401 } 402 }); 403 404 /** 405 * Inizia Home Slider 406 */ 407 // new Swiper('#inizia-home-slider', { 408 // speed: 600, 409 // loop: false, 410 // autoplay: false, 411 // slidesPerView: 'auto', 412 // pagination: { 413 // el: '.swiper-pagination', 414 // type: 'bullets', 415 // clickable: true 416 // }, 417 // /* 418 // navigation: { 419 // nextEl: '.inizia-home-slider-next', 420 // prevEl: '.inizia-home-slider-prev' 421 // }, 422 // */ 423 // navigation: true, 424 // breakpoints: { 425 // 320: { 426 // slidesPerView: 1, 427 // spaceBetween: 20 428 // }, 429 // 480: { 430 // slidesPerView: 1, 431 // spaceBetween: 20 432 // }, 433 // 640: { 434 // slidesPerView: 2, 435 // spaceBetween: 20 436 // }, 437 // 992: { 438 // slidesPerView: 6, 439 // spaceBetween: 0 440 // } 441 // } 442 // }); 443 444 /** 445 * Animation on scroll function and init 446 */ 447 448 449 450}); 451 452 453$(document).ready(function() { 454 $(window).on("resize", function(e) { 455 // checkScreenSize(); 456 }); 457 458 // checkScreenSize(); 459 460 function checkScreenSize() { 461 var newWindowWidth = $(window).width(); 462 if (newWindowWidth > 992) { 463 $(window).scroll(function() { 464 if ($(this).scrollTop() > 100) { 465 $('.header-top').hide(); 466 $('.header-bottom').css('padding-top', '0'); 467 $('.header-bottom').css('justify-content', 'flex-start'); 468 $('.header-bottom .bottone').hide(); 469 $('.logo-bottom').show(); 470 } else { 471 $('.header-top').show(); 472 $('.header-bottom').css('padding-top', '0'); 473 $('.header-bottom').css('justify-content', 'space-between'); 474 $('.header-bottom .bottone').show(); 475 $('.logo-bottom').hide(); 476 } 477 }); 478 479 } 480 } 481}); 482 483
484// NASCONDI SFONDO OPACO MENU 485$(document).mouseup(function(e) { 486 var containerMenu = $(".sidebar-menu"); 487 488 if (!containerMenu.is(e.target) && containerMenu.has(e.target).length === 0) { 489 containerMenu.animate({ "right": "-300px" }, "fast"); 490 $(".sidebar-menu-sfondo").hide(); 491 } 492}); 493 494 495// NASCONDI SFONDO OPACO MENU CARRELLO 496$(document).mouseup(function(e) { 497 var containerMenuCarrello = $(".menu-lat-carrello"); 498 var containerModalCarrello = $(".modal-menu-carrello"); 499 500 if (!containerMenuCarrello.is(e.target) && containerMenuCarrello.has(e.target).length === 0) { 501 if (!containerModalCarrello.is(e.target) && containerModalCarrello.has(e.target).length === 0) { 502 $(".menu-lat-carrello-sfondo").hide(); 503 $(".menu-lat-carrello").animate({ "right": "-320px" }, "fast"); 504 } 505 } 506}); 507 508$(document).ready(function() { 509 510 $("#menu-down").click(function() { 511 $("body").addClass("mobile-nav-active"); 512 }); 513 $("#menu-top-mobile").click(function() { 514 $("body").addClass("mobile-nav-active"); 515 516 }); 517 518 //MENU LATERALE DESKTOP APRI E CHIUDI 519 $("#chiudi-sidebar-menu").click(function() { 520 $(".sidebar-menu").animate({ "right": "-300px" }, "fast"); 521 $(".sidebar-menu-sfondo").hide(0); 522 }); 523 524 $("#apri-sidebar-menu").click(function() { 525 $(".sidebar-menu").animate({ "right": "0px" }); 526 $(".sidebar-menu-sfondo").show(0); 527 }); 528 529 // MENU LATERALE CARRELLO DESKTOP APRI E CHIUDI 530 $("#chiudi-menu-lat-carrello").click(function() { 531 $(".menu-lat-carrello").animate({ "right": "-300px" }, "fast"); 532 $(".menu-lat-carrello-sfondo").hide(0); 533 }); 534 535 $("#apri-menu-lat-carrello").click(function() { 536 $(".menu-lat-carrello").animate({ "right": "0px" }); 537 $(".menu-lat-carrello-sfondo").show(0); 538 }); 539 540 $(".sidebar-menu .bottone").hover(function() { 541 $(".sidebar-menu .bottone i").css("color", "#35c1b8"); 542 }, 543 function() { 544 $(".sidebar-menu .bottone i").css("color", "#FFF"); 545 }); 546 547 // MENU LATERALE CARRELLO HIDE AND SHOW MODIFICA E DETTAGLI CARRELLO 548 $("#modifica-ordine-menu-lat-carrello").click(function() { 549 $(".menu-lat-carrello .dettagli-carrello").hide(); 550 $(".menu-lat-carrello .modifica-carrello").show(); 551 }); 552 553 $("#conferma-modifica-ordine-menu-lat-carrello").click(function() { 554 $(".menu-lat-carrello .modifica-carrello").hide(); 555 $(".menu-lat-carrello .dettagli-carrello").show(); 556 }); 557 558 559 //CHIUDI E APRI FILTRI PRODOTTO 560 $("#chiudi-filtri").click(function() { 561 $("#nascondi-categoria, #ingrandisci-categoria").hide(); 562 $("#ingrandisci-categoria").toggleClass("col-lg-9 col-lg-12"); 563 $("#ingrandisci-categoria").fadeIn("fast"); 564 $("#apri-filtri").show(); 565 }); 566 567 $("#apri-filtri").click(function() { 568 $("#ingrandisci-categoria").toggleClass("col-lg-12 col-lg-9"); 569 $("#ingrandisci-categoria").fadeIn("fast"); 570 $("#nascondi-categoria").fadeIn("fast"); 571 $("#apri-filtri").hide(); 572 }); 573 574 // $('.btn-plus, .btn-minus').on('click', function(e) { 575 // const isNegative = $(e.target).closest('.btn-minus').is('.btn-minus'); 576 // const input = $(e.target).closest('.input-group').find('input'); 577 // if (input.is('input')) { 578 // input[0][isNegative ? 'stepDown' : 'stepUp']() 579 // } 580 // }); 581 582 583 584 585 586 587 relaodtags(); 588 589 590 591 592}); 593 594 595 596 597 598 599 600 601function reloadRoot() { 602 var menuFiltriCollezioni = $(".menu-filtri-collezioni"); 603 var closeMenuFiltriCollezioni = $(".menu-filtri-collezioni i"); 604 menuFiltriCollezioni.click(function() { 605 if ($(this).attr('data-state') === ('not-clicked')) { 606 menuFiltriCollezioni.parent("div").removeClass("col-lg-2 col-6 mb-4"); 607 menuFiltriCollezioni.hide(); 608 $(this).parent("div").addClass("col-lg-2 col-6 mb-4"); 609 $(this).show(); 610 $(this).children(closeMenuFiltriCollezioni).show(); 611 $(this).addClass("active"); 612 $(this).attr('data-state', 'clicked'); 613 } else { 614 menuFiltriCollezioni.parent("div").addClass("col-lg-2 col-6 mb-4"); 615 menuFiltriCollezioni.show(); 616 closeMenuFiltriCollezioni.hide(); 617 $(this).removeClass("active"); 618 $(this).attr('data-state', 'not-clicked'); 619 }; 620 setCategory(); 621 }); 622} 623 624 625function relaodtags() { 626
627 /*** NOSTRE COLLEZIONI ***/ 628 629 630 631 632 633 var etichetta = $(".nostre-collezioni .tag-collezioni .etichetta"); 634 635 etichetta.click(function() { 636 if ($(this).attr('data-state') === ('not-clicked')) { 637 $(this).addClass("active"); 638 $(this).attr('data-state', 'clicked'); 639 640 } else { 641 $(this).removeClass("active"); 642 $(this).attr('data-state', 'not-clicked'); 643 } 644 setTags() 645 }); 646 647 648} 649 650 651function mostra_altri_tags() { 652 let mostraAltri = $(".mostra-altri"); 653 let testoMostraAltri = $(".mostra-altri span"); 654 let tagNascosti = $(".nostre-collezioni .tag-collezioni"); 655 var tag_collezioni = document.getElementById('tag-collezioni') 656 657 if (tag_collezioni.classList.contains("display")) { 658 tag_collezioni.classList.remove("display") 659 testoMostraAltri.html("Mostra Altri"); 660 } else { 661 tag_collezioni.classList.add("display") 662 testoMostraAltri.html("Mostra Meno"); 663 664 }; 665} 666//RIMUOVI PREFERITI DALLA TABELLA 667$("#tabella-preferiti").on("click", ".rimuovi-preferito", function() { 668 $(this).closest("tr").remove(); 669}); 670 671 672 673//AGGIUNGI PRODOTTO AL CARRELLO 674$("#aggiungi-prodotto").click(function() { 675 $(".prodotto-aggiunto-carrello").animate({ "left": "20px" }); 676 setTimeout( 677 function() { 678 $(".prodotto-aggiunto-carrello").animate({ "left": "-300px" }); 679 }, 5000); 680}); 681 682 683 684//MOSTRA/NASCONDI CHIUSURA MENU MOBILE 685$("#menu-top-mobile, #menu-down").click(function() { 686 $(".mobile-nav-close").removeClass("d-none"); 687 $(".mobile-nav-close").addClass("d-block"); 688 $("#CookiebotWidget").addClass('d-none') 689}); 690 691 692$(".mobile-nav-close").click(function() { 693 $(".mobile-nav-close").removeClass("d-block"); 694 $(".mobile-nav-close").addClass("d-none"); 695 $("#CookiebotWidget").removeClass('d-none') 696}); 697 698$("#menu-top-mobile, #menu-down").click(function() { 699 $(".mobile-nav-close, .chiudi-nav-close").removeClass("d-none"); 700 $(".mobile-nav-close, .chiudi-nav-close").addClass("d-block"); 701 702}); 703 704 705$(".chiudi-nav-close").click(function() { 706 $(".chiudi-nav-close").removeClass("d-block"); 707 $(".chiudi-nav-close").addClass("d-none"); 708 709 if ($('.mobile-nav-close').css('display') === 'block') { 710 $(".mobile-nav-close").removeClass("d-block"); 711 $(".mobile-nav-close").addClass("d-none"); 712 } 713 714}); 715 716 717$(".input_el").change(function() { 718 var els = document.getElementsByClassName('input_el') 719 var a = true; 720 var addact = document.getElementById('aggiungi-action') 721 722 if (addact) { 723 for (var m = 0; m < els.length; m++) { 724 725 if (els[m].value == "") { 726 addact.setAttribute('disabled', true) 727 a = false; 728 } 729 } 730 if (a) { 731 addact.removeAttribute('disabled') 732 } 733 734 } 735 736 737}) 738 739 740 741$("#login").click(function() { 742 var form_ = document.getElementById('form-login'); 743 744 var e = document.getElementById('f-email').value 745 var p = document.getElementById('f-pass').value 746 747 var validRegex = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/; 748 var al = document.getElementById('f-l-e'); 749 if (e.match(validRegex)) { 750 if (al) { 751 al.setAttribute('class', 'd-none'); 752 } 753 } else { 754 if (al) { 755 al.setAttribute('class', ''); 756 } else { 757 alert('Email non valida'); 758 } 759 return '' 760 } 761 var al = document.getElementById('f-l-p'); 762 if (p.length == 0) { 763 if (al) { 764 al.setAttribute('class', ''); 765 } else { 766 alert('Campo Password non può essere vuoto'); 767 } 768 return '' 769 } else { 770 if (al) { 771 al.setAttribute('class', 'd-none'); 772 } 773 } 774 775 var c = {}; 776 var values = { 777 api: true, 778 act: 'login', 779 email: e, 780 password: p 781 }; 782 783 var req = $.ajax({ 784 url: "index.php", 785 type: "post", 786 data: values, 787 async: true, 788 success: function(response) { 789 790 c = response 791 if (c['status'] == false) { 792 alertBlock('alert-login', c['message']) 793 } else { 794 if (window.location.href.indexOf("checkout") != -1) { 795 window.location.href = 'https://' + window.location.hostname + '/checkout'; 796 } else if (window.location.href.indexOf("registrati") != -1) { 797 window.location.href = 'https://' + window.location.hostname + ''; 798 } else { 799 window.location.href = 'https://' + window.location.hostname + '/'; 800 } 801 } 802 }, 803 error: function(jqXHR, textStatus, errorThrown) { 804 console.log(textStatus, errorThrown); 805 return true 806 } 807 808 }); 809 return c; 810 811}); 812 813function fb_statusChangeCack(response) { 814 if (response.status === 'connected') { 815 fb_testAPI(); 816 } else { 817 console.info('Please log into this webpage.'); 818 } 819} 820 821$("#btn_social_login_facebook").on("click", function() { 822 var a = FB.init({ 823 appId: '415513137554863', 824 cookie: false, 825 xfbml: true, 826 version: 'v19.0', 827 }); 828 FB.getLoginStatus(function(response) {}); 829 FB.login(function(response) { 830 831 if (response.authResponse) { 832 833 FB.api('/me', { fields: 'name, email' }, function(response_el) { 834 response['email'] = response_el.email 835 socialLogin(response) 836 }); 837 } else {
838 console.log("LOGIN_FAIL - L'utente ha annullato il login o non è stato autorizzato completamente."); 839 } 840 }, { 841 scope: 'public_profile,email' 842 }); 843}); 844 845function get_state() { 846 const chrs = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; 847 var state = ''; 848 for (i = 0; i < 32; i++) { 849 state += chrs.charAt((Math.random() * (chrs.length - 1))); 850 } 851 return state; 852} 853$("#btn_social_login_google").on("click", function() { 854 855 const state = get_state(); 856 const gclient_token = google.accounts.oauth2.initTokenClient({ 857 client_id: "65881001427-aslds2aj9n2s4tvnjhugo1d55sat33mi.apps.googleusercontent.com", 858 state: state, 859 scope: 'email profile https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email', //openid 860 error_callback: (response) => { 861 console.log("ERROR_CALLBACK - response:", response); 862 }, 863 callback: (response) => { 864 console.log("CALLBACK - response:", response); 865 866 if (response && response.access_token) { 867 if (google.accounts.oauth2.hasGrantedAllScopes(response, 'email', 'profile')) { 868 var xhr = new XMLHttpRequest(); 869 xhr.open('GET', 'https://www.googleapis.com/oauth2/v1/userinfo?access_token='
869+ response.access_token); 870 xhr.setRequestHeader('Authorization', 'Bearer ' + response.access_token); 871 xhr.responseType = "json"; 872 xhr.onload = () => { 873 alertBlock('alert-login', 'Login OK<br>Nome: ' + xhr.response.given_name + '<br>Cognome: ' + xhr.response.family_name + '<br>Email: ' + xhr.response.email); 874 socialLogin(xhr.response) 875 } 876 xhr.send(); 877 } else { 878 console.warn("NO - hasGrantedAllScopes"); 879 } 880 } else { 881 console.warn("NO - response OR access_token"); 882 } 883 } 884 }).requestAccessToken(); 885}); 886 887$("#btn_social_login_paypal").on("click", function() {}); 888$("#btn_social_login_apple").on("click", function() { 889 890}); 891 892function alertBlock(id, msg, color = 'warning') { 893 var a = document.getElementById(id) 894 a.innerHTML = '<div class="alert alert-' + color + '" role="alert">' + msg + '</div>' 895 animazioneAlert(id) 896} 897 898function animazioneAlert(id) { 899 $("#" + id + "").animate({ 900 "left": "50%" 901 }); 902 setTimeout(function() { 903 $("#" + id + "").animate({ 904 "left": "-1000px" 905 }); 906 }, 3000); 907 908} 909 910function switch_fatturazione() { 911 912 var tipo = document.getElementById('fatturazione_elettronica') 913 var e = document.getElementById('fatturazione_elettronica-result'); 914 915 if (tipo.value == "") { 916 var h = "" 917 } 918 if (tipo.value == "SDI") { 919 920 var h = `<label for="#">Codice SDI*</label> 921 <input type="text" class="form-control campo-form" id="codice_univoco" required="" name="codice_univoco" value="" onchange="check_field(this)"> 922 <small id="alert-codice_univoco"></small>`; 923 } 924 if (tipo.value == "PEC") { 925 var h = `<label for="#">Indirizzo PEC*</label> 926 <input type="text" class="form-control campo-form" id="pec" required="" name="pec" value="" onchange="check_field(this)"> 927 <small id="alert-pec"></small>`; 928 } 929 e.innerHTML = h 930 931 932} 933 934 935function get_lista_indirizzi() { 936 var c = {}; 937 var values = { 938 api: true, 939 act: 'get_lista_indirizzi' 940 }; 941 942 var req = $.ajax({ 943 url: "index.php", 944 type: "post", 945 data: values, 946 async: false, 947 success: function(response) { 948 c = response 949 }, 950 error: function(jqXHR, textStatus, errorThrown) { 951 console.log(textStatus, errorThrown); 952 return true 953 } 954 }); 955 return c; 956} 957 958 959function get_lista_indirizzi_spedizione() { 960 var c = {}; 961 var values = { 962 api: true, 963 act: 'get_lista_indirizzi_spedizione' 964 }; 965 966 var req = $.ajax({ 967 url: "index.php", 968 type: "post", 969 data: values, 970 async: false, 971 success: function(response) { 972 c = response 973 }, 974 error: function(jqXHR, textStatus, errorThrown) { 975 console.log(textStatus, errorThrown); 976 return true 977 } 978 }); 979 return c; 980} 981 982 983 984 985function display_label(id) { 986 var inp = document.getElementById(id); 987 var lab = document.getElementById('label_' + id); 988 if (document.activeElement == inp) { 989 lab.classList.add('active_label'); 990 inp.classList.add('active_input'); 991 } else { 992 if (inp.value == '') { 993 lab.classList.remove('active_label'); 994 } 995 inp.classList.remove('active_input'); 996 } 997} 998 999function hashEmail(email) { 1000 // Encode the email address as a Uint8Array 1001 const encoder = new TextEncoder(); 1002 const data = encoder.encode(email); 1003 1004 // Hash the data using SHA-256 and return a Promise that resolves with the hash 1005 return crypto.subtle.digest('SHA-256', data).then(hashBuffer => { 1006 // Convert the buffer to a hexadecimal string 1007 const hashArray = Array.from(new Uint8Array(hashBuffer)); 1008 const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); 1009 sessionStorage.setItem('user', hashHex) 1010 return hashHex; 1011 }); 1012} 1013 1014 1015function socialLogin(object) { 1016 1017 const fd = new FormData(); 1018 fd.append("api", true); 1019 fd.append("act", "access_form"); 1020 fd.append("data[social]", true); 1021 fd.append("data[response]", JSON.stringify(object)); 1022 var request = $.ajax({ 1023 url: 'index.php', 1024 type: 'POST', 1025 data: fd, 1026 contentType: false, 1027 processData: false 1028 }); 1029 1030 request.done(function(response) { 1031 if (response['status'] == true) { 1032 var hae = hashEmail(response['user']['email']) 1033 window.location.href = 'https://' + window.location.hostname + '' 1034 } else { 1035 alertBlock('alert-login', response['message']) 1036 } 1037 }) 1038 request.fail(function(jqXHR, textStatus) { 1039 console.log(textStatus, errorThrown); 1040 return true 1041 }) 1042} 1043 1044function checkCampi() { 1045 var lock = false 1046 var aggiungiaction = document.getElementById('aggiungi-action') 1047 var aggiungiaction_sped = document.getElementById('action-spedizione') 1048 var aggiungiaction_fatt = document.getElementById('action-fatturazione') 1049 var found = {} 1050 var cc = document.getElementsByClassName('check-campo') 1051 for (let index = 0; index < cc.length; index++) { 1052 const element = cc[index];
1053 found[element.id] = element.value 1054 if (element.value == "") { 1055 console.log(element.id) 1056 console.log(element.value) 1057 lock = true 1058 } 1059 } 1060 1061 if (aggiungiaction) { 1062 console.log('old') 1063 if (lock == true) { 1064 aggiungiaction.classList.add('disabled') 1065 } else { 1066 aggiungiaction.classList.remove('disabled') 1067 } 1068 } 1069 if (aggiungiaction_sped) { 1070 console.log('sped') 1071 console.log(found) 1072 if (lock == true) { 1073 aggiungiaction_sped.classList.add('disabled') 1074 aggiungiaction_sped.disabled = true 1075 aggiungiaction_sped.setAttribute('onclick', "aggiungi_indirizzo('spedizione')") 1076 } else { 1077 aggiungiaction_sped.classList.remove('disabled') 1078 aggiungiaction_sped.disabled = false 1079 aggiungiaction_sped.setAttribute('onclick', "add_address_new(1)") 1080 } 1081 } 1082 if (aggiungiaction_fatt) { 1083 console.log('fatt') 1084 console.log(found) 1085 if (lock == true) { 1086 aggiungiaction_fatt.classList.add('disabled') 1087 aggiungiaction_fatt.disabled = true 1088 aggiungiaction_fatt.setAttribute('onclick', "aggiungi_indirizzo('fatturazione')") 1089 } else { 1090 aggiungiaction_fatt.classList.remove('disabled') 1091 aggiungiaction_fatt.disabled = false 1092 aggiungiaction_fatt.setAttribute('onclick', "add_address_new(2)") 1093 1094 } 1095 } 1096 1097 1098 1099 1100 1101 1102} 1103 1104function open_add_address(type = 1) { 1105 1106 var c = document.getElementById('add-nuovo'); 1107 c.style.display = 'block'; 1108 autocomplete2('add-nazione', ['Italia']); 1109 var aggiungiaction = document.getElementById('aggiungi-action') 1110 aggiungiaction.classList.add('disabled') 1111 1112 var b = document.getElementById('aggiungi-action'); 1113 b.setAttribute('onclick', 'add_address(' + type + ')') 1114 1115 var a = document.getElementById('annulla-action'); 1116 a.style.display = 'inline-block'; 1117 1118 autocomplete2('add-provincia', getProvincie('Italia')) 1119 var p = document.getElementById('add-provincia') 1120 p.removeAttribute('disabled'); 1121 1122 if (type == 1) { 1123 document.getElementById('label_add-destinatario').innerHTML = 'Destinatario' 1124 document.getElementById('riga-piva').classList.add('d-none') 1125 } else { 1126 document.getElementById('label_add-destinatario').innerHTML = 'Nome azienda' 1127 document.getElementById('riga-piva').classList.remove('d-none') 1128 } 1129 1130 1131 1132} 1133 1134function close_add_address() { 1135 var c = document.getElementById('add-nuovo'); 1136 c.style.display = 'none'; 1137 var b = document.getElementById('aggiungi-action'); 1138 b.setAttribute('onclick', 'open_add_address()') 1139 var a = document.getElementById('annulla-action'); 1140 a.style.display = 'none'; 1141 var p = document.getElementById('add-provincia') 1142 var co = document.getElementById('add-comune') 1143 p.setAttribute('disabled', 'disabled'); 1144 co.setAttribute('disabled', 'disabled'); 1145 1146 var els = document.getElementsByClassName('input_el') 1147 var a = true; 1148 for (var m = 0; m < els.length; m++) { 1149 els[m].value = ""; 1150 } 1151 $('#modal-cassa-loggato').modal('hide') 1152} 1153 1154 1155 1156 1157function getProvincie() { 1158 1159 var prov = [ 1160 "AG", 1161 "AL", 1162 "AN", 1163 "AO", 1164 "AP", 1165 "AQ", 1166 "AR", 1167 "AT", 1168 "AV", 1169 "BA", 1170 "BG", 1171 "BI", 1172 "BL", 1173 "BN", 1174 "BO", 1175 "BR", 1176 "BS", 1177 "BT", 1178 "BZ", 1179 "CA", 1180 "CB", 1181 "CE", 1182 "CH", 1183 "CL", 1184 "CN", 1185 "CO", 1186 "CR", 1187 "CS", 1188 "CT", 1189 "CZ", 1190 "EN", 1191 "FC", 1192 "FE", 1193 "FG", 1194 "FI", 1195 "FM", 1196 "FR", 1197 "GE", 1198 "GO", 1199 "GR", 1200 "IM", 1201 "IS", 1202 "KR", 1203 "LC", 1204 "LE", 1205 "LI", 1206 "LO", 1207 "LT", 1208 "LU", 1209 "MB", 1210 "MC", 1211 "ME", 1212 "MI", 1213 "MN", 1214 "MO", 1215 "MS", 1216 "MT", 1217 "NA", 1218 "NO", 1219 "NU", 1220 "OR", 1221 "PA", 1222 "PC", 1223 "PD", 1224 "PE", 1225 "PG", 1226 "PI", 1227 "PN", 1228 "PO", 1229 "PR", 1230 "PT", 1231 "PU", 1232 "PV", 1233 "PZ", 1234 "RA", 1235 "RC", 1236 "RE", 1237 "RG", 1238 "RI", 1239 "RM", 1240 "RN", 1241 "RO", 1242 "SA", 1243 "SI", 1244 "SO", 1245 "SP", 1246 "SR", 1247 "SS", 1248 "SU", 1249 "SV", 1250 "TA", 1251 "TE", 1252 "TN", 1253 "TO", 1254 "TP", 1255 "TR", 1256 "TS", 1257 "TV", 1258 "UD", 1259 "VA", 1260 "VB", 1261 "VC", 1262 "VE", 1263 "VI", 1264 "VR", 1265 "VT", 1266 "VV" 1267 ]; 1268 1269 return prov; 1270} 1271 1272function getComuni(pr) { 1273 1274 var c = {}; 1275 var values = { 1276 api: true, 1277 act: 'get_comuni', 1278 provincia: pr 1279 }; 1280 1281 var req = $.ajax({ 1282 url: "index.php", 1283 type: "post", 1284 data: values, 1285 async: false, 1286 success: function(response) { 1287 if (response.hasOwnProperty('data')) { 1288 c = response['data']; 1289 } 1290 }, 1291 error: function(jqXHR, textStatus, errorThrown) { 1292 console.log(textStatus, errorThrown); 1293 return true 1294 } 1295 1296 }); 1297 return c; 1298} 1299 1300function setProvincie(pr) { 1301 1302} 1303 1304function setComuni() { 1305 sleep(700).then(() => { 1306 var p = document.getElementById('add-provincia') 1307 autocomplete2('add-comune', getComuni(p.value)) 1308 var c = document.getElementById('add-comune') 1309 c.removeAttribute('disabled'); 1310 }); 1311 1312 1313} 1314 1315 1316function scegli_indirizzo(id) { 1317 1318 var c = {}; 1319 var info = { 1320 'is_predefinito': 1, 1321 'id': id 1322 } 1323 info = JSON.stringify(info); 1324 var values = { 1325 api: true, 1326 act: 'update_indirizzo', 1327 data: info 1328 }; 1329 1330 var req = $.ajax({ 1331 url: "index.php", 1332 type: "post", 1333 data: values, 1334 async: false, 1335 success: function(response) { 1336 1337 if (response.hasOwnProperty('status')) { 1338 window.location.href = window.location.href 1339 } 1340 }, 1341 error: function(jqXHR, textStatus, errorThrown) { 1342 console.log(textStatus, errorThrown); 1343 return true 1344 } 1345 1346 }); 1347 return c; 1348 1349 1350 1351} 1352 1353 1354 1355function verificaCampo(el) { 1356 var container = document.getElementById('edit-' + el.getAttribute('name')); 1357 1358 if (el.value === "") { 1359 container.classList.add('error'); 1360 var esisteErrore = document.getElementById('error-' + el.getAttribute('name')); 1361 1362 document.getElementById('action-button').classList.add('disabled') 1363 if (!esisteErrore) { 1364 var nuovoError = document.createElement('small'); 1365 nuovoError.setAttribute('id', 'error-' + el.getAttribute('name')); 1366 nuovoError.textContent = 'Il campo non può essere vuoto'; 1367 nuovoError.classList.add('error') 1368 el.insertAdjacentElement('afterend', nuovoError); 1369 } 1370 1371 } else { 1372 document.getElementById('action-button').classList.remove('disabled') 1373 container.classList.remove('error'); 1374 var er = document.getElementById('error-' + el.getAttribute('name')); 1375 if (er) { 1376 er.remove(); 1377 } 1378 } 1379 1380 1381 1382 1383 1384 1385} 1386 1387function add_address_new(tipo) { 1388 1389 var add_destinatario = document.getElementById('add-destinatario').value; 1390 var comune = document.getElementById('add-comune').value 1391 var indirizzo = document.getElementById('add-indirizzo').value 1392 var provincia = document.getElementById('add-provincia').value 1393 var cap = document.getElementById('add-cap').value 1394 var nazione = document.getElementById('add-nazione').value 1395 var telefono = document.getElementById('add-telefono').value 1396 var piva = document.getElementById('add-partita_iva').value 1397 var sdi = document.getElementById('add-sdi_pec').value 1398 1399 if (add_destinatario == "" || comune == "" || indirizzo == "" || provincia == "" || nazione == "" || telefono == "" || cap == "") { 1400 return 1401 } 1402 1403 if (nazione == 'Italia') { 1404 nazione = 'IT'; 1405 } 1406 1407 1408 1409 var c = {}; 1410 var info = { 1411 'destinatario': add_destinatario, 1412 'comune': comune, 1413 'indirizzo': indirizzo, 1414 'provincia': provincia, 1415 'partita_iva': piva, 1416 'sdi_pec': sdi, 1417 'cap': cap, 1418 'nazione': nazione, 1419 'telefono': telefono, 1420 'tipo': tipo, 1421 'is_predefinito': 1 1422 } 1423 console.log(info) 1424 info = JSON.stringify(info); 1425 var values = { 1426 api: true, 1427 act: 'add_indirizzo', 1428 data: info 1429 }; 1430 1431 var req = $.ajax({ 1432 url: "index.php", 1433 type: "post", 1434 data: values, 1435 async: false, 1436 success: function(response) { 1437 1438 if (response.hasOwnProperty('status')) { 1439 if (response['status'] == true) { 1440 window.location.href = window.location.href 1441 } 1442 } 1443 }, 1444 error: function(jqXHR, textStatus, errorThrown) { 1445 console.log(textStatus, errorThrown); 1446 return true 1447 } 1448 1449 }); 1450 return c; 1451 1452 1453 1454} 1455 1456function add_address(tipo) { 1457 1458 var aggiungiaction = document.getElementById('aggiungi-action') 1459 aggiungiaction.classList.add('disabled') 1460 1461 var add_destinatario = document.getElementById('add-destinatario').value; 1462 var add_co = document.getElementById('add-co').value; 1463 var comune = document.getElementById('add-comune').value 1464 var indirizzo = document.getElementById('add-indirizzo').value 1465 var provincia = document.getElementById('add-provincia').value 1466 var cap = document.getElementById('add-cap').value 1467 var nazione = document.getElementById('add-nazione').value 1468 var telefono = document.getElementById('add-telefono').value 1469 1470 1471 if (add_destinatario == "" || comune == "" || indirizzo == "" || provincia == "" || nazione == "" || telefono == "" || cap == "") { 1472 return 1473 } 1474 if (nazione == 'Italia') { 1475 nazione = 'IT'; 1476 } 1477 1478 if (add_co != "") { 1479 add_destinatario += ' (' + add_co + ')' 1480 } 1481 var c = {}; 1482 var info = { 1483 'destinatario': add_destinatario, 1484 'comune': comune, 1485 'indirizzo': indirizzo, 1486 'provincia': provincia, 1487 'cap': cap, 1488 'nazione': nazione, 1489 'telefono': telefono, 1490 'tipo': tipo, 1491 'is_predefinito': 1 1492 } 1493 info = JSON.stringify(info); 1494 var values = { 1495 api: true, 1496 act: 'add_indirizzo', 1497 data: info 1498 }; 1499 1500 var req = $.ajax({ 1501 url: "index.php", 1502 type: "post", 1503 data: values, 1504 async: false, 1505 success: function(response) { 1506 1507 if (response.hasOwnProperty('status')) { 1508 if (response['status'] == true) { 1509 close_add_address(); 1510 get_address(tipo); 1511 } else { 1512 1513 } 1514 1515 } 1516 }, 1517 error: function(jqXHR, textStatus, errorThrown) { 1518 console.log(textStatus, errorThrown); 1519 return true 1520 } 1521 1522 }); 1523 return c; 1524 1525 1526 1527} 1528 1529 1530 1531 1532 1533 1534function highL(lista, val) { 1535 1536 if (val.length < 3) { 1537 if (val.length < 3) { 1538 var l = document.getElementById('cercaautocomplete-list'); 1539 if (l) { 1540 l.remove(); 1541 } 1542 return 1543 } 1544 return 1545 } 1546 var a, b, i, val = val; 1547 /*close any already open lists of autocompleted values*/ 1548 closeAllLists(); 1549 if (!val) { return false; } 1550 currentFocus = -1; 1551 /*create a DIV element that will contain the items (values):*/ 1552 a = document.createElement("DIV"); 1553 a.setAttribute("id", "cercaautocomplete-list"); 1554 a.setAttribute("class", "autocomplete-items cerca"); 1555 /*append the DIV element as a child of the autocomplete container:*/ 1556 var inp = document.getElementById('cerca'); 1557 inp.parentNode.appendChild(a); 1558 /*for each item in the array...*/ 1559 var one = false;
1560 var le = lista.length; 1561 if (le > 15) { 1562 le = 15; 1563 } 1564 for (i = 0; i < lista.length; i++) { 1565 /*check if the item starts with the same letters as the text field value:*/ 1566 parola = lista[i]['key'] 1567 desc = lista[i]['desc'] 1568 1569 if (parola.substr(0, val.length).toUpperCase() == val.toUpperCase()) { 1570 one = true; 1571 /*create a DIV element for each matching element:*/ 1572 b = document.createElement("DIV"); 1573 b.classList.add('item'); 1574 /*make the matching letters bold:*/ 1575 b.innerHTML = "<strong>" + parola.substr(0, val.length) + "</strong>"; 1576 b.innerHTML += parola.substr(val.length) + ''; 1577 b.innerHTML += "<input class='hidden_in' type='hidden' value=\"" + parola + "\">"; 1578 b.innerHTML += '<span style="">' + desc + '</span>'; 1579 1580 /*insert a input field that will hold the current array item's value:*/ 1581 1582 /*execute a function when someone clicks on the item value (DIV element):*/ 1583 b.addEventListener("click", function(e) { 1584 1585 /*insert the value for the autocomplete text field:*/ 1586 1587 inp.value = this.getElementsByTagName("input")[0].value; 1588 inp.setAttribute('value', inp.value) 1589 1590 var u = 'https://' + window.location.hostname + '/ricerca?s=' + inp.value + '&c_id=0&category=tutti' 1591 window.location.href = u 1592 /*close the list of autocompleted values, 1593 (or any other open lists of autocompleted values:*/ 1594 closeAllLists(); 1595 }); 1596 a.appendChild(b); 1597 } 1598 } 1599 1600 1601 if (one == false) { 1602 b = document.createElement("DIV"); 1603 /*make the matching letters bold:*/ 1604 b.innerHTML = "Nessun risultato"; 1605 a.appendChild(b); 1606 } else { 1607 var a = document.getElementById('cercaautocomplete-list') 1608 b = document.createElement("DIV"); 1609 b.classList.add('link'); 1610 /*make the matching letters bold:*/ 1611 b.innerHTML = '<a href="https://' + window.location.hostname + '/ricerca?s=' + val + '&c_id=0&category=tutti">Cerca <i class="bi bi-arrow-right"></i></a>'; 1612 a.appendChild(b); 1613 } 1614} 1615 1616 1617function cerca(lista) { 1618 var inp = document.getElementById('cerca'); 1619 inp.removeEventListener("input", function(e) {}) 1620 /*the autocomplete function takes two arguments, 1621 the text field element and an array of possible autocompleted values:*/ 1622 var currentFocus; 1623 /*execute a function when someone writes in the text field:*/ 1624 inp.addEventListener("input", function(e) { 1625 1626 highL(lista, this.value); 1627 1628 }); 1629 1630 1631 /*execute a function when someone clicks in the document:*/ 1632 document.addEventListener("click", function(e) { 1633 closeAllLists(e.target); 1634 }); 1635 1636 1637} 1638 1639function closeAllLists(elmnt) { 1640 /*close all autocomplete lists in the document, 1641 except the one passed as an argument:*/ 1642 var inp = document.getElementById('cerca') 1643 var x = document.getElementsByClassName("autocomplete-items"); 1644 for (var i = 0; i < x.length; i++) { 1645 if (elmnt != x[i] && elmnt != inp) { 1646 x[i].parentNode.removeChild(x[i]); 1647 } 1648 } 1649} 1650 1651 1652function autocomplete2(id, arr, set_founded = false) { 1653 var inp = document.getElementById(id); 1654 if (set_founded == true) { 1655 inp.setAttribute('data-founded', 0) 1656 try { 1657 document.getElementById('action-button-add').removeAttribute('disabled'); 1658 document.getElementById('action-button-add').classList.remove('disabled') 1659 } catch (error) { 1660 1661 } 1662 } 1663 /*the autocomplete function takes two arguments, 1664 the text field element and an array of possible autocompleted values:*/ 1665 var currentFocus; 1666 /*execute a function when someone writes in the text field:*/ 1667 inp.addEventListener("input", function(e) { 1668 var a, b, i, val = this.value; 1669 /*close any already open lists of autocompleted values*/ 1670 closeAllLists(); 1671 if (!val) { return false; } 1672 currentFocus = -1; 1673 /*create a DIV element that will contain the items (values):*/ 1674 a = document.createElement("DIV"); 1675 a.setAttribute("id", this.id + "autocomplete-list"); 1676 a.setAttribute("class", "autocomplete-items"); 1677 /*append the DIV element as a child of the autocomplete container:*/ 1678 this.parentNode.appendChild(a); 1679 /*for each item in the array...*/ 1680 var one = false;
1681 for (i = 0; i < arr.length; i++) { 1682 1683 /*check if the item starts with the same letters as the text field value:*/ 1684 if (arr[i].substr(0, val.length).toUpperCase() == val.toUpperCase()) { 1685 one = true; 1686 if (set_founded == true && arr.length == 1) { 1687 inp.setAttribute('data-founded', 1) 1688 } else { 1689 inp.setAttribute('data-founded', 0) 1690 } 1691 /*create a DIV element for each matching element:*/ 1692 b = document.createElement("DIV"); 1693 /*make the matching letters bold:*/ 1694 b.innerHTML = "<strong>" + arr[i].substr(0, val.length) + "</strong>"; 1695 b.innerHTML += arr[i].substr(val.length); 1696 /*insert a input field that will hold the current array item's value:*/ 1697 b.innerHTML += "<input class='hidden_in' type='hidden' value=\"" + arr[i] + "\">"; 1698 /*execute a function when someone clicks on the item value (DIV element):*/ 1699 b.addEventListener("click", function(e) { 1700 1701 /*insert the value for the autocomplete text field:*/ 1702 1703 inp.value = this.getElementsByTagName("input")[0].value; 1704 inp.setAttribute('data-founded', 1) 1705 try { 1706 document.getElementById('action-button-add').removeAttribute('disabled'); 1707 document.getElementById('action-button-add').classList.remove('disabled') 1708 } catch (error) { 1709 1710 } 1711 inp.setAttribute('value', this.getElementsByTagName("input")[0].value) 1712 /*close the list of autocompleted values, 1713 (or any other open lists of autocompleted values:*/ 1714 closeAllLists(); 1715 }); 1716 a.appendChild(b); 1717 } 1718 } 1719 if (one == false) { 1720 b = document.createElement("DIV"); 1721 /*make the matching letters bold:*/ 1722 if (set_founded == true) { 1723 inp.setAttribute('data-founded', 0) 1724 try { 1725 document.getElementById('action-button-add').removeAttribute('disabled'); 1726 document.getElementById('action-button-add').classList.remove('disabled') 1727 } catch (error) { 1728 1729 } 1730 } 1731 b.innerHTML = "Nessun risultato"; 1732 a.appendChild(b); 1733 } 1734 1735 }); 1736 /*execute a function presses a key on the keyboard:*/ 1737 inp.addEventListener("keydown", function(e) { 1738 if (set_founded == true) { 1739 inp.setAttribute('founded', 0) 1740 } 1741 var x = document.getElementById(this.id + "autocomplete-list"); 1742 if (x) x = x.getElementsByTagName("div"); 1743 if (e.keyCode == 40) { 1744 /*If the arrow DOWN key is pressed, 1745 increase the currentFocus variable:*/ 1746 currentFocus++; 1747 /*and and make the current item more visible:*/ 1748 addActive(x); 1749 } else if (e.keyCode == 38) { //up 1750 /*If the arrow UP key is pressed, 1751 decrease the currentFocus variable:*/ 1752 currentFocus--; 1753 /*and and make the current item more visible:*/ 1754 addActive(x); 1755 } else if (e.keyCode == 13) { 1756 /*If the ENTER key is pressed, prevent the form from being submitted,*/ 1757 e.preventDefault(); 1758 if (currentFocus > -1) { 1759 /*and simulate a click on the "active" item:*/ 1760 if (x) x[currentFocus].click(); 1761 } 1762 } 1763 }); 1764 1765 function addActive(x) { 1766 /*a function to classify an item as "active":*/ 1767 if (!x) return false; 1768 /*start by removing the "active" class on all items:*/ 1769 removeActive(x); 1770 if (currentFocus >= x.length) currentFocus = 0; 1771 if (currentFocus < 0) currentFocus = (x.length - 1); 1772 /*add class "autocomplete-active":*/ 1773 x[currentFocus].classList.add("autocomplete-active"); 1774 } 1775 1776 function removeActive(x) { 1777 /*a function to remove the "active" class from all autocomplete items:*/ 1778 for (var i = 0; i < x.length; i++) { 1779 x[i].classList.remove("autocomplete-active"); 1780 } 1781 } 1782 1783 function closeAllLists(elmnt) { 1784 /*close all autocomplete lists in the document, 1785 except the one passed as an argument:*/ 1786 var x = document.getElementsByClassName("autocomplete-items"); 1787 for (var i = 0; i < x.length; i++) { 1788 if (elmnt != x[i] && elmnt != inp) { 1789 x[i].parentNode.removeChild(x[i]); 1790 } 1791 } 1792 } 1793 /*execute a function when someone clicks in the document:*/ 1794 document.addEventListener("click", function(e) { 1795 closeAllLists(e.target); 1796 }); 1797 1798} 1799 1800 1801function account_logout() { 1802 1803 var values = { 1804 api: true, 1805 act: 'logout', 1806 }; 1807 1808 var req = $.ajax({ 1809 url: "index.php", 1810 type: "post", 1811 data: values, 1812 async: false, 1813 success: function(response) { 1814 1815 window.location.href = 'https://' + window.location.hostname 1816 }, 1817 error: function(jqXHR, textStatus, errorThrown) { 1818 console.log(textStatus, errorThrown); 1819 return true 1820 } 1821 1822 }); 1823 return c; 1824} 1825 1826 1827function get_ordine(id) { 1828 1829 var values = { 1830 api: true, 1831 act: 'get_ordine', 1832 id: id 1833 }; 1834 var c = false;
1835 var request = $.ajax({ 1836 url: "index.php", 1837 type: "post", 1838 data: values, 1839 async: false 1840 }); 1841 request.done(function(response) { 1842 c = response 1843 }) 1844 request.fail(function(jqXHR, textStatus) { 1845 console.log("Request failed: " + textStatus); 1846 }) 1847 1848 return c; 1849} 1850 1851 1852function dismiss_modal(id) { 1853 $('#' + id).modal('hide'); 1854} 1855 1856 1857function replaceAll(string, search, replace) { 1858 return string.split(search).join(replace); 1859} 1860 1861 1862function capitalizeWords(str) { 1863 return str 1864 .toLowerCase() 1865 .split(' ') 1866 .map((word) => word.charAt(0).toUpperCase() + word.slice(1)) 1867 .join(' '); 1868} 1869 1870 1871 1872 1873function runSlide(id, max = 5) { 1874 /** 1875 * Scelti Home Slider 1876 */ 1877 1878 1879 1880 new Swiper('#' + id, { 1881 speed: 600, 1882 loop: false, 1883 autoplay: false, 1884 slidesPerView: 'auto', 1885 pagination: { 1886 el: '.swiper-pagination', 1887 type: 'bullets', 1888 clickable: true 1889 }, 1890 navigation: { 1891 nextEl: '.scelti-home-slider-next', 1892 prevEl: '.scelti-home-slider-prev' 1893 }, 1894 breakpoints: { 1895 320: { 1896 slidesPerView: 2, 1897 spaceBetween: 20 1898 }, 1899 480: { 1900 slidesPerView: 2, 1901 spaceBetween: 20 1902 }, 1903 640: { 1904 slidesPerView: 3, 1905 spaceBetween: 20 1906 }, 1907 992: { 1908 slidesPerView: max, 1909 spaceBetween: 0 1910 } 1911 } 1912 }); 1913 1914 1915} 1916var NON_DEFINITO = 'Non definito'; 1917var ATTESA_DI_PAGAMENTO = 'In attesa di pagamento'; 1918var RICEVUTO = 'Pagamento ricevuto'; 1919var DA_RIMBORSARE = 'Da rimborsare'; 1920var RIMBORSATO = 'Rimborsato'; 1921var APPROVATO = 'Approvato'; 1922var FAIL = 'Non approvato'; 1923 1924 1925 1926/**** 1927AGGIUNTE 26/02 1928***/ 1929 1930 1931$(document).ready(function() { 1932 1933 function ricaricaPagina() { 1934 1935 var newWindowWidth = $(window).width(); 1936 1937 //ACCORDION FOOTER MOBILE 1938 if (newWindowWidth < 992) { 1939 1940 let avviaAccordion = $(".bordo-footer-mobile .trigger-accordion"); 1941 let accordions = $(".footer .accordion-mobile"); 1942 let accordionCliccata; 1943 1944 avviaAccordion.click(function() { 1945 let pulsantePremuto = $(this); 1946 accordions.each(function() { 1947 if (accordions.siblings().children("i").hasClass("bi-chevron-up")) { 1948 accordions.siblings().children("i").removeClass("bi-chevron-up"); 1949 accordions.siblings().children("i").addClass("bi-chevron-down"); 1950 } 1951 // $(this).hide(); 1952 }); 1953 if ($(this).next().prop('id') !== $(accordionCliccata).prop('id')) { 1954 accordionCliccata = $(this).next(); 1955 // accordionCliccata.show(); 1956 accordionCliccata.addClass("active"); // Aggiunta della classe qui 1957 pulsantePremuto.children("i").removeClass("bi-chevron-down"); 1958 pulsantePremuto.children("i").addClass("bi-chevron-up"); 1959 } else { 1960 accordionCliccata.removeClass("active"); // Rimozione della classe se già presente 1961 accordionCliccata = null; 1962 } 1963 }); 1964 1965 } 1966 1967 // MENU DESKTOP CUSTOM 1968 if (newWindowWidth > 992) { 1969 let desktopDropdownsFather = $(".navbar .dropdown"); 1970 let desktopDropdowns = $(".navbar .dropdown ul"); 1971 desktopDropdownsFather.click(function() { 1972 $(this).siblings(".dropdown").find("ul").hide(); 1973 1974 $(this).children("ul").show(); 1975 $(this).children("ul").css('top', '100%'); 1976 }); 1977 1978 $(document).mouseup(function(e) { 1979 if (!desktopDropdowns.is(e.target) && desktopDropdowns.has(e.target).length === 0) { 1980 desktopDropdowns.hide(); 1981 } 1982 }); 1983 }; 1984 1985 if (newWindowWidth < 992) { 1986 //MENU MOBILE CUSTOM 1987 let voceScelta = $(".navbar .dropdown .voce-scelta-mobile"); 1988 let tornaIndietro = $("#icon-torna-indietro"); 1989 let voceSceltaAttuale = []; 1990 1991 voceScelta.click(function() { 1992 voceSceltaAttuale.push($(this)); 1993 $(this).parent().siblings("li").hide(); 1994 $(this).children("i").hide(); 1995 $(this).next().show(); 1996 $(this).addClass("grassetto"); 1997 tornaIndietro.show(); 1998 return voceSceltaAttuale; 1999 }); 2000 2001 tornaIndietro.click(function() { 2002 let ultimaVoceScelta = voceSceltaAttuale.pop(); 2003 ultimaVoceScelta.parent().siblings("li").show(); 2004 ultimaVoceScelta.siblings("ul").hide(); 2005 ultimaVoceScelta.removeClass("grassetto"); 2006 ultimaVoceScelta.children("i").show(); 2007 if (voceSceltaAttuale.length === 0) { 2008 voceScelta.removeClass("grassetto"); 2009 voceScelta.children("i").show(); 2010 tornaIndietro.hide(); 2011 } 2012 }); 2013 } 2014 } 2015 2016 2017 $(window).on("resize", function(e) { 2018 ricaricaPagina(); 2019 }); 2020 2021 ricaricaPagina(); 2022}); 2023 2024 2025function trovaPrimoElemento(array) { 2026 2027 for (let chiave in array) { 2028 if (array.hasOwnProperty(chiave)) { // Controlla se la proprietà appartiene effettivamente all'oggetto 2029 let valore = array[chiave]; 2030 return valore 2031 } 2032 } 2033} 2034 2035 2036function print_prodotto(prodotto, size = 'col-lg-3') { 2037 var p = '' 2038 var h = '' 2039 var spegratuita = '' 2040 var promo = ''; 2041 var thumbs = false;
2042 try { 2043 if (Object.keys(prodotto['thumbs']).length > 0) { 2044 2045 var foto = prodotto['thumbs']["300x300"] 2046 foto = foto[0] 2047 thumbs = true; 2048 2049 } else { 2050 var foto = "https://assets.zangoo.it/webp/not_found.webp" 2051 if (prodotto['foto'] != undefined) { 2052 if (prodotto['foto'][0] != undefined) { 2053 var foto = prodotto['foto'][0] 2054 2055 } 2056 } 2057 2058 } 2059 } catch (error) { 2060 return '' 2061 } 2062 2063 2064 2065 if (parseFloat(prodotto['sconto_percentuale']) > 0) { 2066 p = '<div class="product-label label-offer" style="font-weight: 400;"><span ><strong> Promo</strong></span></div>'; 2067 } 2068 if (prodotto['is_promo']) { 2069 promo = ` <div class="d-flex align-items-end"> 2070 <p class="prezzo-originale me-1 mb-0">â¬` + parseFloat(prodotto['prezzo_old']).toFixed(2) + `</p> 2071 <p class="sconto mb-0">` + parseFloat(prodotto['sconto_percentuale']).toFixed(2) + `%</p> 2072 </div>` 2073 } 2074 if (parseInt(prodotto['prezzo']) > 299) { 2075 spegratuita = `<div class="product-label label-offer spedizione" style="font-weight: 400;"><i class="bi bi-truck"></i><span ><strong> Gratis</strong></span></div>` 2076 } 2077 2078 // <img class="img-fluid mb-2 img-prodotto lazyload" data-src="` + prodotto['foto'][0] + `" src="https://` + window.location.hostname + `/assets/img/lazy-new.gif" alt=""> 2079 2080 2081 2082 var foto_item = '<img class="img-fluid mb-2 img-prodotto " src="' + foto + '" alt="">' 2083 if (thumbs == true) { 2084 foto_item = `<img class="img-fluid mb-2 img-prodotto" src="` + foto + `" 2085 srcset="` + foto.replace('300x300', '800x800') + ` 800w, 2086 ` + foto + ` 300w" 2087 sizes="(max-width: 992px) 100vw, 300px" 2088 alt="">` 2089 } 2090 2091 var u = 'https://' + window.location.hostname + '/' + prodotto['url'] 2092 var rating = prodotto['recensioni_media'] 2093 var numero = prodotto['recensioni'] 2094 stars = '<span class="d-flex valutazione">' + parseFloat(rating).toFixed(1) + '' + generaStelle(rating) + '<el class="n">' + (numero) + '</el></span>' 2095 h += `<div class="p-1 ` + size + `"><div class="image-container"> 2096 <a href="${u}" data-url="` + u + `" data-title="` + prodotto['nome'] + `" onclick="loadContent(this)" 2097 <span> 2098 <div class="prodotto"> 2099 ` + p + ` 2100 ` + foto_item + ` 2101 2102 <p class="codice">Codice: <strong>` + prodotto['sku'] + `</strong></p> 2103 <p class="descrizione mb-2">` + prodotto['nome'] + `</p> 2104 ` + stars + ` 2105 <div class="d-flex justify-content-between mt-2"> 2106 <p class="prezzo mb-0">â¬` + parseFloat(prodotto['prezzo']).toFixed(2) + `</p> 2107 ` + promo + ` 2108 ` + spegratuita + ` 2109 </div> 2110 2111 </div> 2112 </div> 2113 </span> 2114 </a> 2115 </div>` 2116 2117 2118 return h; 2119} 2120 2121 2122function getUrlParam(param = false) { 2123 var url = (window.location.href).split('?')[1] 2124 const paramStr = url; 2125 const searchParams = new URLSearchParams(paramStr); 2126 return searchParams.get(param) 2127 2128} 2129 2130 2131 2132function updateQueryStringParameter(uri, key, value) { 2133 var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i"); 2134 var separator = uri.indexOf('?') !== -1 ? "&" : "?"; 2135 if (uri.match(re)) { 2136 return uri.replace(re, '$1' + key + "=" + value + '$2'); 2137 } else { 2138 return uri + separator + key + "=" + value; 2139 } 2140} 2141 2142 2143 2144function loadPreferiti() { 2145 var pp = document.getElementById('prodotto') 2146 2147 values = { 2148 api: true, 2149 act: 'preferiti', 2150 light: 'light' 2151 }; 2152 var c = {}; 2153 2154 var request = $.ajax({ 2155 url: "index.php", 2156 method: "post", 2157 data: values, 2158 async: true 2159 }); 2160 2161 request.done(function(response) { 2162 if (pp) { 2163 var id = pp.getAttribute('data-id') 2164 document.getElementById('preferito-btn').setAttribute('class', 'bi bi-heart') 2165 document.getElementById('preferito-btn').setAttribute('data-id', id) 2166 document.getElementById('preferito-btn').setAttribute('onclick', 'aggiungi_preferito(this)') 2167 2168 for (let index = 0; index < response.length; index++) { 2169 const element = response[index]; 2170 if (element['id'] == id) { 2171 document.getElementById('preferito-btn').setAttribute('class', 'bi bi-heart-fill') 2172 document.getElementById('preferito-btn').setAttribute('onclick', 'rimuoviPreferito(this)') 2173 } 2174 } 2175 } 2176 var np = document.getElementById('numero-preferiti') 2177 if (np) { 2178 np.innerHTML = response.length 2179 } 2180 var np = document.getElementById('numero-preferiti-mobile') 2181 if (np) { 2182 np.innerHTML = response.length 2183 } 2184 2185 }) 2186 2187 request.fail(function(jqXHR, textStatus) { 2188 console.log("Request failed: " + textStatus); 2189 return false;
2190 }) 2191} 2192 2193 2194 2195function calcoloSpeseComplessive() { 2196 2197 2198} 2199 2200// Altezza in pixel dopo la quale l'header diventa sticky 2201var scrollThreshold = 190; // Cambia questo valore secondo le tue esigenze 2202 2203window.addEventListener("scroll", function() { 2204 var header = document.getElementById("header"); 2205 var main = document.getElementById("main"); 2206 if (header) { 2207 if (window.scrollY > scrollThreshold) { 2208 if (header.classList.contains('fixed') == false) { 2209 header.classList.add('fixed') 2210 main.classList.add('topped') 2211 } 2212 } else { 2213 if (header.classList.contains('fixed') !== false) { 2214 header.classList.remove('fixed') 2215 main.classList.remove('topped') 2216 } 2217 } 2218 } 2219 2220}); 2221 2222 2223document.addEventListener("DOMContentLoaded", function() { 2224 2225 var myLinks = document.getElementsByClassName("voce-scelta-mobile"); 2226 for (let index = 0; index < myLinks.length; index++) { 2227 let myLink = myLinks[index]; 2228 myLink.addEventListener("click", function(event) { 2229 if (myLink.getAttribute("href") === "#") { 2230 event.preventDefault(); 2231 } 2232 }); 2233 } 2234 2235 2236 $("#ricerca-mobile").click(function(e) { 2237 e.preventDefault(); 2238 if (document.getElementById('sezione-ricerca-mobile').classList.contains('active') == true) { 2239 $("#sezione-ricerca-mobile").fadeIn(300).removeClass("active"); 2240 $("#CookiebotWidget").removeClass('d-none') 2241 } else { 2242 $("#sezione-ricerca-mobile").fadeIn(300).addClass("active"); 2243 $("#CookiebotWidget").addClass('d-none') 2244 } 2245 2246 }); 2247 2248 $(document).click(function(e) { 2249 2250 2251 2252 2253 2254 if (!$(e.target).closest('#sezione-ricerca-mobile, #ricerca-mobile').length) { 2255 var fadeOutDuration = 300; 2256 $("#sezione-ricerca-mobile").fadeOut(fadeOutDuration, function() { 2257 var input = document.querySelectorAll('.aa-Input'); 2258 var event = new Event('change'); 2259 var event_b = new Event('blur'); 2260 var event_f = new Event('focus'); 2261 var event_i = new Event('input'); 2262 if (input[0]) { 2263 input[0].dispatchEvent(event); 2264 input[0].dispatchEvent(event_b); 2265 input[0].dispatchEvent(event_i); 2266 input[0].dispatchEvent(event_f); 2267 } 2268 2269 2270 2271 var $this = $(this); 2272 setTimeout(function() { 2273 $this.removeClass("active"); 2274 $("#CookiebotWidget").removeClass('d-none') 2275 }, fadeOutDuration); 2276 }); 2277 } 2278 }); 2279 2280 2281 2282})
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.