1jQuery(document).ready(function ($) { 2 $(function () { 3 if (window.self == window.top) { 4 $(document.body).addClass('no-iframe') 5 } 6 }) 7 8 // VARIABILI 9 let modalTotalepassengers = 0 10 let modalDepartureDate = new Date() 11 let modalReturnDate = new Date() 12 // vehicle 13 const modalSelectors = [] 14 const modalVeiclesSummary = [] 15 const ModalIds = [] 16 17 // FUNZIONI UTILS 18 const compareDates = (d1, d2) => { 19 let date1 = new Date(d1).getTime() 20 let date2 = new Date(d2).getTime() 21 22 if (date1 > date2) { 23 return true 24 } else { 25 return false 26 } 27 } 28 29 const makeID = (length) => { 30 let result 31 let notUnique = true 32 while (notUnique) { 33 result = '' 34 const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' 35 const charactersLength = characters.length 36 let counter = 0 37 while (counter < length) { 38 result += characters.charAt(Math.floor(Math.random() * charactersLength)) 39 counter += 1 40 } 41 if (!ModalIds.includes(result)) { 42 notUnique = false 43 } 44 } 45 return result 46 } 47 48 const displayvehicles = () => { 49 if (modalVeiclesSummary.length > 0) { 50 $('#iframe-hero .modal-control-vehicles .aggiungi').css('display', 'none') 51 $('#iframe-hero .modal-control-vehicles .totale').css('display', 'flex') 52 if (modalVeiclesSummary.length > 1) { 53 $('#iframe-hero .modal-control-vehicles .totale').prepend('<p class="tot-vehicles pe-2">' + modalVeiclesSummary.length + ' ' + WPURLS.string.vehicles_str + '</p>') 54 } else { 55 $('#iframe-hero .modal-control-vehicles .totale').prepend('<p class="tot-vehicles pe-2">' + modalVeiclesSummary.length + ' ' + WPURLS.string.vehicle_str + '</p>') 56 } 57 } else { 58 $('#iframe-hero .modal-control-vehicles .aggiungi').css('display', 'flex') 59 $('#iframe-hero .modal-control-vehicles .totale').css('display', 'none') 60 $('#iframe-hero .modal-control-vehicles .totale .tot-vehicles').remove() 61 } 62 } 63 64 const displayPassengers = () => { 65 if (modalTotalepassengers > 0) { 66 $('#iframe-hero .modal-control-passengers .aggiungi').css('display', 'none') 67 if (modalTotalepassengers > 1) { 68 $('#iframe-hero .modal-control-passengers .totale').prepend('<p class="tot-passengers pe-2">' + modalTotalepassengers + ' ' + WPURLS.string.passengers_str + '</p>') 69 } else { 70 $('#iframe-hero .modal-control-passengers .totale').prepend('<p class="tot-passengers pe-2">' + modalTotalepassengers + ' ' + WPURLS.string.passenger_str + '</p>') 71 } 72 } else { 73 $('#iframe-hero .modal-control-passengers .aggiungi').css('display', 'block') 74 } 75 } 76 77 $('#iframe-hero .number-select').each(function () { 78 $(this) 79 .find('.add') 80 .on('click', () => { 81 $(this).find('input')[0].stepUp() 82 $(this).find('.number').text($(this).find('input').val()) 83 if (parseInt($('#select-adulti input').val()) > modalVeiclesSummary.length) { 84 $('#select-adulti').find('.sub').removeClass('disable') 85 $('.errore-passengers').remove() 86 } 87 }) 88 $(this) 89 .find('.sub') 90 .on('click', () => { 91 $(this).find('input')[0].stepDown() 92 $(this).find('.number').text($(this).find('input').val()) 93 if (parseInt($('#select-adulti input').val()) <= modalVeiclesSummary.length) { 94 $('#select-adulti').find('.sub').addClass('disable') 95 $('<div class="errore-passengers">Errore</div>').insertAfter('.adulti') 96 } 97 }) 98 }) 99 100 $('#iframe-hero .iframe-modal.passengers') 101 .find('.number') 102 .each(function () { 103 modalTotalepassengers += parseInt($(this).text()) 104 }) 105 106 displayvehicles() 107 displayPassengers() 108 109 function checkSelect() { 110 if ($('#iframe-hero #form-trip-direction-hero').val() == 'A') { 111 $('#iframe-hero #calendar-date-return').addClass('disable') 112 } else { 113 $('#iframe-hero #calendar-date-return').removeClass('disable') 114 } 115 $('.ss-option').on('click', function () { 116 checkSelect() 117 }) 118 } 119 120 function checkRadio() { 121 if ($('#iframe-hero .direction-select .form-check-input:checked').val() == 'A') { 122 $('#iframe-hero .calendar.calendar-return').addClass('disable'); 123 $('#iframe-hero #calendar-date-return').addClass('disable'); 124 } else { 125 $('#iframe-hero .calendar.calendar-return').removeClass('disable'); 126 $('#iframe-hero #calendar-date-return').removeClass('disable') 127 } 128 } 129 130 $('#iframe-hero .direction-select .form-check-input').on('change', function () { 131 checkRadio(); 132 }); 133 134 checkSelect(); 135 checkRadio(); 136 137 $('#iframe-hero .switch-destinations svg').on('click', function () { 138 $(this).parent().toggleClass('rotate')
139 let utilDestination = $('#iframe-hero .form-departure span').text() 140 $('#iframe-hero .form-departure span').text($('#iframe-hero .form-destination span').text()) 141 $('#iframe-hero .form-destination span').text(utilDestination); 142 143 }); 144 145 $('#iframe-hero .calendar-departure-city-from-select').on('change', function () { 146 selectDestination($(this)); 147 }); 148 149 150 function selectDestination(select) { 151 let selectedValue = select.val(); 152 let notSelectedValue = select.find('option:not(:selected)').val(); 153 let departureTo = select.closest('.form-calendars-container').find('.calendar-departure-city-to-name'); 154 let returnFrom = select.closest('.form-calendars-container').find('.calendar-return-city-from-name'); 155 let returnTo = select.closest('.form-calendars-container').find('.calendar-return-city-to-name'); 156 157 departureTo.text(notSelectedValue); 158 departureTo.attr('data-value', notSelectedValue); 159 160 returnFrom.text(notSelectedValue); 161 returnFrom.attr('data-value', notSelectedValue); 162 163 returnTo.text(selectedValue); 164 returnTo.attr('data-value', selectedValue); 165 } 166 167 168 169 // DATEPICKER 170 let conferma = { 171 content: WPURLS.string.conferma, 172 tagName: 'div', 173 onClick: (dp) => { 174 dp.destroy() 175 }, 176 } 177 178 const todayDateAndata = new AirDatepicker('#iframe-hero #calendar-date-departure', { 179 locale: locale[$('#iframe-hero .container-card').data('lang')], 180 autoClose: true, 181 buttons: [conferma], 182 selectedDates: [new Date()], 183 minDate: modalDepartureDate, 184 dateFormat: 'd MMM yyyy', 185 toggleSelected: false, 186 }) 187 188 const todayDateRitorno = new AirDatepicker('#iframe-hero #calendar-date-return', { 189 locale: locale[$('#iframe-hero .container-card').data('lang')], 190 autoClose: true, 191 buttons: [conferma], 192 selectedDates: [new Date()], 193 minDate: modalDepartureDate, 194 dateFormat: 'd MMM yyyy', 195 toggleSelected: false, 196 }) 197 198 $('#iframe-hero').on('click', '#calendar-date-departure', function () { 199 const dataInizio = new AirDatepicker('#iframe-hero #calendar-date-departure', { 200 locale: locale[$('#iframe-hero .container-card').data('lang')], 201 inline: true, 202 buttons: [conferma], 203 dateFormat: 'd MMM yyyy', 204 minDate: new Date(), 205 classes: 'datapicker-inizio', 206 selectedDates: modalDepartureDate, 207 toggleSelected: false, 208 onSelect({date, formattedDate, datepicker}) { 209 modalDepartureDate = dataInizio.focusDate 210 $('#iframe-hero #calendar-date-departure').attr('aria-label', WPURLS.string.data_andata + ': ' + formattedDate) 211 // console.log('departure', modalDepartureDate) 212 // console.log('airdate date', date) 213 // console.log('airdate formatted', formattedDate) 214 215 if (compareDates(modalDepartureDate, modalReturnDate)) { 216 modalReturnDate = modalDepartureDate 217 218 const todayDateRitorno = new AirDatepicker('#iframe-hero #calendar-date-return', { 219 locale: locale[$('#iframe-hero .container-card').data('lang')], 220 autoClose: true, 221 buttons: [conferma], 222 selectedDates: modalReturnDate, 223 minDate: modalReturnDate, 224 dateFormat: 'd MMM yyyy', 225 toggleSelected: false, 226 }) 227 228 setTimeout(() => { 229 todayDateRitorno.destroy() 230 }, '100') 231 } 232 } 233 234 }) 235 236 // $('#iframe-hero').on('click', function () { 237 // console.log("click") 238 // }) 239 240 // $('#iframe-hero').on('click', '.datapicker-inizio .air-datepicker-cell', function () { 241 // modalDepartureDate = dataInizio.focusDate 242 243 // console.log('departure', modalDepartureDate) 244 // console.log('return', modalReturnDate) 245 246 // if (compareDates(modalDepartureDate, modalReturnDate)) { 247 // modalReturnDate = modalDepartureDate 248 249 // const todayDateRitorno = new AirDatepicker('#iframe-hero #calendar-date-return', { 250 // locale: locale[$('#iframe-hero .container-card').data('lang')], 251 // autoClose: true, 252 // buttons: [conferma], 253 // selectedDates: modalReturnDate, 254 // minDate: modalReturnDate, 255 // dateFormat: 'd MMM yyyy', 256 // toggleSelected: false, 257 // }) 258 259 // setTimeout(() => { 260 // todayDateRitorno.destroy() 261 // }, '100') 262 // } 263 // }) 264 265 const htmlToAppend = ` 266 <div class="date-picker-dettaglio"> 267 <p>${WPURLS.string.partenza}</p> 268 <svg class="close-modal" width="15" height="15" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg"> 269 <path d="M-0.000151038 1.41421L1.41406 0L14.142 12.7279L12.7278 14.1421L-0.000151038 1.41421Z" fill="#292C7E"/> 270 <path d="M1.41421 14.1422L0 12.728L12.7279 0.0001055L14.1421 1.41432L1.41421 14.1422Z" fill="#292C7E"/> 271 </svg> 272 </div> 273 ` 274 $('#iframe-hero .datapicker-inizio .air-datepicker--navigation').prepend(htmlToAppend) 275 $('#iframe-hero .date-picker-dettaglio svg').on('click', function () { 276 dataInizio.destroy() 277 }) 278 }) 279 280 $('#iframe-hero').on('click', '#calendar-date-return', function () { 281 const dataFine = new AirDatepicker('#iframe-hero #calendar-date-return', { 282 locale: locale[$('.container-card').data('lang')], 283 inline: true, 284 buttons: [conferma], 285 dateFormat: 'd MMM yyyy', 286 minDate: modalDepartureDate, 287 classes: 'datapicker-fine', 288 selectedDates: modalReturnDate, 289 toggleSelected: false, 290 onSelect({date, formattedDate, datepicker}) { 291 modalReturnDate = dataFine.focusDate 292 $('#iframe-hero #calendar-date-return').attr('aria-label', WPURLS.string.data_ritorno + ': ' + formattedDate) 293 } 294 }) 295 296 // $('#iframe-hero').on('click', '.datapicker-fine .air-datepicker-cell.-day-', function () { 297 // modalReturnDate = dataFine.focusDate 298 // }) 299 300 const htmlToAppend = ` 301 <div class="date-picker-dettaglio"> 302 <p>${WPURLS.string.arrivo}</p> 303 <svg class="close-modal" width="15" height="15" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg"> 304 <path d="M-0.000151038 1.41421L1.41406 0L14.142 12.7279L12.7278 14.1421L-0.000151038 1.41421Z" fill="#292C7E"/> 305 <path d="M1.41421 14.1422L0 12.728L12.7279 0.0001055L14.1421 1.41432L1.41421 14.1422Z" fill="#292C7E"/> 306 </svg> 307 </div> 308 ` 309 $('#iframe-hero .datapicker-fine .air-datepicker--navigation').prepend(htmlToAppend) 310 $('#iframe-hero .date-picker-dettaglio svg').on('click', function () { 311 dataFine.destroy() 312 }) 313 }) 314 315 // Hide the loader 316 setTimeout(() => { 317 todayDateAndata.destroy() 318 todayDateRitorno.destroy() 319 }, '500') 320 321 $('#iframe-hero .iframe-modal .close-modal').on('click', function () { 322 $(this).closest('.iframe-modal').removeClass('open') 323 }) 324 325 $('#iframe-hero .modal-control').on('click', function () { 326 $('#iframe-hero .errore-passengers').remove() 327 328 if (parseInt($('#iframe-hero #select-adulti input').val()) > modalVeiclesSummary.length) { 329 $('#iframe-hero #select-adulti').find('.sub').removeClass('disable') 330 } else { 331 $('<div class="errore-passengers">Errore</div>').insertAfter('.adulti') 332 $('#iframe-hero #select-adulti').find('.sub').addClass('disable') 333 } 334 335 $('#iframe-hero .iframe-modal.' + $(this).data('modal')).addClass('open') 336 }) 337 338 $('#iframe-hero .vehicle').on('click', function () { 339 modalSelectors.map((select) => { 340 if (select.selector.data('select-type') == 'vehicle') { 341 select.selector.find('.number').text('0') 342 select.selector.find('input').val(0) 343 select.selector.val('') 344 } 345 }) 346 $('#iframe-hero .iframe-modal.' + $(this).data('vehicle')).addClass('open') 347 348 if (!$('#iframe-hero .iframe-modal.' + $(this).data('vehicle')).find('.number-select-container').length > 0) { 349 $('#iframe-hero .iframe-modal.' + $(this).data('vehicle')) 350 .find('.moda-footer .button-footer-modal') 351 .trigger('click') 352 } 353 }) 354 355 // CREATE AL DROPDOWN SELECT 356 $('#iframe-hero .number-select').each(function () { 357 const id = $(this).attr('id') 358 359 modalSelectors.push({ 360 slug: id, 361 selector: $(this), 362 }) 363 }) 364 365 const getSummaryVeicleList = (summaryString) => { 366 modalVeiclesSummary.map((item) => { 367 if (item.active) { 368 summaryString +=
369 '<li data-id-parent="' + 370 item.id + 371 '" data-vehicle="' + 372 item.slug + 373 '">' + 374 item.title + 375 ' <svg width="14" height="18" viewBox="0 0 14 18" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M14 1H10.5L9.5 0H4.5L3.5 1H0V3H14V1ZM1 4V16C1 17.1 1.9 18 3 18H11C12.1 18 13 17.1 13 16V4H1Z" fill="#C01E14"/></svg></li><ul class="ps-2">' 376 item.subFields.map((field) => { 377 if (field.type == 'string' && field.value.length > 0) { 378 summaryString += 379 '<li class="d-flex align-itemx-center justify-content-between" data-id-children="' + 380 item.id + 381 '" data-vehicle="' + 382 field.slug + 383 '" >' + 384 '<span>' + 385 field.title + 386 '</span>' + 387 '<span class="txt caps">' + 388 field.value + 389 '</span>' + 390 '</li>' 391 // <svg width="14" height="18" viewBox="0 0 14 18" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M14 1H10.5L9.5 0H4.5L3.5 1H0V3H14V1ZM1 4V16C1 17.1 1.9 18 3 18H11C12.1 18 13 17.1 13 16V4H1Z" fill="#C01E14"/></svg> 392 } 393 if (field.type == 'number' && field.value > 0) { 394 summaryString += '<li data-id-children="' + item.id + '" data-vehicle="' + field.slug + '" >' + '<span>' + field.title + '</span>' + '<span>' + field.value + '</span>' + '</li>' 395 // <svg width="14" height="18" viewBox="0 0 14 18" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M14 1H10.5L9.5 0H4.5L3.5 1H0V3H14V1ZM1 4V16C1 17.1 1.9 18 3 18H11C12.1 18 13 17.1 13 16V4H1Z" fill="#C01E14"/></svg> 396 } 397 }) 398 item.extra.map((element) => { 399 if (parseInt(element.quantity) > 0) { 400 for (let i = 0; i < element.quantity; i++) { 401 summaryString += 402 '<li data-id-children="' + 403 item.id + 404 '" data-vehicle="' + 405 element.slug + 406 '" >' + 407 element.title + 408 '<svg width="14" height="18" viewBox="0 0 14 18" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M14 1H10.5L9.5 0H4.5L3.5 1H0V3H14V1ZM1 4V16C1 17.1 1.9 18 3 18H11C12.1 18 13 17.1 13 16V4H1Z" fill="#C01E14"/></svg></li>' 409 } 410 } 411 }) 412 summaryString += '</ul>' 413 } 414 }) 415 return summaryString 416 } 417 418 const printSummary = () => { 419 $('#iframe-hero .iframe-modal.vehicles .summary ul').remove() 420 $('#iframe-hero .iframe-modal.vehicles .summary-footer').remove() 421 let summaryString = '<ul>' 422 423 summaryString = getSummaryVeicleList(summaryString) 424 425 summaryString += '</ul>' 426 427 $('#iframe-hero .iframe-modal.vehicles .summary').append(summaryString) 428 429 if ($('#iframe-hero .iframe-modal.vehicles .summary').find('li').length) { 430 $('#iframe-hero .iframe-modal.vehicles .modal-title').first().text(WPURLS.string.vehicles_selezionati_str) 431 $('#iframe-hero .iframe-modal.vehicles .summary').after(` 432 <div class="summary-footer d-flex justify-content-between align-items-center"> 433 <span class="summary-footer-titolo txt testo-piccolo blu-navy">${WPURLS.string.altri_vehicles_str}</span> 434 </div> 435 `) 436 } 437 438 $('#iframe-hero .iframe-modal.vehicles .summary li svg').on('click', function () { 439 $(this).parent().remove() 440 // $(this).remove() 441 const id = $(this).parent().data('id-parent') 442 if (id) { 443 $('li').each(function () { 444 if ($(this).data('id-children') == id) { 445 $(this).remove() 446 } 447 }) 448 } 449 450 checkUpdate($(this).parent().data('vehicle')) 451 if (!$('#iframe-hero .iframe-modal.vehicles .summary').find('li').length) { 452 $('#iframe-hero .iframe-modal.vehicles .summary-footer').remove() 453 $('#iframe-hero .iframe-modal.vehicles .modal-title').first().text(WPURLS.string.vehicles_str) 454 } 455 456 if (modalVeiclesSummary.length < $('#iframe-hero #select-adulti input').val()) { 457 $('#iframe-hero .vehicle').removeClass('disable') 458 } else { 459 $('#iframe-hero .vehicle').addClass('disable') 460 } 461 }) 462 } 463 464 const checkUpdate = (text) => { 465 466 modalVeiclesSummary.map((item, index) => { 467 if (item.slug == text) { 468 // item.active = false 469 modalVeiclesSummary.splice(index, 1) 470 } 471 item.extra.map((element) => { 472 if (element.slug == text || item.active == false) { 473 element.quantity = 0 474 modalSelectors.map((select) => { 475 if (select.slug == element.slug) { 476 select.selector.find('.number').text('0') 477 select.selector.find('input').val(0) 478 } 479 }) 480 } 481 }) 482 }) 483 } 484 485 const summarizeVeicles = (myThis) => { 486 const title = myThis.closest('#iframe-hero .iframe-modal').find('.iframe-modal-header').find('.modal
486-title').text() 487 const slug = myThis.closest('#iframe-hero .iframe-modal').attr('class').replace('iframe-modal', '').trim() 488 489 const id = makeID(10) 490 491 const vehicle = { 492 id: id, 493 slug: slug, 494 active: true, 495 title: title, 496 extra: [], 497 subFields: [], 498 } 499 500 myThis 501 .closest('#iframe-hero .iframe-modal') 502 .find('[data-subfield]') 503 .each(function () { 504 const slug = $(this).attr('data-subfield') 505 const title = $(this).attr('data-title') 506 const type = $(this).attr('data-type') 507 const value = $(this).val() 508 vehicle.subFields.push({ 509 slug, 510 title, 511 value, 512 type, 513 }) 514 }) 515 516 modalSelectors.map((selector) => { 517 if (selector.slug.includes(slug.split(' ')[0]) && typeof selector.selector.data('subfield') == 'undefined') { 518 519 // Supporto per trailer-length 520 // if selector.slug contains trailer-length 521 if (selector.slug.includes('trailer-length')) { 522 523 let input = selector.selector.find('input'); 524 let trailer = input.closest('.trailer-select-container'); 525 let select = trailer.find('select'); 526 let trailerType = select.find('option:selected').val(); 527 if(trailerType){ 528 // get the label of the selected option 529 let trailerTypeLabel = trailer.find('select option:selected').text(); 530 let trailerLength = selector.selector.find('input').val() 531 const extrasvehicle = { 532 title: trailerTypeLabel, 533 type: 'trailer', 534 subtype: trailerType, 535 quantity: 1, 536 length: trailerLength, 537 slug: selector.slug, 538 } 539 vehicle.extra.push(extrasvehicle) 540 } 541 542 } else { 543 const extrasvehicle = { 544 title: $('#' + selector.slug) 545 .parent() 546 .find('.titoletto') 547 .text(), 548 quantity: selector.selector.find('input').val(), 549 slug: selector.slug, 550 } 551 vehicle.extra.push(extrasvehicle) 552 } 553 554 } 555 }) 556 557 modalVeiclesSummary.push(vehicle) 558 559 checkUpdate() 560 printSummary() 561 } 562 563 // DESTINAZIONI 564 $('#iframe-hero .confirm-button').on('click', function () { 565 $(this).closest('#iframe-hero .iframe-modal').removeClass('open') 566 567 modalTotalepassengers = 0 568 $('#iframe-hero .iframe-modal.passengers') 569 .find('.number') 570 .each(function () { 571 modalTotalepassengers += parseInt($(this).text()) 572 }) 573 574 $('#iframe-hero .modal-control-passengers .totale .tot-passengers').remove() 575 $('#iframe-hero .modal-control-vehicles .totale .tot-vehicles').remove() 576 577 displayPassengers() 578 579 displayvehicles() 580 581 if (modalVeiclesSummary.length < $('#iframe-hero #select-adulti input').val()) { 582 $('#iframe-hero .vehicle').removeClass('disable') 583 } else { 584 $('#iframe-hero .vehicle').addClass('disable') 585 } 586 }) 587 588 $('#iframe-hero .close-modal').on('click', function () { 589 $(this).closest('#iframe-hero .iframe-modal').removeClass('open') 590 591 modalTotalepassengers = 0 592 $('#iframe-hero .iframe-modal.passengers') 593 .find('.number') 594 .each(function () { 595 modalTotalepassengers += parseInt($(this).text()) 596 }) 597 598 $('#iframe-hero .modal-control-passengers .totale .tot-passengers').remove() 599 $('#iframe-hero .modal-control-vehicles .totale .tot-vehicles').remove() 600 601 displayPassengers() 602 603 displayvehicles() 604 605 if (modalVeiclesSummary.length < $('#iframe-hero #select-adulti input').val()) { 606 $('#iframe-hero .vehicle').removeClass('disable') 607 } else { 608 $('#iframe-hero .vehicle').addClass('disable') 609 } 610 }) 611 612 $('#iframe-hero .confirm-button-vehicle').on('click', function () { 613 if ($(this).closest('#iframe-hero .iframe-modal').find(':input[required]').length) { 614 let inputRequired = $(this).closest('#iframe-hero .iframe-modal').find(':input[required]') 615 if (inputRequired.val() >= 4 && inputRequired.val() <= 12) { 616 summarizeVeicles($(this)) 617 $(this).closest('.iframe-modal').removeClass('open') 618 inputRequired.removeClass('error-required') 619 inputRequired.parent().removeClass('error-required') 620 $('.required-message').remove() 621 } else { 622 inputRequired.addClass('error-required') 623 inputRequired.parent().addClass('error-required') 624 // inputRequired.parent().parent().append('<p class="required-message">campo richiesto</p>') 625 } 626 } else { 627 summarizeVeicles($(this)) 628 $(':input[required]').removeClass('error-required') 629 $(':input[required]').parent().removeClass('error-required') 630 $(this).closest('.iframe-modal').removeClass('open') 631 } 632
633 if (modalVeiclesSummary.length < $('#iframe-hero #select-adulti input').val()) { 634 $('#iframe-hero .vehicle').removeClass('disable') 635 } else { 636 $('#iframe-hero .vehicle').addClass('disable') 637 } 638 }) 639 640 $('#iframe-hero .form-button-search').on('click', function () { 641 /* 642 * Widget che trovo in home 643 * 644 * URL Refs.: 645 * base_url = https://booking.blunavytraghetti.com/ 646 * - from/Portoferraio/230224/to/Piombino?adulti=1&hl=it 647 * - from/Portoferraio/230224/to/Piombino/230226?adulti=1&hl=it 648 * */ 649 650 // let bookingUrl = 'https://booking.blunavytraghetti.com/from/' 651 652 let language = $('.container-card').data('lang') 653 654 if (language != 'it' && language != 'fr' && language != 'de') { 655 language = 'en' 656 } 657 658 //let bookingUrl = 'https://booking.blunavytraghetti.com/' + language + '/from/' 659 let bookingUrl = WPURLS.bookingUrl; 660 bookingUrl += language + '/from/'; 661 662 663 // bookingUrl += '&hl=' + $('.container-card').data('lang') 664 665 let from = 'Piombino'; 666 667 if ($('#iframe-hero .calendar-departure-city-from-select').val()) { 668 from = $('#iframe-hero .calendar-departure-city-from-select').val(); 669 } 670 671 let to = 'Portoferraio'; 672 673 if ($('#iframe-hero .calendar-departure-city-to-name').text()) { 674 to = $('#iframe-hero .calendar-departure-city-to-name').text(); 675 } 676 677 678 const myDate = new Date(modalDepartureDate); 679 const year = (myDate.getFullYear() + '').match(/\d{2}$/);
680 const month = myDate.getMonth() + 1 < 10 ? '0' + (myDate.getMonth() + 1) : myDate.getMonth() + 1; 681 const day = myDate.getDate() < 10 ? '0' + myDate.getDate() : myDate.getDate(); 682 const myDeparture = year[0] + month + day; 683 const myDepartureFormatted = year[0] + '/' + month + '/' + day; 684 let myReturnFormatted = null; 685 let veicolo = null; 686 let passengersIndex = 0 687 688 689 690 bookingUrl += from + '/' + myDeparture + '/to/' + to; 691 692 if ($('#iframe-hero .form-check-input:checked').val() == 'AR') { 693 const myDate = new Date(modalReturnDate); 694 const year = (myDate.getFullYear() + '').match(/\d{2}$/); 695 const month = myDate.getMonth() + 1 < 10 ? '0' + (myDate.getMonth() + 1) : myDate.getMonth() + 1; 696 const day = myDate.getDate() < 10 ? '0' + myDate.getDate() : myDate.getDate(); 697 const myReturn = year[0] + month + day; 698 myReturnFormatted = year[0] + month + day; 699 bookingUrl += '/' + myReturn 700 } 701 702 if (modalVeiclesSummary.length == 0) { 703 let passengers = '' 704 $('#iframe-hero .iframe-modal.passengers .iframe-modal-main .passenger').each(function () { 705 if ($(this).find('input').val() > 0) { 706 passengers += $(this).data('passenger') + '=' + $(this).find('input').val() + '&' 707 } 708 }) 709 bookingUrl += '?' + passengers 710 } else { 711 selectedFareCategories = [] 712 713 $('#iframe-hero .iframe-modal.passengers .iframe-modal-main .passenger').each(function () { 714 let count = $(this).find('input').val() 715 if (count > 0) { 716 for (let i = 0; i < count; i++) { 717 let passenger = { ...passengersLegend[$(this).data('passenger')] } 718 passenger.subGroupId = passengersIndex 719 selectedFareCategories.push(passenger) 720 passengersIndex += 1 721 } 722 } 723 }) 724 725 vehiclesCount = 0; 726 727 modalVeiclesSummary.map((vehicle) => { 728 veicolo = { ...vehiclesLegend[vehicle.slug.replaceAll('-', '_').split(' ')[0]] } 729 veicolo.subGroupId = vehiclesCount 730 selectedFareCategories.push(veicolo) 731 732 vehicle.subFields.map((sub) => { 733 veicolo['extra'][sub.slug] = sub.value 734 }) 735 736 737 // ! verifica la struttura per il rimorchio, quindi aggiungi l'equivalente e la sua lunghezza 738 739 vehicle.extra.map((extras) => { 740 let count = extras.quantity 741 if (count > 0) { 742 for (let i = 0; i < count; i++) { 743 let extraSlugs = extras.slug.split('-') 744 let extra = {} 745 if(extraSlugs[extraSlugs.length - 1] == 'extra'){ 746 extra = { ...vehiclesLegend[extraSlugs[extraSlugs.length - 1]] } 747 } else { 748 let type = extras.subtype 749 extra = { ...vehiclesLegend[type] } 750 extra.extra.Lunghezza = extras.length 751 } 752 extra.subGroupId = vehiclesCount 753 selectedFareCategories.push(extra) 754 } 755 } 756 }) 757 758 vehiclesCount++; 759 }) 760 761 const searchJSON = `?selectedFareCategories=${encodeURIComponent(JSON.stringify(selectedFareCategories))}`; 762 763 bookingUrl += searchJSON; 764 765 766 767 } 768 769 770 const form = $(this).closest('form') 771 const coupon = form.find('input[name=coupon]').val() 772 if (coupon) { 773 bookingUrl += '&referral=' + coupon 774 } 775 776 // bookingUrl += '&hl=' + $('.container-card').data('lang') 777 778 let GTMdate = myDepartureFormatted; 779 780 if (myReturnFormatted) { 781 GTMdate += ' - ' + myReturnFormatted; 782 } 783 784 dataLayer.push({ 785 'event': 'cerca_widget', 786 'type': $('#iframe .form-check-input:checked').val(), //Selezione Andata o Andata e ritorno 787 'departure_return': from + '-' + to, //Selezione Piombino-Portoferraio o Portoferraio-Piombino 788 'date': GTMdate, //Selezione intervallo date 789 'passengers': passengersIndex, //Selezione numero passeggeri 790 'vehicles': veicolo, //Selezione veicoli(auto, moto, camper) 791 'discount_code': coupon, //Applicazione codice sconto 792 'hotel': window.location.href //Pagina in cui si trova lâiframe (URL) 793 }); 794 795 window.open(bookingUrl, '_blank') 796 }) 797 798 799 800 801 // Lazy load video if exists: 802 if ($('#hero-landing-video').length) { 803 var video = document.getElementById("hero-landing-video"); 804 var source = video.getElementsByTagName("source")[0]; 805 var src = source.attributes['data-src'].value; 806 var srcMobile = source.attributes['data-src-mobile'].value; 807 if(window.innerWidth < 768){ 808 src = srcMobile; 809 } 810 // set the source to the video tag 811 video.getElementsByTagName("source")[0].src = src; 812 // video load 813 video.load(); 814 video.play(); 815 // add class active 816 $('#hero-landing-video').addClass('active'); 817 } 818 819 // Lazy load video if exists: 820 if ($('#homepage-hero video').length) { 821 822 // Get all videos od homepage-hero 823 var videos = document.querySelectorAll("#homepage-hero video"); 824 825 // Loop through all videos 826 videos.forEach(function(video){ 827 var source = video.getElementsByTagName("source")[0]; 828 var src = source.attributes['data-src'].value; 829 var srcMobile = source.attributes['data-src-mobile'].value; 830 if(window.innerWidth < 768){ 831 src = srcMobile; 832 } 833 // set the source to the video tag 834 video.getElementsByTagName("source")[0].src = src; 835 // video load 836 video.load(); 837 video.play(); 838 }) 839 840 } 841 842}) 843 844
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.