1/* Loonymoon Email Gate â frontend toggles. Vanilla JS, no deps. */ 2(function () { 3 'use strict'; 4 5 function ready(fn) { 6 if (document.readyState !== 'loading') { 7 fn(); 8 } else { 9 document.addEventListener('DOMContentLoaded', fn); 10 } 11 } 12 13 function initForm(form) { 14 var channelInput = form.querySelector('input[name="contact_type"]'); 15 var emailField = form.querySelector('.lmeg-field-email'); 16 var phoneField = form.querySelector('.lmeg-field-phone'); 17 var emailInput = form.querySelector('input[name="email"]'); 18 var phoneInput = form.querySelector('input[name="phone"]'); 19 var countrySel = form.querySelector('select[name="phone_country"]'); 20 var dialBadge = form.querySelector('.lmeg-dial'); 21 22 function setChannel(channel) { 23 channelInput.value = channel; 24 form.querySelectorAll('.lmeg-tab').forEach(function (t) { 25 var active = t.dataset.channel === channel; 26 t.classList.toggle('is-active', active); 27 t.setAttribute('aria-selected', active ? 'true' : 'false'); 28 }); 29 if (channel === 'phone') { 30 emailField.hidden = true; 31 phoneField.hidden = false; 32 if (emailInput) emailInput.required = false; 33 if (phoneInput) phoneInput.required = true; 34 } else { 35 emailField.hidden = false; 36 phoneField.hidden = true; 37 if (emailInput) emailInput.required = true; 38 if (phoneInput) phoneInput.required = false; 39 } 40 } 41 42 form.querySelectorAll('.lmeg-tab').forEach(function (t) { 43 t.addEventListener('click', function (e) { 44 e.preventDefault(); 45 setChannel(t.dataset.channel); 46 }); 47 }); 48 49 if (countrySel && dialBadge) { 50 var updateDial = function () { 51 var opt = countrySel.options[countrySel.selectedIndex]; 52 dialBadge.textContent = opt ? '+' + opt.dataset.dial : ''; 53 }; 54 countrySel.addEventListener('change', updateDial); 55 updateDial(); 56 } 57 58 // Address fields collapsible 59 var addrToggle = form.querySelector('.lmeg-address-toggle'); 60 var addrBlock = form.querySelector('.lmeg-address-block'); 61 if (addrToggle && addrBlock) { 62 addrToggle.addEventListener('click', function (e) { 63 e.preventDefault(); 64 var open = !addrBlock.hidden; 65 addrBlock.hidden = open; 66 addrToggle.setAttribute('aria-expanded', open ? 'false' : 'true'); 67 addrToggle.classList.toggle('is-open', !open); 68 }); 69 } 70 71 // Sync hidden iso field with country dropdown 72 if (countrySel) { 73 var isoInput = form.querySelector('input[name="phone_country_iso"]'); 74 var syncIso = function () { 75 var opt = countrySel.options[countrySel.selectedIndex]; 76 if (isoInput && opt) isoInput.value = opt.value; 77 }; 78 countrySel.addEventListener('change', syncIso); 79 syncIso(); 80 } 81 } 82 83 ready(function () { 84 document.querySelectorAll('.lmeg-form').forEach(initForm); 85 }); 86})();
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.