Sha256: 67526eb0dfa839e44d4784a40a07f8f9224e0726e9c562f7ea8d38b8c59afe9e

Contents?: true

Size: 2 KB

Versions: 62

Compression:

Stored size: 2 KB

Contents

/**
 * @namespace WORKAREA.checkoutPrimaryPayments
 */
WORKAREA.registerModule('checkoutPrimaryPayments', (function () {
    'use strict';

    var fieldExists = function ($field) {
            return !_.isEmpty($field);
        },

        fieldNeedsRule = function ($field) {
            return !$field.rules().creditcard;
        },

        addCreditCardValidation = function ($form) {
            var $field = $('[name="credit_card[number]"]', $form);

            if (fieldExists($field) && fieldNeedsRule($field)) {
                $form
                    .find('input[name="credit_card[number]"]')
                    .rules('add', { extendedCreditCard: true });
            }
        },

        handlePaymentMethodClick = function (event) {
            $(event.currentTarget)
                .find('input[name="payment"]')
                .prop('checked', true)
                .trigger('change');
        },

        activatePaymentMethod = function (event) {
            var $selection = $(event.currentTarget),
                $form = $selection.closest('form'),
                $all = $form.find('.checkout-payment__primary-method'),
                $current = $selection.closest('.checkout-payment__primary-method');

            $all.removeClass('checkout-payment__primary-method--selected');
            $current.addClass('checkout-payment__primary-method--selected');
        },

        setupForm = function (index, section) {
            var $form = $('form', section);

            addCreditCardValidation($form);

            $('input[name="payment"]', $form)
            .on('change', activatePaymentMethod);

            $('.checkout-payment__primary-method', $form)
            .on('click', handlePaymentMethodClick);
        },

        /**
         * @method
         * @name init
         * @memberof WORKAREA.checkoutPrimaryPayments
         */
        init = function ($scope) {
            $('[data-checkout-primary-payment]', $scope).each(setupForm);
        };

    return {
        init: init
    };
}()));

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-storefront-3.5.27 app/assets/javascripts/workarea/storefront/modules/checkout_primary_payments.js
workarea-storefront-3.5.26 app/assets/javascripts/workarea/storefront/modules/checkout_primary_payments.js
workarea-storefront-3.4.45 app/assets/javascripts/workarea/storefront/modules/checkout_primary_payments.js
workarea-storefront-3.5.25 app/assets/javascripts/workarea/storefront/modules/checkout_primary_payments.js
workarea-storefront-3.5.23 app/assets/javascripts/workarea/storefront/modules/checkout_primary_payments.js
workarea-storefront-3.4.44 app/assets/javascripts/workarea/storefront/modules/checkout_primary_payments.js
workarea-storefront-3.5.22 app/assets/javascripts/workarea/storefront/modules/checkout_primary_payments.js
workarea-storefront-3.4.43 app/assets/javascripts/workarea/storefront/modules/checkout_primary_payments.js
workarea-storefront-3.5.21 app/assets/javascripts/workarea/storefront/modules/checkout_primary_payments.js
workarea-storefront-3.4.42 app/assets/javascripts/workarea/storefront/modules/checkout_primary_payments.js
workarea-storefront-3.5.20 app/assets/javascripts/workarea/storefront/modules/checkout_primary_payments.js
workarea-storefront-3.4.41 app/assets/javascripts/workarea/storefront/modules/checkout_primary_payments.js
workarea-storefront-3.5.19 app/assets/javascripts/workarea/storefront/modules/checkout_primary_payments.js
workarea-storefront-3.4.40 app/assets/javascripts/workarea/storefront/modules/checkout_primary_payments.js
workarea-storefront-3.5.18 app/assets/javascripts/workarea/storefront/modules/checkout_primary_payments.js
workarea-storefront-3.4.39 app/assets/javascripts/workarea/storefront/modules/checkout_primary_payments.js
workarea-storefront-3.5.17 app/assets/javascripts/workarea/storefront/modules/checkout_primary_payments.js
workarea-storefront-3.4.38 app/assets/javascripts/workarea/storefront/modules/checkout_primary_payments.js
workarea-storefront-3.5.16 app/assets/javascripts/workarea/storefront/modules/checkout_primary_payments.js
workarea-storefront-3.4.37 app/assets/javascripts/workarea/storefront/modules/checkout_primary_payments.js