FossilRepo
| afe42d0… | ragelink | 1 | "use strict"; |
| afe42d0… | ragelink | 2 | // Fallback JS for browsers which do not support :has selector used in |
| afe42d0… | ragelink | 3 | // admin/css/unusable_password_fields.css |
| afe42d0… | ragelink | 4 | // Remove file once all supported browsers support :has selector |
| afe42d0… | ragelink | 5 | try { |
| afe42d0… | ragelink | 6 | // If browser does not support :has selector this will raise an error |
| afe42d0… | ragelink | 7 | document.querySelector("form:has(input)"); |
| afe42d0… | ragelink | 8 | } catch (error) { |
| afe42d0… | ragelink | 9 | console.log("Defaulting to javascript for usable password form management: " + error); |
| afe42d0… | ragelink | 10 | // JS replacement for unsupported :has selector |
| afe42d0… | ragelink | 11 | document.querySelectorAll('input[name="usable_password"]').forEach(option => { |
| afe42d0… | ragelink | 12 | option.addEventListener('change', function() { |
| afe42d0… | ragelink | 13 | const usablePassword = (this.value === "true" ? this.checked : !this.checked); |
| afe42d0… | ragelink | 14 | const submit1 = document.querySelector('input[type="submit"].set-password'); |
| afe42d0… | ragelink | 15 | const submit2 = document.querySelector('input[type="submit"].unset-password'); |
| afe42d0… | ragelink | 16 | const messages = document.querySelector('#id_unusable_warning'); |
| afe42d0… | ragelink | 17 | document.getElementById('id_password1').closest('.form-row').hidden = !usablePassword; |
| afe42d0… | ragelink | 18 | document.getElementById('id_password2').closest('.form-row').hidden = !usablePassword; |
| afe42d0… | ragelink | 19 | if (messages) { |
| afe42d0… | ragelink | 20 | messages.hidden = usablePassword; |
| afe42d0… | ragelink | 21 | } |
| afe42d0… | ragelink | 22 | if (submit1 && submit2) { |
| afe42d0… | ragelink | 23 | submit1.hidden = !usablePassword; |
| afe42d0… | ragelink | 24 | submit2.hidden = usablePassword; |
| afe42d0… | ragelink | 25 | } |
| afe42d0… | ragelink | 26 | }); |
| afe42d0… | ragelink | 27 | option.dispatchEvent(new Event('change')); |
| afe42d0… | ragelink | 28 | }); |
| afe42d0… | ragelink | 29 | } |