1(function(){ 2 function hideElement(el){ 3 if (!el) return; 4 el.style.display = 'none'; 5 el.setAttribute && el.setAttribute('aria-hidden', 'true'); 6 } 7 8 function applyRule(rule, labelText) { 9 var id = rule.field_id; 10 if (!id) return; 11 var el = document.getElementById(id); 12 if (!el) return; 13 14 var label = document.querySelector('label[for="'+id+'"]'); 15 var isHidden = parseInt(rule.hidden || 0, 10) === 1; 16 var isRequired = parseInt(rule.required || 0, 10) === 1; 17 var addLabel = parseInt(rule.add_label || 0, 10) === 1; 18 19 if (isHidden) { 20 if (el.tagName && el.tagName.toLowerCase() === 'input') { 21 el.setAttribute('type', 'hidden'); 22 } else { 23 hideElement(el); 24 } 25 if (label) hideElement(label); 26 27 el.removeAttribute('required'); 28 el.removeAttribute('aria-required'); 29 30 // cleanup any helper 31 var next = el.nextElementSibling; 32 if (next && next.classList && next.classList.contains('wff-helper-required')) next.remove(); 33 if (label) { 34 var tag = label.querySelector('.wff-tag-required'); 35 if (tag) tag.remove(); 36 } 37 return; 38 } 39 40 if (isRequired) { 41 el.setAttribute('required', 'required'); 42 el.setAttribute('aria-required', 'true'); 43 if (addLabel) { 44 if (!label) { 45 var helper = document.createElement('small'); 46 helper.className = 'wff-helper-required'; 47 helper.innerText = labelText || 'campo obrigatório'; 48 helper.style.display = 'block'; 49 helper.style.marginTop = '4px'; 50 helper.style.fontSize = '12px'; 51 helper.style.opacity = '0.8'; 52 el.insertAdjacentElement('afterend', helper); 53 } else { 54 var existed = label.querySelector('.wff-tag-required'); 55 if (!existed) { 56 var tag = document.createElement('span'); 57 tag.className = 'wff-tag-required'; 58 tag.innerText = ' (' + (labelText || 'campo obrigatório') + ')'; 59 label.appendChild(tag); 60 } 61 } 62 } 63 } else { 64 el.removeAttribute('required'); 65 el.removeAttribute('aria-required'); 66 var next = el.nextElementSibling; 67 if (next && next.classList && next.classList.contains('wff-helper-required')) next.remove(); 68 if (label) { 69 var tag = label.querySelector('.wff-tag-required'); 70 if (tag) tag.remove(); 71 } 72 } 73 } 74 75 function run(){ 76 if (typeof wffmSettings === 'undefined' || !Array.isArray(wffmSettings.rules)) return; 77 var labelText = wffmSettings.labelText || 'campo obrigatório'; 78 for (var i=0; i<wffmSettings.rules.length; i++) { 79 applyRule(wffmSettings.rules[i], labelText); 80 } 81 } 82 83 if (document.readyState === 'loading') { 84 document.addEventListener('DOMContentLoaded', run); 85 } else { 86 run(); 87 } 88})();
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.