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