WPR FM
uid=9814(b13i2mwmyrdbxio) php=8.4.28
info
cwd /data/sites/web/b13i2mwmyrdbxio/www |
naik
Buka
-
flip.min.js
57322
x
-
script.js
7846
x
-
shortcode-form.js
10905
x
Upload
Simpan
function buildPlaceListItem(place) { return ` <li> <div class="partner-place-item"> <input name="google-place-id" type="radio" value="${place.id}"> <div> <strong><a href="${place.googleMapsUri}" target="_blank">${place.name}</a></strong> <small>${place.address}</small> </div> </div> </li> `; } jQuery(document).ready(function ($) { const countrySelect = $('#country'); const billingCountrySelect = $('#billing-country'); const sameAsCompanyCheckbox = $('#same-as-company'); const form = $('.partner-form-v2'); const storageKey = 'rtt_form_backup'; let selectedLogo; function saveToLocalStorage() { const formData = {}; form.serializeArray().forEach(function (item) { if (item.name === 'platform[]') { if (!formData[item.name]) formData[item.name] = []; formData[item.name].push(item.value); } else { formData[item.name] = item.value; } }); // Checkboxes like same-as-company might not be in serializeArray if not checked formData['same-as-company'] = sameAsCompanyCheckbox.is(':checked'); formData['already-customer'] = $('#already-customer').is(':checked'); formData['sepa-notice-read'] = $('#sepa-notice-read').is(':checked'); localStorage.setItem(storageKey, JSON.stringify(formData)); } function loadFromLocalStorage() { const savedData = localStorage.getItem(storageKey); if (!savedData) return; const formData = JSON.parse(savedData); // Populate fields Object.keys(formData).forEach(key => { const value = formData[key]; const element = form.find(`[name="${key}"]`); if (element.is(':checkbox')) { if (Array.isArray(value)) { element.each(function () { $(this).prop('checked', value.includes($(this).val())).trigger('change'); }); } else { element.prop('checked', value).trigger('change'); } } else if (element.is(':radio')) { element.filter(`[value="${value}"]`).prop('checked', true).trigger('change'); } else { element.val(value).trigger('change'); } }); } const countryFallback = [ { code: 'DE', name: 'Deutschland' }, { code: 'AT', name: 'Österreich' }, { code: 'CH', name: 'Schweiz' }, { code: 'LU', name: 'Luxemburg' }, { code: 'LI', name: 'Liechtenstein' } ]; function populateCountries(countries) { countrySelect.find('option:not([value=""])').remove(); billingCountrySelect.find('option:not([value=""])').remove(); countries.forEach(country => { const option = `<option value="${country.code}" ${country.code === 'DE' ? 'selected' : ''}>${country.name}</option>`; countrySelect.append(option); billingCountrySelect.append(option); }); loadFromLocalStorage(); sameAsCompanyCheckbox.trigger('change'); } $.ajax({ url: `${rtt_form_vars.plugin_url}/public/countries.json`, timeout: 5000, success: function (countries) { const formattedCountries = countries .map(country => ({ code: country.cca2, name: country.translations.deu?.common ?? country.name.common })) .sort((a, b) => a.name.localeCompare(b.name)); populateCountries(formattedCountries); }, error: function () { console.warn('Local countries.json unreachable, using fallback.'); populateCountries(countryFallback); } }); form.on('input change', 'input, select, textarea', function () { saveToLocalStorage(); }); $(globalThis).on('beforeunload', function () { const savedData = localStorage.getItem(storageKey); if (savedData) { // Check if there is actual data worth warning about const formData = JSON.parse(savedData); const hasData = Object.values(formData).some(val => (Array.isArray(val) && val.length > 0) || (typeof val === 'string' && val.trim() !== '') || (typeof val === 'boolean' && val === true) ); if (hasData) return 'Sie haben nicht gespeicherte Änderungen. Möchten Sie die Seite wirklich verlassen?'; } }); $('#already-customer').change(function () { const customerNumberWrapper = $('#customer-number-wrapper'); const isChecked = $(this).prop('checked'); $('#customer-number').prop('required', isChecked); if (isChecked) customerNumberWrapper.show(); else customerNumberWrapper.hide(); }); $('input[name="platform[]"]').change(function () { const googleChecked = $('#platform-google').is(':checked'); const trustpilotChecked = $('#platform-trustpilot').is(':checked'); const googleSection = $('#google-search-query-section, #google-search-button-section'); const trustpilotSection = $('#trustpilot-section'); if (googleChecked) googleSection.show(); else googleSection.hide(); $('#trustpilot-url').prop('required', trustpilotChecked); if (trustpilotChecked) trustpilotSection.show(); else trustpilotSection.hide(); }); $('#google-place-search').click(function () { const googlePlaceResults = $('#google-place-results'); googlePlaceResults.empty(); const nameInput = $('#google-search-query'); const name = nameInput.val(); if (!name) { nameInput.addClass('is-invalid'); return; } $.ajax({ url: rtt_form_vars.ajax_url, method: 'POST', data: { action: 'search_google_place', query: name }, success: function (places) { if (Array.isArray(places) && places.length > 0) { places .map(place => buildPlaceListItem(place)) .forEach(place => googlePlaceResults.append(place)); } else googlePlaceResults.append('<li><small>Keine Ergebnisse gefunden. Bitte nutzen Sie die manuelle Eingabe unten (siehe Anleitung).</small></li>'); $('#google-url-wrapper').show(); }, error: function () { googlePlaceResults.append('<li><small>Suche aktuell nicht verfügbar. Bitte nutzen Sie die manuelle Eingabe unten (siehe Anleitung).</small></li>'); $('#google-url-wrapper').show(); } }); }); $('#logo').change(function () { const files = $(this)[0].files; if (files?.length) { const logo = files[0]; const reader = new FileReader(); reader.readAsDataURL(logo); reader.onload = function () { [, selectedLogo] = reader.result.split(','); // Remove data URL prefix }; } }); const sepaModal = $('#sepa-modal'); $('#sepa-modal-trigger').click(function (e) { e.preventDefault(); sepaModal.css('display', 'flex'); }); $('.partner-modal-close').click(function () { sepaModal.hide(); }); $(globalThis).click(function (event) { if (event.target === sepaModal[0]) { sepaModal.hide(); } }); const screenshotModal = $('#screenshot-modal'); const screenshotFull = $('#screenshot-full'); $('.rtt-screenshot-trigger').click(function (e) { e.preventDefault(); const imageName = $(this).data('image'); const imageUrl = `${rtt_form_vars.plugin_url}/public/${imageName}`; screenshotFull.attr('src', imageUrl); screenshotModal.css('display', 'flex'); }); $('#close-screenshot-modal').click(function () { screenshotModal.hide(); }); $(globalThis).click(function (event) { if (event.target === screenshotModal[0]) { screenshotModal.hide(); } }); sameAsCompanyCheckbox.change(function () { const isChecked = $(this).prop('checked'); const billingAddressWrapper = $('#billing-address-wrapper'); if (isChecked) billingAddressWrapper.hide(); else billingAddressWrapper.show(); // Toggle required attribute for billing fields when visible billingAddressWrapper.find('input, select').each(function () { if ($(this).attr('id') !== 'billing-street2') { $(this).prop('required', !isChecked); } }); }); $('#submit-button').click(function (e) { e.preventDefault(); const form = $('form'); function clearValidationErrors() { form.find('*').each(function () { $(this).removeClass('is-invalid'); }); $('#google-place-results').removeClass('is-invalid-google'); $('input[name="platform[]"]').closest('.partner-grid').removeClass('is-invalid-platform'); $('#error-message').hide().text(''); } function checkRequiredFields() { let isValid = true; form.find('[required]:visible').each(function () { const isFieldValid = this.type === 'checkbox' ? this.checked : this.value; if (isFieldValid) { $(this).removeClass('is-invalid'); } else { isValid = false; $(this).addClass('is-invalid'); } }); // Check if at least one platform is selected const platforms = $('input[name="platform[]"]:checked'); if (platforms.length === 0) { isValid = false; $('input[name="platform[]"]').closest('.partner-grid').addClass('is-invalid-platform'); } // Check Google platform requirements if ($('#platform-google').is(':checked')) { const googleUrlInput = $('#google-url'); const googlePlaceSelected = $('input[name="google-place-id"]:checked').length > 0; const googleUrlEntered = googleUrlInput.val().trim() !== ''; if (!googlePlaceSelected && !googleUrlEntered) { isValid = false; $('#google-place-results').addClass('is-invalid-google'); googleUrlInput.addClass('is-invalid'); const errorMessage = $('#error-message'); errorMessage.text('Bitte wählen Sie einen Google Place Eintrag aus oder geben Sie eine Google-URL ein.'); errorMessage.show(); } } return isValid; } function extractFormFields() { const formData = {}; form.serializeArray().forEach(function (item) { formData[item.name] = item.value.trim() === '' ? null : item.value.trim(); }); formData['logo'] = selectedLogo; return formData; } clearValidationErrors(); let isValid = checkRequiredFields(); if (!isValid) return; const formData = extractFormFields(); function submitForm() { $.ajax({ url: rtt_form_vars.ajax_url, method: 'POST', data: { action: 'submit_form', ...formData }, success: function (response) { if (response?.message) { const errorMessage = $('#error-message'); errorMessage.text(response.message); errorMessage.show(); } else { localStorage.removeItem(storageKey); window.open(rtt_form_vars.redirect_url, '_self'); } } }); } submitForm(); }); });
Exec