jQuery.noConflict(); (function ($) { $(function () { let googleMapsLoaded = false; // Map variables var selectedLat = '0'; var selectedLng = '0'; var selectedAddress = ''; var selectedAddressValue = ''; var schoolPlaceId = ''; var abortSignals = []; window.addEventListener("message", (e) => { if (e.data.type === "hsFormCallback" && e.data.eventName === "onFormReady") { // Google Maps API deferred loading once if(!googleMapsLoaded){ loadGoogleMaps(); } // Modify each form $("form.hs-form").each(function(index) { if($(this).find("#schools-search-"+index).length === 0){ if($(this).hasClass( 'plugin-modified' )){ return; } // Get inputs references $(this).attr("autocomplete", "off"); $(this).addClass("plugin-identifier-"+index); $(this).addClass("plugin-modified"); const schoolInput = $(this).find("[name='company']"); const placeIDInput = $(this).find("[name='place_id']"); const addressInput = $(this).find("[name='address']"); const newSchoolInput = $(this).find("[name='colegio_nuevo']"); $(this).data('case','selected-school' ) // only these cases: 'selected-school' | 'add-school' // Kill if inputs are not complete if ( !schoolInput || schoolInput.length === 0 || !placeIDInput || placeIDInput.length === 0 || !addressInput || addressInput.length === 0 || !newSchoolInput || newSchoolInput.length === 0 ) { return; } console.log('Form is beign modified', index) // Initial setup schoolInput.prop('readonly',true); schoolInput.attr('style', 'display:none'); addressInput.attr('style', 'display:none'); const schoolParent = schoolInput.parent("div.input"); const searchIcon = ``; schoolParent.prepend( `
Ubicación confirmada:
Dirección: ${selectedAddress}
`); placeIdInputRef.val(schoolPlaceId); placeIdInputRef.trigger('change') $('#addressText-'+index).html("Dirección: " + selectedAddress); $('#addressText-'+index).attr('style', 'display:block;'); toggleShowSchoolConfirmed(true,index); } if (flowCase === 'add-school') { addressRef.val(selectedAddressValue) addressRef.trigger('change') } $("#schools-search-"+index).attr( "style", "overflow:hidden;max-height:0;width:100%;visibility:hidden;opacity:0;margin-bottom:18px" ); } } // Search functions function performSearch(e, formRef, index) { abortSignals.map((controller) => { controller.abort(); abortSignals.splice(0, 1); }); if (e.target.value.length > 3) { if ($(formRef).find(".container-search .spinner").length === 0) { $(formRef).find(".container-search").append( 'Añade el nombre del colegio
`; const schoolInputRef = $(`.plugin-identifier-${index} [name='company']`); const schoolParentRef = schoolInputRef.parent("div.input"); schoolParentRef[0].insertBefore(addSchoolNameElDiv, schoolInputRef[0]); } // Toogle functions function toggleAddSchoolTextVisibility(visible = false,index) { let addSchoolNameEl = $('#addSchoolNameText-'+index)[0]; if (!!addSchoolNameEl) { if (!visible) { addSchoolNameEl.style.display = 'none'; addSchoolNameEl.style.visibility = 'hidden'; addSchoolNameEl.style.opacity = '0'; } else { addSchoolNameEl.style.display = 'block'; addSchoolNameEl.style.visibility = 'visible'; addSchoolNameEl.style.opacity = '1'; } } } function toggleSelectSchoolLocationTextVisibility(visible = false,index) { let selectSchoolLocationEl = $('#selectSchoolLocationText-'+index)[0]; if (!!selectSchoolLocationEl) { if (!visible) { selectSchoolLocationEl.style.display = 'none'; selectSchoolLocationEl.style.visibility = 'hidden'; selectSchoolLocationEl.style.opacity = '0'; } else { selectSchoolLocationEl.style.display = 'block'; selectSchoolLocationEl.style.visibility = 'visible'; selectSchoolLocationEl.style.opacity = '1'; } } } function toggleConfirmBtn(visible = false,index) { const confirmLocationBtn = $("#confirmLocationBtn-"+index)[0]; const confirmLocationText = $("#confirmLocationText-"+index)[0]; if (!!confirmLocationBtn && !!confirmLocationText) { if (!visible) { confirmLocationBtn.style.display = "none"; confirmLocationText.style.visibility = "visible"; confirmLocationText.style.opacity = "1"; } else { confirmLocationBtn.style.display = "block"; confirmLocationText.style.visibility = "hidden"; confirmLocationText.style.opacity = "0"; } } } function toggleShowAddress(visible = false, index, addressContainer) { const addressItems = $("#addressItems-"+index)[0]; if (!!addressContainer && !!addressItems) { if (!visible) { if (addressItems.classList.contains('visible')) { addressItems.classList.remove('visible'); } } else { if (!addressItems.classList.contains('visible')) { addressItems.classList.add('visible'); } } } } function toggleShowSchoolConfirmed(visible = false, index) { const addressConfirmed = $("#addressConfirmed-"+index)[0]; if (!!addressConfirmed) { if (!visible) { addressConfirmed.style.display = 'none'; } else { addressConfirmed.style.display = 'block'; } } } }) // ----Script Functions---- function loadGoogleMaps() { var apiKey = 'AIzaSyDo_NiA2rfp6hUsAssFFBWtTKgnJUtS68s'; var script = document.createElement('script'); script.src = 'https://maps.googleapis.com/maps/api/js?key=' + apiKey+'&loading=async'; script.async = true; document.head.appendChild(script); googleMapsLoaded = true; } } }); }); })(jQuery);