refactor login template
This commit is contained in:
parent
77c38cd17d
commit
afd4981ba7
@ -39,29 +39,25 @@
|
||||
<div class="alert alert-{{ 'success' if success else 'danger' }} mt-4">{{ message }}</div>
|
||||
{% endif %}
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const tokenInput = document.getElementById('token');
|
||||
const userInput = document.getElementById('user');
|
||||
const pwInput = document.getElementById('pw');
|
||||
const userLabel = document.getElementById('user-label');
|
||||
const pwLabel = document.getElementById('pw-label');
|
||||
const inputs = [document.getElementById('user'), document.getElementById('pw')];
|
||||
const labels = [document.getElementById('user-label'), document.getElementById('pw-label')];
|
||||
const fieldClasses = ['bg-body-secondary', 'text-body-secondary', 'text-decoration-line-through'];
|
||||
|
||||
function toggleCredFields() {
|
||||
const hasToken = tokenInput.value.trim() !== '';
|
||||
[userInput, pwInput].forEach(el => {
|
||||
el.readOnly = hasToken;
|
||||
el.tabIndex = hasToken ? -1 : 0;
|
||||
el.style.pointerEvents = hasToken ? 'none' : '';
|
||||
if (hasToken && document.activeElement === el) {
|
||||
const inactive = tokenInput.value.trim() !== '';
|
||||
inputs.forEach(el => {
|
||||
el.readOnly = inactive;
|
||||
el.tabIndex = inactive ? -1 : 0;
|
||||
el.style.pointerEvents = inactive ? 'none' : '';
|
||||
if (inactive && document.activeElement === el) {
|
||||
el.blur();
|
||||
}
|
||||
el.classList.toggle('bg-body-secondary', hasToken);
|
||||
el.classList.toggle('text-decoration-line-through', hasToken);
|
||||
el.classList.toggle('text-body-secondary', hasToken);
|
||||
fieldClasses.forEach(cls => el.classList.toggle(cls, inactive));
|
||||
});
|
||||
[userLabel, pwLabel].forEach(el => {
|
||||
el.classList.toggle('text-decoration-line-through', hasToken);
|
||||
el.classList.toggle('text-body-secondary', hasToken);
|
||||
labels.forEach(el => {
|
||||
['text-decoration-line-through', 'text-body-secondary'].forEach(cls => el.classList.toggle(cls, inactive));
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user