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.4.27 app/assets/javascripts/workarea/storefront/modules/checkout_primary_payments.js
workarea-storefront-3.5.4 app/assets/javascripts/workarea/storefront/modules/checkout_primary_payments.js
workarea-storefront-3.4.26 app/assets/javascripts/workarea/storefront/modules/checkout_primary_payments.js
workarea-storefront-3.5.3 app/assets/javascripts/workarea/storefront/modules/checkout_primary_payments.js
workarea-storefront-3.4.25 app/assets/javascripts/workarea/storefront/modules/checkout_primary_payments.js
workarea-storefront-3.5.2 app/assets/javascripts/workarea/storefront/modules/checkout_primary_payments.js
workarea-storefront-3.4.24 app/assets/javascripts/workarea/storefront/modules/checkout_primary_payments.js
workarea-storefront-3.5.1 app/assets/javascripts/workarea/storefront/modules/checkout_primary_payments.js
workarea-storefront-3.4.23 app/assets/javascripts/workarea/storefront/modules/checkout_primary_payments.js
workarea-storefront-3.4.22 app/assets/javascripts/workarea/storefront/modules/checkout_primary_payments.js
workarea-storefront-3.5.0 app/assets/javascripts/workarea/storefront/modules/checkout_primary_payments.js
workarea-storefront-3.4.21 app/assets/javascripts/workarea/storefront/modules/checkout_primary_payments.js
workarea-storefront-3.5.0.beta.1 app/assets/javascripts/workarea/storefront/modules/checkout_primary_payments.js
workarea-storefront-3.4.20 app/assets/javascripts/workarea/storefront/modules/checkout_primary_payments.js
workarea-storefront-3.4.19 app/assets/javascripts/workarea/storefront/modules/checkout_primary_payments.js
workarea-storefront-3.4.18 app/assets/javascripts/workarea/storefront/modules/checkout_primary_payments.js
workarea-storefront-3.4.17 app/assets/javascripts/workarea/storefront/modules/checkout_primary_payments.js
workarea-storefront-3.4.16 app/assets/javascripts/workarea/storefront/modules/checkout_primary_payments.js
workarea-storefront-3.4.15 app/assets/javascripts/workarea/storefront/modules/checkout_primary_payments.js
workarea-storefront-3.4.14 app/assets/javascripts/workarea/storefront/modules/checkout_primary_payments.js