HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/netwerkbrabant/netwerkbrabant.nl/resources/assets/js/site/paymentMethodsHandler.js
/* ==========================================================================
   Payment methods Handler

   Currently only for one form in a page
 ========================================================================== */

const PaymentMethodsHandler = {

    paymentMethodsElement: null,

    init: function () {

        PaymentMethodsHandler.paymentMethodsElement = document.querySelector('.payment-methods');

        if (isset(PaymentMethodsHandler.paymentMethodsElement)) {

            const radioButtons = PaymentMethodsHandler.paymentMethodsElement.querySelectorAll('.js-payment-methods-radio')
            const nRadioButtons = radioButtons.length;

            for (let i = 0; i < nRadioButtons; i++) {
                const radioButton = radioButtons[i];

                radioButton.addEventListener('change', function () {

                    // Get and remove the current selected state
                    const currentSelected = PaymentMethodsHandler.paymentMethodsElement.querySelector('.is-selected');
                    if (isset(currentSelected)) currentSelected.classList.remove('is-selected');

                    this.parentElement.classList.add('is-selected');
                });

            }

        }
    },
};

PaymentMethodsHandler.init();