1 2//gestione loader 3/* 4document.addEventListener('click', function (e) { 5 6 if (!document.body.classList.contains('view-app')) return; 7 8 const link = e.target.closest('a'); 9 if (!link) return; 10 11 // condizioni per IGNORARE il loader 12 if ( 13 !link.href || 14 link.href.startsWith('#') || 15 link.href.startsWith('javascript:') || 16 link.target === '_blank' || 17 link.hasAttribute('download') || 18 link.dataset.noLoader === '1' 19 ) { 20 return; 21 } 22 23 // stesso URL â niente loader 24 if (link.href === window.location.href) { 25 return; 26 } 27 28 const loader = document.getElementById('page-loader'); 29 if (loader) { 30 loader.style.display = 'flex'; 31 loader.style.opacity = '1'; 32 } 33 34}, true); 35 36window.addEventListener('load', function () { 37 38 if (!document.body.classList.contains('view-app')) return; 39 40 41 //alert("quiii"); 42 43 const loader = document.getElementById('page-loader'); 44 if (!loader) return; 45 46 loader.style.display = 'none'; 47 48 //setTimeout(() => loader.remove(), 300); 49}); 50*/ 51//fine gestione loader 52 53 54 55document.addEventListener('DOMContentLoaded', function () { 56 57 if (!document.body.classList.contains('view-app')) return; 58 59 const ids = ['form-field-profilazione', 'form-field-marketing']; 60 61 ids.forEach(id => { 62 63 const el = document.getElementById(id); 64 if (!el) return; 65 66 // Elementor usa wrapper, quindi troviamo l'input vero 67 const checkbox = el.querySelector('input[type="checkbox"]') || el; 68 69 if (checkbox) { 70 checkbox.checked = true; 71 checkbox.value = "1"; 72 73 // importante per Elementor 74 checkbox.dispatchEvent(new Event('change', { bubbles: true })); 75 checkbox.dispatchEvent(new Event('input', { bubbles: true })); 76 } 77 78 }); 79 80}); 81 82 83 84 85var dati_utente; 86 87var errorMessagecustom = false; 88 89 90if (document.URL.includes("registrati")) { 91 jQuery("body").keydown(function (event) { 92 var hideUseriInfoModal = jQuery('.popup_confirm_user') 93 if (event.keyCode === 13) { 94 if (hideUseriInfoModal.css('display') == 'flex') { 95 // Cancel the default action, if needed 96 event.preventDefault(); 97 // Trigger the button element with a click 98 jQuery('#completeFormRegistrazione').click(); 99 } 100 101 } 102 103 104 }); 105} 106; 107 108 109 110jQuery(window).on("elementor/frontend/init", function () { 111 112 setTimeout(function () { 113 if (document.URL.includes("ottieni-carta")) { 114 115 (function (global, factory) { 116 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : 117 typeof define === 'function' && define.amd ? define(['exports'], factory) : 118 (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.it = {})); 119 }(this, (function (exports) { 120 'use strict'; 121 122 var fp = typeof window !== "undefined" && window.flatpickr !== undefined 123 ? window.flatpickr 124 : { 125 l10ns: {}, 126 }; 127 var Italian = { 128 weekdays: { 129 shorthand: ["Dom", "Lun", "Mar", "Mer", "Gio", "Ven", "Sab"], 130 longhand: [ 131 "Domenica", 132 "Lunedì", 133 "Martedì", 134 "Mercoledì", 135 "Giovedì", 136 "Venerdì", 137 "Sabato", 138 ], 139 }, 140 months: { 141 shorthand: [ 142 "Gen", 143 "Feb", 144 "Mar", 145 "Apr", 146 "Mag", 147 "Giu", 148 "Lug", 149 "Ago", 150 "Set", 151 "Ott", 152 "Nov", 153 "Dic", 154 ], 155 longhand: [ 156 "Gennaio", 157 "Febbraio", 158 "Marzo", 159 "Aprile", 160 "Maggio", 161 "Giugno", 162 "Luglio", 163 "Agosto", 164 "Settembre", 165 "Ottobre", 166 "Novembre", 167 "Dicembre", 168 ], 169 }, 170 firstDayOfWeek: 1, 171 ordinal: function () { 172 return "°"; 173 }, 174 rangeSeparator: " al ", 175 weekAbbreviation: "Se", 176 scrollTitle: "Scrolla per aumentare", 177 toggleTitle: "Clicca per cambiare", 178 time_24hr: true, 179 }; 180 fp.l10ns.it = Italian; 181 var it = fp.l10ns; 182
183 exports.Italian = Italian; 184 exports.default = it; 185 186 Object.defineProperty(exports, '__esModule', {value: true}); 187 188 }))); 189 190 flatpickr.localize(flatpickr.l10ns.it); 191 192 const today = new Date(); 193 today.setDate(today.getDate() + 1); 194 195 196 // Calcolo la data di nascita (massimo 18 anni fa) 197 var adult = new Date(); 198 adult.setFullYear(adult.getFullYear() - 18); // Sottrai 18 anni 199 var maxDateFormatted = adult.toISOString().split('T')[0]; 200 // Inizializza Flatpickr con localizzazione italiana per il secondo campo 201 flatpickr("#form-field-field_data", { 202 dateFormat: 'd-m-Y', 203 maxDate: maxDateFormatted 204 205 206 }); 207 208 209 210 211 212 213 214 function initRichiesta() { 215 if (jQuery('body.elementor-editor-active').length > 0) 216 return; 217 218 219 loader(); 220 jQuery.ajax({ 221 type: 'POST', 222 url: ajax_object.ajaxurl, 223 data: { 224 action: 'getListaPDV' 225 }, 226 /*timeout: 5000,*/ 227 success: function (output) { 228 229 var returnJson = output; 230 returnJson = returnJson["Pdv"]; 231 var select = document.getElementById('punti_vendita'); // Get the datalist element 232 233 // Clear any existing options first, if necessary 234 select.innerHTML = ''; 235 236 // Loop through each item in the JSON response 237 returnJson.forEach(function (optionText) { 238 239 // Create a new option element 240 var option = document.createElement('option'); 241 242 243 option.setAttribute("isa-index", optionText["codice"]); 244 option.text = optionText["citta"]; 245 option.value = optionText.ragioneSociale + " - " + optionText.provincia + " - " + optionText.citta + " - " + optionText.indirizzo + " - " + optionText.cap; // Set the visible text (optional) 246 247 // Append the option to the datalist 248 select.appendChild(option); 249 }); 250 251 loader(); 252 253 254 }, 255 error: function (jqXHR, textStatus, errorThrown) { 256 console.error('AJAX request failed:', textStatus, errorThrown); 257 console.log('Response:', jqXHR.responseText); 258 loader(); 259 } 260 }); 261 jQuery.ajax({ 262 type: 'POST', 263 url: ajax_object.ajaxurl, 264 data: { 265 action: 'get_province' 266 }, 267 /*timeout: 5000,*/ 268 success: function (output) { 269 var AField = output; 270 271 var dataListProvincia = document.getElementById('provincia_residenza'); // Get the datalist element 272 var dataListProvinciaNasc = document.getElementById('provincia_nascita'); // Get the datalist element 273 274 AField.forEach(function (optionText) { 275 let option = document.createElement('option'); 276 option.value = optionText.Nome; // Set the value of the option 277 option.text = optionText.Sigla; // Set the visible text (optional) 278 option.setAttribute("isa-index", optionText.id); 279 option.setAttribute("isa-value", optionText.Sigla); 280 let option2 = option.cloneNode(true); 281 282 dataListProvincia.appendChild(option); 283 dataListProvinciaNasc.appendChild(option2); 284 } 285 286 ); 287// loader() 288 }, 289 error: function (jqXHR, textStatus, errorThrown) { 290 console.error('AJAX request failed:', textStatus, errorThrown); 291 console.log('Response:', jqXHR.responseText); 292 loader() 293 } 294 }); 295 296 } 297 initRichiesta(); 298 299 300 301 302
303 jQuery('form[name="Nuova carta"]').on("change", "#form-field-punti_vendita", function () { 304 305 if (this.value != "") { 306 var listId = this.getAttribute("list"); 307 308 309 var selectedOption = document.querySelector('#' + listId + ' option[value="' + this.value + '"]'); 310 var isaIndex = selectedOption.getAttribute("isa-index"); 311 jQuery("#puntoVendita").text(this.value) 312 document.getElementById("form-field-idPuntovendita").value = isaIndex; 313 314 } else { 315 document.getElementById("form-field-idPuntovendita").value = isaIndex; 316 } 317 318 319 320 }); 321 322 323 324 325 326 jQuery('form[name="Nuova carta"]').on("click", "#cambiaPunto", function () { 327 328 jQuery(".e-form__buttons__wrapper__button-previous").click(); 329 jQuery("#form-field-punti_vendita").val(""); 330 }) 331 332 333 334 jQuery('form[name="Nuova carta"]').on("change", "#form-field-provincia_residenza, #form-field-provincia_nascita", function () { 335 336 loader(); 337 var listId = this.getAttribute("list"); 338 var tipo = (listId.includes("residenza")) ? "citta_residenza" : "citta_nascita"; 339 jQuery("#form-field-" + tipo).val(""); 340 var dataList = document.getElementById(tipo); 341 342 var provinciaValue = this.value; 343 344 345 var selectedOption = document.querySelector('#' + listId + ' option[value="' + provinciaValue + '"]'); 346 347 if (selectedOption) { 348 var idProv = selectedOption.getAttribute('isa-index'); 349 350 jQuery.ajax({ 351 type: 'POST', 352 url: ajax_object.ajaxurl, 353 data: { 354 action: 'get_comuni', 355 IdProv: idProv 356 }, 357 /*timeout: 5000,*/ 358 success: function (output) { 359 360 var comuniList = output; 361 362 363 dataList.innerHTML = ''; 364 365 366 comuniList.forEach(function (comune) { 367 let option = document.createElement('option'); 368 let nomeComune = comune.descrizione.toLowerCase(); 369 let nomeComuneCap = nomeComune.charAt(0).toUpperCase() + nomeComune.slice(1); 370 option.text = nomeComuneCap; 371 option.value = nomeComuneCap; 372 option.setAttribute("isa-index", comune.id); 373 option.setAttribute("isa-value", nomeComuneCap); 374 dataList.appendChild(option); 375 }); 376 377 loader(); 378 } 379 }); 380 } else { 381 382 loader(); 383 dataList.innerHTML = ''; 384 console.log('Nessuna comune matcha con la selezione'); 385 } 386 }); 387 388 389 390 jQuery('form[name="Nuova carta"]').on("change", "#form-field-provincia_residenza", function () { 391 if (this.value != "") { 392 var listId = this.getAttribute("list"); 393 394 395 var selectedOption = document.querySelector('#' + listId + ' option[value="' + this.value + '"]'); 396 var isaIndex = selectedOption.getAttribute("isa-index"); 397 document.getElementById("form-field-idProvincia").value = isaIndex; 398 } 399 400 }); 401 402 403 404 jQuery('form[name="Nuova carta"]').on("change", "#form-field-citta_residenza", function () { 405 406 if (this.value != "") { 407 var listId = this.getAttribute("list"); 408 409 410 var selectedOption = document.querySelector('#' + listId + ' option[value="' + this.value + '"]'); 411 var isaIndex = selectedOption.getAttribute("isa-index"); 412 document.getElementById("form-field-idComune").value = isaIndex; 413 } 414 415 }); 416 417 418
419 jQuery('form[name="Nuova carta"]').on("change", "#form-field-citta_nascita", function () { 420 if (this.value != "") { 421 var listId = this.getAttribute("list"); 422 423 424 var selectedOption = document.querySelector('#' + listId + ' option[value="' + this.value + '"]'); 425 var isaIndex = selectedOption.getAttribute("isa-index"); 426 document.getElementById("form-field-idComuneNascita").value = isaIndex; 427 } 428 429 }); 430 }; 431 432 }, 1000); 433}); 434 435 436 437 438function ajaxCaruselUpdate() { 439 440 if (document.URL.includes("carrello")) { 441 442 if (document.querySelector('.swiper')) { 443 444 var script = true; 445 } 446 jQuery.ajax({ 447 type: 'POST', 448 url: ajax_object.ajaxurl, 449 data: { 450 action: 'process_shortcode_carusel' 451 }, 452 /*timeout: 5000,*/ 453 success: function (response) { 454// 455 if (response.success) { 456// 457 if (document.querySelector('.swiper')) { 458 let swiper1 = document.querySelector('.swiper').swiper; 459 const params = swiper1.params; 460 } 461 jQuery("#carusel_more .e-con-inner").empty() 462 jQuery("#carusel_more .e-con-inner").show() 463// 464 jQuery("#carusel_more .e-con-inner").append(response.data) 465 let swiper2 = document.querySelector('.swiper'); 466 467 let swiperOptions = { 468 "template_id": "1156", 469 "slidesPerView": 4, 470 "slide_to_show_mobile": 2, 471 "slide_to_show_tablet": 2, 472 "_skin": "post", 473 "slidesToScroll": 1, 474 "edit_handle_selector": ".elementor-widget-container", 475 "autoplay": { 476 "enabled": true, 477 "delay": 5000, 478 "pauseOnMouseEnter": true, 479 "disableOnInteraction": true, 480 "reverseDirection": false, 481 "stopOnLastSlide": false, 482 "waitForTransition": true 483 }, 484 "pause_on_hover": true, 485 "pause_on_interaction": true, 486 487 "infinite": true, 488 "speed": 500, 489 "spaceBetween": 10, 490 "offset_sides": "none", 491 "arrows": true, 492 "image_spacing_custom": { 493 "unit": "px", 494 "size": 10, 495 "sizes": [] 496 }, 497 "image_spacing_custom_tablet": { 498 "unit": "px", 499 "size": "", 500 "sizes": [] 501 }, 502 "image_spacing_custom_mobile": { 503 "unit": "px", 504 "size": "", 505 "sizes": [] 506 } 507} 508 509 510 let swiper = new Swiper(swiper2, swiperOptions); 511 512 } else { 513 514 jQuery("#carusel_more .e-con-inner").hide() 515 } 516 } 517 518 519 }); 520 } 521} 522 523 524 525 526jQuery(document.body).on('updated_cart_totals', function () { 527 ajaxCaruselUpdate(); 528 529 530 531}); 532 533 534 535 536 537 538 539 540function cambioProvincia(provincia) { 541 jQuery.ajax({ 542 type: 'POST', 543 url: ajax_object.ajaxurl, 544 data: { 545 action: 'get_comuni_by_prov_e_ins', 546 provincia: provincia, 547 insegna: 1 548 }, 549 /*timeout: 5000,*/ 550 success: function (output) { 551 552 var returnJson = output; 553 554 jQuery('#comune_pv').children('option').remove();// elimina tutte le select che ci sono già 555 jQuery('#comune_pv').append('<option value="default" disabled selected >Seleziona Comune*</option>'); //nome è definito nella stringa JSON 556 for (var i = 0; i < returnJson.comuni.length; i++) {// ciclo che riempie di nuovo la select con id "comune" con le nuove option 557 jQuery('#comune_pv').append('<option value="' + returnJson.comuni[i].PUN_COMUNI + '">' + returnJson.comuni[i].PUN_COMUNI + '</option>'); //nome è definito nella stringa JSON 558 } 559 jQuery('#container_lista_pv').html(returnJson.pv); 560 initMap(9); 561 } 562 }); 563} 564 565function cambiaComune(comune) { 566 jQuery.ajax({ 567 type: 'POST', 568 url: ajax_object.ajaxurl, 569 data: { 570 action: 'get_pv_by_id_ins_comune', 571 comune: comune, 572 insegna: 1 573 }, 574 /*timeout: 5000,*/ 575 success: function (output) { 576 jQuery('#container_lista_pv').html(output); 577 initMap(11); 578 } 579 }); 580} 581 582function riempiComuni(idProv, idCom) { 583 jQuery(".registration_city").html(""); 584// loader(); 585 jQuery.ajax({ 586 type: 'POST', 587 url: ajax_object.ajaxurl, 588 data: { 589 action: 'get_comuni', 590 IdProv: idProv 591 }, 592 /*timeout: 5000,*/ 593 success: function (output) { 594 var AComuni = output; 595 var a = jQuery(".registration_city").append('<option selected value="">Città </option>'); 596 jQuery.each(AComuni, function (index, value) { 597 let nomeComune = this.descrizione.toLowerCase(); 598 let nomeComuneCap = nomeComune.charAt(0).toUpperCase() + nomeComune.slice(1); 599 let html = '<option value="' + this.id + '">' + nomeComuneCap + '</option>'; 600 jQuery(".registration_city").append(html); 601 602 }); 603 a.select(); 604 loader(); 605 }, 606 complete: function () { 607 if (idCom == null) { 608 var html = '<option value="" disabled selected >Città di residenza:</option>'; 609 jQuery(".registration_city").append(html); 610 611 } else { 612 613 jQuery(".registration_city option:selected").attr(idCom); 614 } 615 616 } 617 }); 618} 619 620function riempiComuniNascita(idProv, idCom) { 621 jQuery(".cittaNascita").html(""); 622// loader(); 623 jQuery.ajax({ 624 type: 'POST', 625 url: ajax_object.ajaxurl, 626 data: { 627 action: 'get_comuni', 628 IdProv: idProv 629 }, 630 /*timeout: 5000,*/ 631 success: function (output) { 632 var AComuni = output; 633 jQuery.each(AComuni, function (index, value) { 634 let nomeComune = this.descrizione.toLowerCase(); 635 let nomeComuneCap = nomeComune.charAt(0).toUpperCase() + nomeComune.slice(1); 636 let html = '<option value="' + this.id + '">' + nomeComuneCap + '</option>'; 637 jQuery(".cittaNascita").append(html); 638 639 }); 640 loader(); 641 }, 642 complete: function () { 643 644 if (idCom == null) { 645 646 var html = '<option value="" disabled selected >Città di nascita:</option>'; 647 jQuery(".cittaNascita").append(html); 648 } else { 649 650 jQuery(".cittaNascita option:selected").attr(idCom); 651 } 652 653 } 654 655 656 }); 657} 658 659function riempiProvince() { 660 loader(); 661 662 jQuery.ajax({ 663 type: 'GET', 664 url: ajax_object.ajaxurl, 665 data: { 666 action: 'get_province' 667 }, 668 /*timeout: 5000,*/ 669 success: function (output) { 670 671 var AField = output; 672// let a = jQuery(".registration_provincia").append('<option selected value="" >seleziona</option>'); 673 jQuery.each(AField, function (index, value) { 674 let html = '<option isa-index="' + this.id + '" value="' + this.Sigla + '">' + this.Nome + '</option>'; 675 jQuery(".registration_provincia").append(html); 676 jQuery(".provinciaNascita").append(html); 677 678 } 679 680 681 ); 682 683// a.select(); 684// loader(); 685 }, complete: function () { 686 if (dati_utente.userProvincia != 0) { 687 688// console.log(dati_utente.userProvincia) 689 jQuery(".registration_provincia").val(dati_utente.userProvincia); 690 var idProv = jQuery(".registration_provincia option:selected").attr("isa-index"); 691 var IdComun = dati_utente.idComune; 692 riempiComuni(idProv, IdComun); 693// console.log(dati_utente) 694 if (dati_utente.provinciaNascita != 0) { 695 jQuery(".provinciaNascita").val(dati_utente.provinciaNascita); 696 var idProvNascita = dati_utente.provinciaNascita; 697 var IdComunNascita = dati_utente.cittaNascita; 698 riempiComuniNascita(idProvNascita, IdComunNascita); 699 } 700 } else { 701 loader(); 702 } 703 } 704 }); 705} 706 707 708function utenteByNumeroTessera(nTessera) { 709// loader(); 710 711 return jQuery.ajax({ 712 type: 'POST', 713 url: ajax_object.ajaxurl, 714 715 data: {
716 action: 'get_utente_by_tessera', 717 nTessera: nTessera 718 }, 719 /*timeout: 5000,*/ 720 721 722 }).then(output => { 723 if (output.success) { 724 725 return decryptEncData(output.data).then(AUser => { 726 AUser = JSON.parse(AUser); 727 728 729 730 console.log("vedi qua"); 731 console.log(AUser); 732 733 //window.dati_utente = AUser; 734 dati_utente = AUser; 735 736 if (Array.isArray(AUser)) { 737 jQuery(".codice_carta").attr("valido", 0); 738 var result_box = jQuery(".result_box .result"); 739 window.scrollTo(0, document.body.scrollHeight); 740 result_box.addClass('sc_infobox sc_infobox_style_error').html("Carta inesistente"); 741 result_box.scroll(); 742 result_box.fadeIn().delay(3000).fadeOut(); 743 loader(); 744 return; 745 746 } else { 747 jQuery(".codice_carta").attr("valido", 1); 748 dati_utente = AUser; 749 console.log("vedi qua dopo"); 750 console.log(dati_utente); 751 752 jQuery(".puntoVenditaEmisione").val(dati_utente.puntoVenditaEmissione).trigger('change'); 753 754 if (dati_utente.userEmail != "") { 755 756 var email_parts = dati_utente.userEmail.match(/.{1,3}/g); 757 var emailHided = email_parts[0]; 758 var i = 0; 759 do { 760 emailHided = emailHided + "..."; 761 i = i + 1; 762 } while 763 (i <= (email_parts.length - 3)); 764 emailHided = emailHided + email_parts[email_parts.length - 2] + email_parts[email_parts.length - 1]; 765 var HTML = '<label id="label-confirm-card">email:' + emailHided + '</label><input type="text" id="confirm-user-email" placeholder="completa il campo"> <button id="completeFormRegistrazione" tipoverifica="email" form="confirm-card" value="Invia">Invia</button> ' 766 jQuery("#formConfirmUtenti").append(HTML); 767 768 jQuery(".popup_confirm_user").css("display", "flex"); 769 770 jQuery("#confirm-user-email").focus(); 771 } else if (dati_utente.userNome != "") { 772 var HTML = '<label>Inserisci il tuo Nome (solo il nome)</label><input type="text" id="confirm-user-email" placeholder="completa il campo con i dati presenti nella tessera"> <button id="completeFormRegistrazione" tipoverifica="nome" form="confirm-card" value="Invia">Invia</button> ' 773 774 jQuery("#formConfirmUtenti").append(HTML); 775 776 jQuery(".popup_confirm_user").css("display", "flex"); 777 778 jQuery("#confirm-user-email").focus(); 779 } else { 780 781 var HTML = '<label>Dati anagrafici inesistenti, clicca il pulsante "Inizia" per continuare la registrazione</label><button id="completeFormRegistrazione" tipoverifica="nuovo" form="confirm-card" value="Invia">Inizia</button> ' 782 783 jQuery("#formConfirmUtenti").append(HTML); 784 785 jQuery(".popup_confirm_user").css("display", "flex"); 786 787 jQuery("#confirm-user-email").focus(); 788 789 790 791 792 } 793 loader(); 794 } 795 }).catch(error => { 796 797 console.error('Decryption failed:', error); 798 loader(); 799 jQuery(".codice_carta").attr("valido", 0); 800 var result_box = jQuery(".result_box .result"); 801 window.scrollTo(0, document.body.scrollHeight); 802 result_box.addClass('sc_infobox sc_infobox_style_error').html("Erorre Connesione"); 803 result_box.scroll(); 804 result_box.fadeIn().delay(3000).fadeOut(); 805 }); 806 } else { 807 console.error('Dati vuoti:', error); 808 loader(); 809 jQuery(".codice_carta").attr("valido", 0); 810 var result_box = jQuery(".result_box .result"); 811 window.scrollTo(0, document.body.scrollHeight); 812 result_box.addClass('sc_infobox sc_infobox_style_error').html("Erorre Connesione"); 813 result_box.scroll(); 814 result_box.fadeIn().delay(3000).fadeOut(); 815 return; 816 } 817 818 819 820 821 }).catch(error => { 822 console.error('AJAX request failed:', error); 823 loader(); 824 jQuery(".codice_carta").attr("valido", 0); 825 var result_box = jQuery(".result_box .result"); 826 window.scrollTo(0, document.body.scrollHeight); 827 result_box.addClass('sc_infobox sc_infobox_style_error').html("Erorre Connesione"); 828 result_box.scroll(); 829 result_box.fadeIn().delay(3000).fadeOut(); 830 }); 831 832 833 834// loader(); 835} 836 837 838jQuery("body").on("change", "#puntoVenditaEmisione", function () { 839 840 var pdv = this.value; 841 842 jQuery.ajax({ 843 type: 'POST', 844 url: ajax_object.ajaxurl, 845 async: false, 846 data: { 847 action: 'getListaPDV' 848 849 }, 850 /*timeout: 5000,*/ 851 success: function (output) { 852 var returnJson = output; 853 854 returnJson = returnJson["Pdv"] 855 856 857 for (let i = 0; i < returnJson.length; i++) { 858 if (returnJson[i]["codice"] === pdv) { 859 jQuery("#puntoVenditaEmisione").attr("valido", 1); 860 break; 861 } else { 862 jQuery("#puntoVenditaEmisione").attr("valido", 0); 863 } 864 } 865 866 } 867 868 }); 869}); 870 871 872jQuery(".codice_carta").on("input", function () { 873 874 if (jQuery(".codice_carta").attr("valido") != 1) { 875 var result_box = jQuery(".result_box .result"); 876 877 if (this.value.length == 13) { 878 var codice_carta = this.value; 879 if (result_box.empty()) { 880 881 loader(); 882 jQuery.ajax({ 883 type: 'POST', 884 url: ajax_object.ajaxurl, 885 data: { 886 action: 'check_carta', 887 codice_carta: codice_carta 888 }, 889 /*timeout: 5000,*/ 890 success: function (output) { 891 892 if (output.trim() == 1) { 893 window.scrollTo(0, document.body.scrollHeight); 894 895 896 result_box.addClass('sc_infobox sc_infobox_style_error').html("Carta già registrata! Ti abbiamo inviato una mail con i tuoi dati"); 897 result_box.scroll(); 898 result_box.fadeIn().delay(5000).fadeOut(() => { 899 result_box.empty() 900 }); 901 902 loader(); 903 } else { 904 jQuery(".codice_carta").blur(); 905 jQuery(".codice_carta").attr("valido", 1); 906 var nTessera = codice_carta; 907 jQuery("#label-confirm-card, #confirm-user-email, #confirm-user-email,#completeFormRegistrazione").remove(); 908 utenteByNumeroTessera(nTessera); 909 } 910 } 911 }) 912 } 913 } else { 914 915 jQuery(".codice_carta").attr("valido", 0); 916 } 917 } 918}); 919 920//function submitFormRegistration(formData) { 921// loader(); 922// var nome = formData["registration_nome"].value; 923// var nomeCapitalized = nome.charAt(0).toUpperCase() + nome.slice(1); 924// var cognome = formData["registration_cognome"].value; 925// var cognomeCapitalized = cognome.charAt(0).toUpperCase() + cognome.slice(1); 926// const result_box = jQuery(".result") 927// 928// jQuery.ajax({ 929// url: ajax_object.ajaxurl, 930// type: 'POST', 931// 932// data: { 933// action: 'registra_utente', 934// type: 'request', 935// url: ajax_object.ajaxurl, 936// nonceRegistrazione: formData["nonceRegistrazione"].value, 937// email: formData["registration_email"].value, 938// registration_nome: nomeCapitalized, 939// registration_cognome: cognomeCapitalized, 940// pwd: formData["registration_password"].value, 941// pwd2: formData["registration_password2"].value,
942// registration_civico: formData["registration_civico"].value, 943// registration_phone: formData["registration_phone"].value, 944// registration_address: formData["registration_address"].value, 945// registration_cap: formData["registration_cap"].value, 946// registration_provncia: formData["registration_provincia"].options[formData["registration_provincia"].selectedIndex].text, 947// registration_city: formData["registration_city"].options[formData["registration_city"].selectedIndex].text, 948// luogoNascita: formData["luogoNascita"].value, 949// dataNascita: formData["dataNascita"].value, 950// gender: formData["gender"].value, 951// codiceCarta: formData["codiceCarta"].value, 952// user_sigla_provincia_residenza: formData["registration_provincia"].value, 953// user_id_provincia_residenza: formData["registration_provincia"].options[formData["registration_provincia"].selectedIndex].getAttribute("isa-index"), 954// user_id_city: formData["registration_city"].value, 955// user_birth_city: formData['cittaNascita'].options[formData["cittaNascita"].selectedIndex].text, 956// user_id_birth_city: formData["cittaNascita"].value, 957// user_birth_province: formData['provinciaNascita'].options[formData["provinciaNascita"].selectedIndex].text, 958// user_sigla_birth_province: formData["provinciaNascita"].value, 959// user_id_birth_province: formData["provinciaNascita"].options[formData["provinciaNascita"].selectedIndex].getAttribute("isa-index"), 960// user_punto_emissione: formData["puntoVenditaEmisioneCheck"].value, 961// user_data_emissione: formData["dataEmisioneCheck"].value 962// 963// }, 964// timeout: 5000, 965// success: function (response) { 966// 967// loader(); 968// 969// 970// if (response.success) { 971// result_box.removeClass("sc_infobox sc_infobox_style_error") 972// result_box.show(); 973// result_box.addClass('sc_infobox sc_infobox_style_success').html(response.data); 974// result_box.delay(3000).fadeOut(); 975// result_box.scroll(); 976// } else { 977// result_box.removeClass("sc_infobox sc_infobox_style_success") 978// result_box.show(); 979// result_box.addClass('sc_infobox sc_infobox_style_error').html("Errore nella richiesta"); 980// result_box.delay(3000).fadeOut(); 981// result_box.scroll(); 982// } 983// }, 984// error: function (XMLHttpRequest, textStatus, errorThrown) { 985// loader(); 986// result_box.show(); 987// result_box.addClass('sc_infobox sc_infobox_style_error').html("Errore di connessione. Riprova più tardi."); 988// result_box.delay(3000).fadeOut(); 989// result_box.scroll(); 990// } 991// }); 992//} 993 994 995 996 997function loader() { 998 if (jQuery(".loader-box").css("display") == "none") { 999 jQuery(".loader-box").css("display", "flex"); 1000 } else { 1001 jQuery(".loader-box").hide(); 1002 } 1003} 1004 1005 1006 1007//jQuery("#registrationForm").on("click", ".submit_button", function () { 1008// 1009// 1010// 1011// 1012// if (jQuery(".puntoVenditaEmisione").attr("valido") != 1) { 1013// 1014// event.preventDefault(); 1015// var result_box = jQuery(".result") 1016// window.scrollTo(0, document.body.scrollHeight); 1017// result_box.addClass('sc_infobox sc_infobox_style_error').html("Punto vendita inesistente!"); 1018// result_box.scroll(); 1019// result_box.fadeIn().delay(3000).fadeOut(); 1020// } 1021// 1022// 1023// 1024// 1025// 1026//}); 1027 1028 1029 1030jQuery("body").on("click", "#completeFormRegistrazione", function () { 1031 loader(); 1032 var tipoControllo = jQuery("#completeFormRegistrazione").attr("tipoverifica"); 1033 var pdvCheck = jQuery(".puntoVenditaEmisione").attr("valido"); 1034 1035 1036 if (pdvCheck != 1) { 1037 1038 if (errorMessagecustom == false) { 1039 loader(); 1040 var HTML = '<div id="erromessagConifrm" class="result message_block sc_infobox sc_infobox_style_error">Punto vendita inesistente!</div>' 1041 jQuery("#formConfirmUtenti").append(HTML); 1042 var error_message_box = jQuery("#erromessagConifrm") 1043 errorMessagecustom = true; 1044 setTimeout(function () { 1045 error_message_box.fadeOut(); 1046 error_message_box.remove(); 1047 errorMessagecustom = false;
1048 }, 2000); 1049 } 1050 1051 } else { 1052 loader(); 1053 1054 if (jQuery('body.elementor-editor-active').length > 0) 1055 return; 1056 1057 1058 loader(); 1059 1060 jQuery.ajax({ 1061 type: 'POST', 1062 url: ajax_object.ajaxurl, 1063 data: { 1064 action: 'get_province' 1065 }, 1066 /*timeout: 5000,*/ 1067 success: function (output) { 1068 var AField = output; 1069 1070 var dataListProvincia = document.getElementById('provincia_residenza'); // Get the datalist element 1071 var dataListProvinciaNasc = document.getElementById('provincia_nascita'); // Get the datalist element 1072 1073 AField.forEach(function (optionText) { 1074 let option = document.createElement('option'); 1075 option.value = optionText.Nome; // Set the value of the option 1076 option.text = optionText.Sigla; // Set the visible text (optional) 1077 option.setAttribute("isa-index", optionText.id); 1078 option.setAttribute("isa-value", optionText.Sigla); 1079 let option2 = option.cloneNode(true); 1080 1081 dataListProvincia.appendChild(option); 1082 dataListProvinciaNasc.appendChild(option2); 1083 } 1084 1085 ); 1086 loader() 1087 }, complete: function (response) { 1088 (function (global, factory) { 1089 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : 1090 typeof define === 'function' && define.amd ? define(['exports'], factory) : 1091 (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.it = {})); 1092 }(this, (function (exports) { 1093 'use strict'; 1094 1095 var fp = typeof window !== "undefined" && window.flatpickr !== undefined 1096 ? window.flatpickr 1097 : { 1098 l10ns: {}, 1099 }; 1100 var Italian = { 1101 weekdays: { 1102 shorthand: ["Dom", "Lun", "Mar", "Mer", "Gio", "Ven", "Sab"], 1103 longhand: [ 1104 "Domenica", 1105 "Lunedì", 1106 "Martedì", 1107 "Mercoledì", 1108 "Giovedì", 1109 "Venerdì", 1110 "Sabato", 1111 ], 1112 }, 1113 months: { 1114 shorthand: [ 1115 "Gen", 1116 "Feb", 1117 "Mar", 1118 "Apr", 1119 "Mag", 1120 "Giu", 1121 "Lug", 1122 "Ago", 1123 "Set", 1124 "Ott", 1125 "Nov", 1126 "Dic", 1127 ], 1128 longhand: [ 1129 "Gennaio", 1130 "Febbraio", 1131 "Marzo", 1132 "Aprile", 1133 "Maggio", 1134 "Giugno", 1135 "Luglio", 1136 "Agosto", 1137 "Settembre", 1138 "Ottobre", 1139 "Novembre", 1140 "Dicembre", 1141 ], 1142 }, 1143 firstDayOfWeek: 1, 1144 ordinal: function () { 1145 return "°"; 1146 }, 1147 rangeSeparator: " al ", 1148 weekAbbreviation: "Se", 1149 scrollTitle: "Scrolla per aumentare", 1150 toggleTitle: "Clicca per cambiare", 1151 time_24hr: true, 1152 }; 1153 fp.l10ns.it = Italian; 1154 var it = fp.l10ns; 1155
1156 exports.Italian = Italian; 1157 exports.default = it; 1158 1159 Object.defineProperty(exports, '__esModule', {value: true}); 1160 1161 }))); 1162 1163 flatpickr.localize(flatpickr.l10ns.it); 1164 1165 1166 1167 jQuery('body').on("change", "#form-field-provincia_residenza, #form-field-provincia_nascita", function () { 1168 1169 loader(); 1170 var listId = this.getAttribute("list"); 1171 var tipo = (listId.includes("residenza")) ? "citta_residenza" : "citta_nascita"; 1172 jQuery("#form-field-" + tipo).val(""); 1173 var dataList = document.getElementById(tipo); 1174 1175 var provinciaValue = this.value; 1176 1177 1178 var selectedOption = document.querySelector('#' + listId + ' option[value="' + provinciaValue + '"]'); 1179 1180 if (selectedOption) { 1181 1182 var idProv = selectedOption.getAttribute('isa-index'); 1183 1184 1185 jQuery.ajax({ 1186 type: 'POST', 1187 url: ajax_object.ajaxurl, 1188 data: { 1189 action: 'get_comuni', 1190 IdProv: idProv 1191 }, 1192 /*timeout: 5000,*/ 1193 success: function (output) { 1194 1195 var comuniList = output; 1196 1197 1198 1199 dataList.innerHTML = ''; 1200 1201 1202 comuniList.forEach(function (comune) { 1203 let option = document.createElement('option'); 1204 let nomeComune = comune.descrizione.toLowerCase(); 1205 let nomeComuneCap = nomeComune.charAt(0).toUpperCase() + nomeComune.slice(1); 1206 option.text = nomeComuneCap; 1207 option.value = nomeComuneCap; 1208 option.setAttribute("isa-index", comune.id); 1209 option.setAttribute("isa-value", nomeComuneCap); 1210 dataList.appendChild(option); 1211 }); 1212 1213 loader(); 1214 } 1215 }); 1216 } else { 1217 1218 loader(); 1219 dataList.innerHTML = ''; 1220 console.log('Nessuna comune matcha con la selezione'); 1221 } 1222 }); 1223 1224 1225 jQuery('body').on("change", "#form-field-provincia_residenza", function () { 1226 1227 if (this.value != "") { 1228 var listId = this.getAttribute("list"); 1229 1230 1231 var selectedOption = document.querySelector('#' + listId + ' option[value="' + this.value + '"]'); 1232 var isaIndex = selectedOption.getAttribute("isa-index"); 1233 var valueIndex = selectedOption.getAttribute("isa-value"); 1234 document.getElementById("form-field-idProvincia").value = isaIndex; 1235 document.getElementById("form-field-siglaProvincia").value = valueIndex; 1236 } else { 1237 document.getElementById("form-field-idProvincia").value = ""; 1238 document.getElementById("form-field-siglaProvincia").value = ""; 1239 } 1240 1241 }); 1242 1243 jQuery('body').on("change", "#form-field-provincia_nascita", function () { 1244 if (this.value != "") { 1245 var listId = this.getAttribute("list"); 1246 1247 1248 var selectedOption = document.querySelector('#' + listId + ' option[value="' + this.value + '"]'); 1249 var isaIndex = selectedOption.getAttribute("isa-index"); 1250 var valueIndex = selectedOption.getAttribute("isa-value"); 1251 document.getElementById("form-field-idProvinciaNascita").value = isaIndex; 1252 document.getElementById("form-field-siglaProvinciaNascita").value = valueIndex; 1253 } else { 1254 document.getElementById("form-field-idProvinciaNascita").value = ""; 1255 document.getElementById("form-field-siglaProvinciaNascita").value = ""; 1256 } 1257 1258 }); 1259 1260 jQuery('body').on("change", "#form-field-citta_residenza", function () { 1261 1262 if (this.value != "") { 1263 var listId = this.getAttribute("list"); 1264 1265 1266 var selectedOption = document.querySelector('#' + listId + ' option[value="' + this.value + '"]'); 1267 var isaIndex = selectedOption.getAttribute("isa-index"); 1268 document.getElementById("form-field-idComune").value = isaIndex; 1269 } 1270 1271 }); 1272 1273 jQuery('body').on("change", "#form-field-citta_nascita", function () { 1274 if (this.value != "") { 1275 var listId = this.getAttribute("list"); 1276 1277 1278 var selectedOption = document.querySelector('#' + listId + ' option[value="' + this.value + '"]'); 1279 var isaIndex = selectedOption.getAttribute("isa-index"); 1280 document.getElementById("form-field-idComuneNascita").value = isaIndex; 1281 } 1282 1283 }); 1284 1285 var showForm=false; 1286 1287 if (tipoControllo == "email") { 1288 console.log(dati_utente.userEmail.toLowerCase()+":::"+jQuery("#confirm-user-email").val().toLowerCase()); 1289 console.log(dati_utente); 1290 if (dati_utente.userEmail.toLowerCase() == jQuery("#confirm-user-email").val().toLowerCase()) { 1291 1292 console.log("UGUALEEEEEEEEEEE"); 1293 showForm=true; 1294 1295 1296 1297 jQuery(".popup_confirm_user").css("display", "none"); 1298 jQuery(".card_field").hide(); 1299 jQuery("#cardInfo").hide(); 1300 jQuery(".hideform").toggleClass("hideform"); 1301 jQuery("#nuova_richiesta").hide() 1302 1303 jQuery("#form-field-idPuntovendita").val(dati_utente.puntoVenditaEmissione); 1304 jQuery("#form-field-dataEmissione").val(dati_utente.dataEmissione); 1305 jQuery("#form-field-codiceCarta").val(dati_utente.userNumeroTessera); 1306 jQuery("#form-field-email").val(dati_utente.userEmail); 1307 jQuery("#form-field-nome").val(dati_utente.userNome); 1308 jQuery("#form-field-cognome").val(dati_utente.userCognome); 1309 jQuery("#form-field-telefono").val(dati_utente.userTelefono); 1310 jQuery("#form-field-via").val(dati_utente.userIndirizzo); 1311 jQuery("#form-field-numerocivico").val(dati_utente.userNumeroCivico); 1312 jQuery("#form-field-cap").val(dati_utente.userCap);
1313 jQuery("#form-field-sesso").val(dati_utente.sesso); 1314 jQuery("#form-field-paese").val(dati_utente.luogoNascita); 1315 1316 1317 jQuery("#form-field-dataEmissione").val(dati_utente.dataEmissione); 1318 1319 var optionToSelect = jQuery("#provincia_residenza option[isa-value='" + dati_utente.userProvincia + "']"); 1320 1321 if (optionToSelect.length > 0) { 1322 1323 jQuery("#form-field-provincia_residenza").val(optionToSelect.val()).trigger('change'); 1324 } 1325 1326 1327 } else { 1328 if (errorMessagecustom == false) { 1329 1330 var HTML = '<div id="erromessagConifrm" class="result message_block sc_infobox sc_infobox_style_error" style="">Dati errati!</div>' 1331 jQuery("#formConfirmUtenti").append(HTML); 1332 var error_message_box = jQuery("#erromessagConifrm") 1333 errorMessagecustom = true; 1334 setTimeout(function () { 1335 error_message_box.fadeOut(); 1336 error_message_box.remove(); 1337 errorMessagecustom = false; 1338 }, 2000); 1339 } 1340 1341 } 1342 } else if (tipoControllo == "nome") { 1343 if (dati_utente.userNome.toLowerCase() == jQuery("#confirm-user-email").val().toLowerCase()) { 1344 1345 showForm=true; 1346 1347 jQuery(".popup_confirm_user").css("display", "none"); 1348 jQuery(".card_field").hide(); 1349 jQuery("#cardInfo").hide(); 1350 jQuery("#nuova_richiesta").hide() 1351 jQuery(".hideform").toggleClass("hideform"); 1352 1353 1354 jQuery("#form-field-idPuntovendita").val(dati_utente.puntoVenditaEmissione); 1355 jQuery("#form-field-dataEmissione").val(dati_utente.dataEmissione); 1356 jQuery("#form-field-codiceCarta").val(dati_utente.userNumeroTessera); 1357 jQuery("#form-field-email").val(dati_utente.userEmail); 1358 jQuery("#form-field-nome").val(dati_utente.userNome); 1359 jQuery("#form-field-cognome").val(dati_utente.userCognome); 1360 jQuery("#form-field-telefono").val(dati_utente.userTelefono); 1361 jQuery("#form-field-via").val(dati_utente.userIndirizzo); 1362 jQuery("#form-field-numerocivico").val(dati_utente.userNumeroCivico); 1363 jQuery("#form-field-cap").val(dati_utente.userCap); 1364 jQuery("#form-field-sesso").val(dati_utente.sesso); 1365 jQuery("#form-field-paese").val(dati_utente.luogoNascita); 1366 1367 1368 jQuery("#form-field-dataEmissione").val(dati_utente.dataEmissione); 1369 1370 1371 1372 var optionToSelect = jQuery("#provincia_residenza option[isa-value='" + dati_utente.userProvincia + "']"); 1373 1374 1375 if (optionToSelect.length > 0) { 1376 1377 jQuery("#form-field-provincia_residenza").val(optionToSelect.val()).trigger('change'); 1378 } 1379 } else { 1380 if (errorMessagecustom == false) { 1381 1382 var HTML = '<div id="erromessagConifrm" class="result message_block sc_infobox sc_infobox_style_error" style="">Dati errati!</div>' 1383 jQuery("#formConfirmUtenti").append(HTML); 1384 var error_message_box = jQuery("#erromessagConifrm") 1385 errorMessagecustom = true; 1386 setTimeout(function () { 1387 error_message_box.fadeOut(); 1388 error_message_box.remove(); 1389 errorMessagecustom = false; 1390 }, 2000); 1391 } 1392 1393 } 1394 } else if (tipoControllo == "nuovo") { 1395 /*MODIFICA RICHIESTA AFFINCHE SI POSSANO REGISTRARE ANCHE SE LA CARTA NON HA NESSUN DATO ANAGRAFICO 05/02/2025 "problema registrazione sito"*/ 1396 if (/*dati_utente.userNome.toLowerCase() == jQuery("#confirm-user-email").val().toLowerCase()*/true) { 1397 1398 showForm=true; 1399 1400 jQuery(".popup_confirm_user").css("display", "none"); 1401 jQuery(".card_field").hide(); 1402 jQuery("#cardInfo").hide(); 1403 jQuery("#nuova_richiesta").hide() 1404 jQuery(".hideform").toggleClass("hideform"); 1405 1406 1407 1408 jQuery("#form-field-idPuntovendita").val(dati_utente.puntoVenditaEmissione); 1409 jQuery("#form-field-dataEmissione").val(dati_utente.dataEmissione); 1410 jQuery("#form-field-codiceCarta").val(dati_utente.userNumeroTessera); 1411 jQuery("#form-field-email").val(dati_utente.userEmail); 1412 jQuery("#form-field-nome").val(dati_utente.userNome); 1413 jQuery("#form-field-cognome").val(dati_utente.userCognome); 1414 jQuery("#form-field-telefono").val(dati_utente.userTelefono); 1415 jQuery("#form-field-via").val(dati_utente.userIndirizzo); 1416 jQuery("#form-field-numerocivico").val(dati_utente.userNumeroCivico); 1417 jQuery("#form-field-cap").val(dati_utente.userCap);
1418 jQuery("#form-field-sesso").val(dati_utente.sesso); 1419 jQuery("#form-field-paese").val(dati_utente.luogoNascita); 1420 1421 jQuery("#form-field-dataEmissione").val(dati_utente.dataEmissione); 1422 1423 1424 1425 1426 1427 var optionToSelect = jQuery("#provincia_residenza option[isa-value='" + dati_utente.userProvincia + "']"); 1428 console.log(optionToSelect) 1429 1430 if (optionToSelect.length > 0) { 1431 1432 jQuery("#form-field-provincia_residenza").val(optionToSelect.val()).trigger('change'); 1433 } 1434 } else { 1435 if (errorMessagecustom == false) { 1436 1437 var HTML = '<div id="erromessagConifrm" class="result message_block sc_infobox sc_infobox_style_error" style="">Dati errati!</div>' 1438 jQuery("#formConfirmUtenti").append(HTML); 1439 var error_message_box = jQuery("#erromessagConifrm") 1440 errorMessagecustom = true; 1441 setTimeout(function () { 1442 error_message_box.fadeOut(); 1443 error_message_box.remove(); 1444 errorMessagecustom = false; 1445 }, 2000); 1446 } 1447 } 1448 } 1449 1450 1451 let data = dati_utente.dataNascita ? dati_utente.dataNascita.split('/').join('-') : ""; 1452 // Calcolo la data di nascita (massimo 18 anni fa) 1453 var adult = new Date(); 1454 adult.setFullYear(adult.getFullYear() - 18); // Sottrai 18 anni 1455 var maxDateFormatted = adult.toISOString().split('T')[0]; 1456 1457 1458 // Inizializza Flatpickr con localizzazione italiana per il secondo campo 1459 flatpickr("#form-field-data", { 1460 1461 maxDate: maxDateFormatted, 1462 dateFormat: "d-m-Y", 1463 defaultDate: data ? data : maxDateFormatted 1464 1465 }); 1466 1467 1468 if(showForm){ 1469 jQuery("#form-container").show(); 1470 } 1471 1472 1473 }, 1474 error: function (jqXHR, textStatus, errorThrown) { 1475 console.error('AJAX request failed:', textStatus, errorThrown); 1476 console.log('Response:', jqXHR.responseText); 1477 loader() 1478 } 1479 }); 1480 1481 1482 1483 1484 } 1485}); 1486 1487 1488 1489 1490function closeCardConfirm() { 1491 dati_utente = ""; 1492 1493 jQuery(".i_agree_privacy_policy_registration").prop("disabled", false); 1494 1495 jQuery(".codice_carta").attr("valido", 0); 1496 jQuery(".popup_confirm_user").css("display", "none"); 1497 1498 1499} 1500 1501 1502async function decryptEncData(ciphertext) { 1503 const password = await getSecretKey(); 1504 1505 1506 const ivHex = ciphertext.slice(0, 32); 1507 const ctBase64 = ciphertext.slice(32); 1508 1509 1510 const iv = new Uint8Array(ivHex.match(/.{1,2}/g).map(byte => parseInt(byte, 16))); 1511 1512 1513 const ctBytes = Uint8Array.from(atob(ctBase64), c => c.charCodeAt(0)); 1514 1515 1516 const pwUtf8 = new TextEncoder().encode(password); 1517 const pwHash = await window.crypto.subtle.digest('SHA-256', pwUtf8); 1518 1519 1520 const alg = {name: 'AES-CBC', iv: iv}; 1521 const key = await window.crypto.subtle.importKey('raw', pwHash, alg, false, ['decrypt']); 1522 1523 1524 const ptBuffer = await window.crypto.subtle.decrypt(alg, key, ctBytes); 1525 const plaintext = new TextDecoder().decode(ptBuffer); 1526 1527 return plaintext; 1528} 1529 1530 1531 1532 1533// get key asyn/promise per decryptData 1534function getSecretKey() { 1535 return new Promise((resolve, reject) => { 1536 jQuery.ajax({ 1537 type: 'POST', 1538 url: ajax_object.ajaxurl, 1539 data: { 1540 action: 'getSecretKeyAjax' 1541 }, 1542 /*timeout: 5000,*/ 1543 success: function (response) { 1544 1545 if (response.success) { 1546 resolve(response.data); 1547 } else { 1548 reject('Failed to get secret key'); 1549 } 1550 }, 1551 error: function (error) { 1552 reject(error); 1553 } 1554 }); 1555 }); 1556} 1557 1558 1559 jQuery('body').on("click", "#downloadCard", function (e) { 1560 1561 e.preventDefault(); 1562 jQuery.ajax({ 1563 type: 'POST', 1564 url: ajax_object.ajaxurl, 1565 data: { 1566 1567 action: 'downloadCard' 1568 1569 }, 1570 /*timeout: 5000,*/ 1571 success: function (output) { 1572 1573 1574 1575 1576 var pdfData = output['data'][0].pdf; 1577 1578 var pdfBlob = base64ToBlob(pdfData, 'application/pdf'); 1579 var url = URL.createObjectURL(pdfBlob); 1580 var link = document.createElement('a'); 1581 link.href = url; 1582 link.download = 'carta_'+output['data'][1]+'.pdf'; 1583 document.body.appendChild(link); 1584 link.click(); 1585 document.body.removeChild(link); 1586 1587 1588 1589 } 1590 }); 1591 }) 1592 1593 1594 1595 function base64ToBlob(base64, contentType) { 1596 var byteCharacters = atob(base64); 1597 var byteArrays = []; 1598 for (var offset = 0; offset < byteCharacters.length; offset += 512) { 1599 var slice = byteCharacters.slice(offset, offset + 512); 1600 var byteNumbers = new Array(slice.length); 1601 for (var i = 0; i < slice.length; i++) { 1602 byteNumbers[i] = slice.charCodeAt(i); 1603 } 1604 var byteArray = new Uint8Array(byteNumbers); 1605 byteArrays.push(byteArray); 1606 } 1607 var blob = new Blob(byteArrays, { type: contentType }); 1608 return blob; 1609 }
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.