Sha256: f0df604a9174b05eb857ada5c6f66a16867db27189d3df8b7840768e1305c6d2

Contents?: true

Size: 1.9 KB

Versions: 2

Compression:

Stored size: 1.9 KB

Contents

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

    var replaceProductSummary = function ($productSummary, newSummary) {
            var $newSummary = $(newSummary);

            WORKAREA.initModules($newSummary);

            $productSummary.empty().append($newSummary);
        },

        loadImage = function ($productSummary, newSummary) {
            var imageSrc = $('.product-summary__media-image', newSummary)[0].src,
                gettingImage = WORKAREA.image.get(imageSrc);

            WORKAREA.loading.createLoadingIndicator(gettingImage, {
                container: $productSummary,
                cssModifiers: 'loading--fill-parent',
                delay: 0
            });

            gettingImage.always(_.partial(replaceProductSummary, $productSummary, newSummary));
        },

        fallbackToUrl = function ($button) {
            window.location = $button.attr('href');
        },

        buttonIsSelected = function ($button) {
            return $button.hasClass('swatch-options__swatch-button--selected');
        },

        handleSwatchButtonClick = function (event) {
            var $button = $(event.currentTarget),
                $productSummary = $button.closest('.product-summary'),
                endpoint = $button.data('productSummarySwatch').url;

            event.preventDefault();

            if (buttonIsSelected($button)) { return; }

            $.get(endpoint)
            .done(_.partial(loadImage, $productSummary))
            .fail(_.partial(fallbackToUrl, $button));
        },

        /**
         * @method
         * @name init
         * @memberof WORKAREA.productSummarySwatches
         */
        init = function ($scope) {
            $('[data-product-summary-swatch]', $scope)
            .on('click', handleSwatchButtonClick);
        };

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
workarea-swatches-1.0.6 app/assets/javascripts/workarea/storefront/swatches/modules/product_summary_swatches.js
workarea-swatches-1.0.5 app/assets/javascripts/workarea/storefront/swatches/modules/product_summary_swatches.js