admin-script.js
49 lines
| 1 | /** |
| 2 | * Admin scripts for Easy Actions Scheduler Cleaner |
| 3 | * |
| 4 | * Handles toggle visibility for schedule and notification options. |
| 5 | * |
| 6 | * @package EasyActionsSchedulerCleanerAyudaWP |
| 7 | * @since 1.2.0 |
| 8 | */ |
| 9 | |
| 10 | ( function () { |
| 11 | 'use strict'; |
| 12 | |
| 13 | document.addEventListener( 'DOMContentLoaded', function () { |
| 14 | |
| 15 | /** |
| 16 | * Generic toggle handler: show/hide a target element based on checkbox state. |
| 17 | * |
| 18 | * @param {string} toggleId ID of the checkbox. |
| 19 | * @param {string} targetId ID of the element to show/hide. |
| 20 | */ |
| 21 | function setupToggle( toggleId, targetId ) { |
| 22 | var toggle = document.getElementById( toggleId ); |
| 23 | var target = document.getElementById( targetId ); |
| 24 | |
| 25 | if ( ! toggle || ! target ) { |
| 26 | return; |
| 27 | } |
| 28 | |
| 29 | function update() { |
| 30 | if ( toggle.checked ) { |
| 31 | target.classList.remove( 'easc-disabled' ); |
| 32 | } else { |
| 33 | target.classList.add( 'easc-disabled' ); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | update(); |
| 38 | toggle.addEventListener( 'change', update ); |
| 39 | } |
| 40 | |
| 41 | // Schedule tab toggle. |
| 42 | setupToggle( 'easc-schedule-toggle', 'easc-schedule-options' ); |
| 43 | |
| 44 | // Notification tab toggles. |
| 45 | setupToggle( 'easc-report-toggle', 'easc-report-options' ); |
| 46 | setupToggle( 'easc-alert-toggle', 'easc-alert-options' ); |
| 47 | } ); |
| 48 | } )(); |
| 49 |