Sha256: 2e5b8e6a206c7d01c899791ceff633ae598c3f6c31be34b3df3f6b95ec7c9de8

Contents?: true

Size: 1.99 KB

Versions: 62

Compression:

Stored size: 1.99 KB

Contents

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

    var breakPoints,
        currentMatches = [],
        supportsMatchMedia = window.feature.matchMedia,
        fullSupport = false,

        createBreakPoints = function () {
            if (supportsMatchMedia) {
                breakPoints = _.reduce(WORKAREA.config.storefrontBreakPoints.sizes, function (obj, widthValue, widthName) {
                    obj[widthName] = window.matchMedia('(min-width: ' + widthValue + 'px)');
                    return obj;
                }, {});
            }
        },

        queryCurrentMatches = function () {
            currentMatches = _.reduce(breakPoints, function (newArray, mediaQuery, sizeName) {
                if (mediaQuery.matches) {
                    newArray.push(sizeName);
                }
                return newArray;
            }, []);
        },

        getInitialMatches = function () {
            if (!supportsMatchMedia) {
                currentMatches = WORKAREA.config.storefrontBreakPoints.ie9Matches;
                return;
            }

            queryCurrentMatches();
            fullSupport = true;
        },

        /**
         * @method
         * @name currentlyLessThan
         * @memberof WORKAREA.breakPoints
         * @param {string} widthName - Name of the breakpoint, e.g. 'small' or 'medium'
         */
        currentlyLessThan = function (widthName) {
            if (_.includes(_.keys(breakPoints), widthName)) {
                return !_.includes(currentMatches, widthName);
            } else {
                return false;
            }
        };

    createBreakPoints();
    getInitialMatches();

    if (fullSupport) {
        $(window).on('resize', _.debounce(queryCurrentMatches, 250));
    }

    return {
        currentlyLessThan: currentlyLessThan,
        currentMatches: currentMatches,
        // Public method for testing only
        createBreakPoints: createBreakPoints
    };
}()));

Version data entries

62 entries across 62 versions & 1 rubygems

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