@justeat/fozzie
Advanced tools
Comparing version 9.2.0 to 9.3.0
@@ -8,3 +8,3 @@ "use strict"; | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _breakpointHelper.getBreakpoints; | ||
@@ -15,3 +15,3 @@ } | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _breakpointHelper.getCurrentScreenWidth; | ||
@@ -22,3 +22,3 @@ } | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _breakpointHelper.isWithinBreakpoint; | ||
@@ -25,0 +25,0 @@ } |
@@ -8,14 +8,2 @@ "use strict"; | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
/** | ||
@@ -26,10 +14,10 @@ * @overview Breakpoint handler | ||
*/ | ||
var getBreakpoints = function getBreakpoints() { | ||
var output = {}; // Append hidden element to body | ||
const getBreakpoints = () => { | ||
const output = {}; // Append hidden element to body | ||
var screenSizer = document.createElement('div'); | ||
const screenSizer = document.createElement('div'); | ||
screenSizer.classList.add('c-screen-sizer'); | ||
document.body.appendChild(screenSizer); // It should have a 'content' property containing the breakpoints | ||
var breakpoints = window.getComputedStyle(document.querySelector('.c-screen-sizer')).getPropertyValue('content').replace(/["']/g, '').split(','); // Gives a list of breakpoints in the form ['narrow:414px', ...etc] | ||
const breakpoints = window.getComputedStyle(document.querySelector('.c-screen-sizer')).getPropertyValue('content').replace(/["']/g, '').split(','); // Gives a list of breakpoints in the form ['narrow:414px', ...etc] | ||
// When there is no content, at this stage breakpoints should be [''] | ||
@@ -41,9 +29,5 @@ | ||
return breakpoints.reduce(function (prev, current) { | ||
return breakpoints.reduce((prev, current) => { | ||
// `current` is of the form 'narrow:414px' | ||
var _current$split = current.split(':'), | ||
_current$split2 = _slicedToArray(_current$split, 2), | ||
breakpointName = _current$split2[0], | ||
breakpointValue = _current$split2[1]; | ||
const [breakpointName, breakpointValue] = current.split(':'); | ||
prev[breakpointName] = breakpointValue; // <- the initial value is used for the first iteration | ||
@@ -58,7 +42,7 @@ // The object, e.g., { 'narrow': '414px' } is returned to be used as `prev` in the next iteration | ||
var createBreakpointArray = function createBreakpointArray(breakpoints) { | ||
const createBreakpointArray = breakpoints => { | ||
// Order the breakpoints from widest to narrowest, | ||
// takes the form [['narrow', '414px'], [...etc]] | ||
var bps = []; | ||
Object.keys(breakpoints).forEach(function (key) { | ||
const bps = []; | ||
Object.keys(breakpoints).forEach(key => { | ||
bps.unshift([key, breakpoints[key]]); | ||
@@ -71,11 +55,11 @@ }); | ||
var getCurrentScreenWidth = function getCurrentScreenWidth() { | ||
var currentWidth = window.innerWidth; | ||
var breakpoints = getBreakpoints(); | ||
var bps = createBreakpointArray(breakpoints); | ||
const getCurrentScreenWidth = () => { | ||
const currentWidth = window.innerWidth; | ||
const breakpoints = getBreakpoints(); | ||
const bps = createBreakpointArray(breakpoints); | ||
for (var i = 0; i < bps.length; i++) { | ||
for (let i = 0; i < bps.length; i++) { | ||
// Loops through the breakpoints (in descending order) | ||
// returning the first one that is narrower than currentWidth. | ||
var breakpointWidth = parseInt(bps[i][1], 10); // This also strips the 'px' from the string | ||
const breakpointWidth = parseInt(bps[i][1], 10); // This also strips the 'px' from the string | ||
@@ -94,19 +78,15 @@ if (i === bps.length - 1 || currentWidth > breakpointWidth) { | ||
var isWithinBreakpoint = function isWithinBreakpoint(breakpointString) { | ||
var operatorRegex = /[<>=]+/; | ||
var operatorMatch = breakpointString.match(operatorRegex); | ||
var operator = operatorMatch ? operatorMatch[0] : ''; | ||
var _breakpointString$spl = breakpointString.split(operatorRegex), | ||
_breakpointString$spl2 = _slicedToArray(_breakpointString$spl, 2), | ||
breakpoint = _breakpointString$spl2[1]; | ||
var currentScreenWidth = window.innerWidth; | ||
var breakpoints = getBreakpoints(); | ||
var bps = createBreakpointArray(breakpoints); // We loop through the breakpoint array until we get a match. | ||
const isWithinBreakpoint = breakpointString => { | ||
const operatorRegex = /[<>=]+/; | ||
const operatorMatch = breakpointString.match(operatorRegex); | ||
const operator = operatorMatch ? operatorMatch[0] : ''; | ||
const [, breakpoint] = breakpointString.split(operatorRegex); | ||
const currentScreenWidth = window.innerWidth; | ||
const breakpoints = getBreakpoints(); | ||
const bps = createBreakpointArray(breakpoints); // We loop through the breakpoint array until we get a match. | ||
// If we match we return the px value as an int. If we do not match we return false | ||
var breakpointToPX = function breakpointToPX(breakpointName) { | ||
var match = false; | ||
bps.forEach(function (bp) { | ||
const breakpointToPX = breakpointName => { | ||
let match = false; | ||
bps.forEach(bp => { | ||
if (bp[0] === breakpointName) { | ||
@@ -119,3 +99,3 @@ match = parseInt(bp[1], 10); | ||
var breakpointInPX = breakpointToPX(breakpoint); // If the breakpoint passed in does not match any we; | ||
const breakpointInPX = breakpointToPX(breakpoint); // If the breakpoint passed in does not match any we; | ||
@@ -126,3 +106,3 @@ if (!breakpointInPX) { | ||
var mediaQuery = { | ||
const mediaQuery = { | ||
'<': currentScreenWidth < breakpointInPX, | ||
@@ -134,3 +114,3 @@ '<=': currentScreenWidth <= breakpointInPX, | ||
}; | ||
var result = mediaQuery[operator]; | ||
const result = mediaQuery[operator]; | ||
@@ -137,0 +117,0 @@ if (result == null) { |
@@ -5,3 +5,3 @@ { | ||
"description": "UI Web Framework for the Just Eat Global Platform", | ||
"version": "9.2.0", | ||
"version": "9.3.0", | ||
"main": "dist/js/index.js", | ||
@@ -46,2 +46,3 @@ "files": [ | ||
"@justeat/browserslist-config-fozzie": "2.0.0", | ||
"caniuse-lite": "1.0.30001374", | ||
"@justeat/eslint-config-fozzie": "5.1.0", | ||
@@ -52,3 +53,2 @@ "@justeat/f-dom": "1.1.0", | ||
"@justeat/stylelint-config-fozzie": "2.3.0", | ||
"caniuse-lite": "1.0.30001374", | ||
"concurrently": "7.3.0", | ||
@@ -55,0 +55,0 @@ "coveralls": "3.1.1", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
284255
112