| 1 |
document.addEventListener('DOMContentLoaded', function () { |
| 2 |
console.log('script.js loaded'); |
| 3 |
|
| 4 |
/** |
| 5 |
* Helper function to handle the visibility of a text field/container. |
| 6 |
* |
| 7 |
* @param {string} toggleId - The ID of the toggle (checkbox) element. |
| 8 |
* @param {string} textFieldId - The ID of the text field/container. |
| 9 |
*/ |
| 10 |
function handleTextFieldVisibility(toggleId, textFieldId) { |
| 11 |
const toggle = document.getElementById(toggleId); |
| 12 |
const textField = document.getElementById(textFieldId); |
| 13 |
|
| 14 |
if (toggle && textField) { |
| 15 |
console.log(`Initial state for ${toggleId}: ${toggle.checked}`); |
| 16 |
textField.style.display = toggle.checked ? 'block' : 'none'; |
| 17 |
toggle.addEventListener('change', function () { |
| 18 |
console.log(`Toggle ${toggleId} changed: ${this.checked}`); |
| 19 |
textField.style.display = this.checked ? 'block' : 'none'; |
| 20 |
}); |
| 21 |
} else { |
| 22 |
if (!toggle) console.error(`Toggle element with ID "${toggleId}" not found.`); |
| 23 |
if (!textField) console.error(`Text field element with ID "${textFieldId}" not found.`); |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
// "Change Login URL" |
| 28 |
handleTextFieldVisibility('ns_shield_login_url_enabled', 'ns_shield_login_url'); |
| 29 |
|
| 30 |
// "Disable Default Admin" |
| 31 |
handleTextFieldVisibility('ns_shield_default_admin', 'admin_login_field'); |
| 32 |
|
| 33 |
/** |
| 34 |
* Helper function to handle tooltips. |
| 35 |
*/ |
| 36 |
function handleTooltip(sliderSelector, tooltipSelector) { |
| 37 |
const sliders = document.querySelectorAll(sliderSelector); |
| 38 |
sliders.forEach(function (slider) { |
| 39 |
const tooltip = slider.parentElement.querySelector(tooltipSelector); |
| 40 |
if (slider && tooltip) { |
| 41 |
slider.addEventListener('mouseenter', function () { |
| 42 |
tooltip.style.display = 'block'; |
| 43 |
}); |
| 44 |
slider.addEventListener('mouseleave', function () { |
| 45 |
tooltip.style.display = 'none'; |
| 46 |
}); |
| 47 |
slider.addEventListener('focus', function () { |
| 48 |
tooltip.style.display = 'block'; |
| 49 |
}); |
| 50 |
slider.addEventListener('blur', function () { |
| 51 |
tooltip.style.display = 'none'; |
| 52 |
}); |
| 53 |
} |
| 54 |
}); |
| 55 |
} |
| 56 |
handleTooltip('.slider', '.tooltip'); |
| 57 |
}); |