| 1 |
( function() { |
| 2 |
function addEventListeners() { |
| 3 |
document.addEventListener( 'change', handleChangeEvent ); |
| 4 |
document.addEventListener( 'keydown', handleKeyDownEvent ); |
| 5 |
} |
| 6 |
|
| 7 |
function handleChangeEvent( e ) { |
| 8 |
if ( 'INPUT' === e.target.nodeName && 'checkbox' === e.target.type && e.target.parentNode.classList.contains( 'frm_toggle_block' ) ) { |
| 9 |
handleToggleChangeEvent( e ); |
| 10 |
} |
| 11 |
|
| 12 |
if ( 'frm_currency' === e.target.id ) { |
| 13 |
syncCurrencyOptions( e.target ); |
| 14 |
} |
| 15 |
} |
| 16 |
|
| 17 |
function handleKeyDownEvent( e ) { |
| 18 |
switch ( e.key ) { // eslint-disable-line sonarjs/no-small-switch |
| 19 |
case ' ': |
| 20 |
handleSpaceDownEvent( e ); |
| 21 |
break; |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
function handleToggleChangeEvent( e ) { |
| 26 |
e.target.nextElementSibling.setAttribute( 'aria-checked', e.target.checked ? 'true' : 'false' ); |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* Updates the currency formatting options based on the selected currency. |
| 31 |
* |
| 32 |
* @param {HTMLSelectElement} currencySelect The currency select element. |
| 33 |
*/ |
| 34 |
function syncCurrencyOptions( currencySelect ) { |
| 35 |
const currency = frmSettings.currencies[ currencySelect.value ]; |
| 36 |
|
| 37 |
document.getElementById( 'frm_thousand_separator' ).value = currency.thousand_separator; |
| 38 |
document.getElementById( 'frm_decimal_separator' ).value = currency.decimal_separator; |
| 39 |
document.getElementById( 'frm_decimals' ).value = currency.decimals; |
| 40 |
} |
| 41 |
|
| 42 |
function handleSpaceDownEvent( e ) { |
| 43 |
if ( e.target.classList.contains( 'frm_toggle' ) ) { |
| 44 |
e.preventDefault(); // Prevent automatic browser scroll when space is pressed. |
| 45 |
e.target.click(); |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
addEventListeners(); |
| 50 |
}() ); |
| 51 |
|