woocommerce-paypal-payments/modules/ppcp-wc-gateway/resources/js/gateway-settings.js

34 lines
1.3 KiB
JavaScript
Raw Normal View History

;document.addEventListener(
'DOMContentLoaded',
() => {
const payLaterMessagingCheckboxes = document.querySelectorAll(
"#ppcp-message_enabled, #ppcp-message_cart_enabled, #ppcp-message_product_enabled"
)
const vaultingCheckboxes = document.querySelectorAll(
2021-03-25 15:42:28 +02:00
"#ppcp-vault_enabled, #ppcp-save_paypal_account"
)
function atLeastOneChecked(checkboxesNodeList) {
return Array.prototype.slice.call(checkboxesNodeList).filter(node => !node.disabled && node.checked).length > 0
}
function disableAll(nodeList){
nodeList.forEach(node => node.setAttribute('disabled', 'true'))
}
function enableAll(nodeList){
nodeList.forEach(node => node.removeAttribute('disabled'))
}
function updateCheckboxes() {
atLeastOneChecked(payLaterMessagingCheckboxes) ? disableAll(vaultingCheckboxes) : enableAll(vaultingCheckboxes)
atLeastOneChecked(vaultingCheckboxes) ? disableAll(payLaterMessagingCheckboxes) : enableAll(payLaterMessagingCheckboxes)
}
updateCheckboxes()
payLaterMessagingCheckboxes.forEach(node => node.addEventListener('change', updateCheckboxes))
vaultingCheckboxes.forEach(node => node.addEventListener('change', updateCheckboxes));
}
);