This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var para = document.querySelector('p'); | |
var mql = window.matchMedia('(max-width: 600px)'); | |
function screenTest(e) { | |
if (e.matches) { | |
/* the viewport is 600 pixels wide or less */ | |
para.textContent = 'This is a narrow screen — less than 600px wide.'; | |
document.body.style.backgroundColor = 'red'; | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {Object} | |
* @param {String} keys - Dot notation of property access | |
*/ | |
function accessProperty(object, keys) { | |
return keys.split('.').reduce((value, key) => value && value[key], object) | |
} | |
// Unknown if nested values will exist | |
const payload = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function promiseWithTimeout(promise, timeoutTime = 5000) { | |
return new Promise((resolve, reject) => { | |
const timeout = setTimeout(() => reject({ | |
message: 'timeout' | |
}), timeoutTime) | |
const resolveWithTimeout = (res) => { | |
clearTimeout(timeout) | |
resolve(res) | |
} | |
const rejectWithTimeout = (err) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function validEmailFormat(email) { | |
return email.length > 0 && /\w[@].+[.]\w{2,3}/.test(email) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const useReducer = (reducer, initState = {}) => { | |
let state = initState; | |
const getState = () => state; | |
const dispatch = action => (state = reducer(state, action)); | |
return Object.freeze({ getState, dispatch }); | |
}; | |
const reducer = (state, action) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ifMobile = () => { | |
if( navigator.userAgent.match(/Android/i) || | |
navigator.userAgent.match(/webOS/i) || | |
navigator.userAgent.match(/iPhone/i) || | |
navigator.userAgent.match(/iPod/i) || | |
navigator.userAgent.match(/iPad/i) || | |
navigator.userAgent.match(/BlackBerry/i) || | |
navigator.userAgent.match(/IEMobile/i) || | |
navigator.userAgent.match(/Opera Mini/i) | |
) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const reOrderArray = (array, oldIndex, newIndex) => { | |
if ( array.length === 0 ) return array | |
while (oldIndex < 0) { | |
oldIndex += array.length | |
} | |
while (newIndex < 0) { | |
newIndex += array.length | |
} | |
if (newIndex >= array.length) { | |
var k = newIndex - array.length |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Default Variables */ | |
$column_name : col !default; | |
$column_before : before !default; | |
$column_after : after !default; | |
$max_width : 1080; // Unit in pixels | |
$column_count : 12; | |
$column_gutter : 15; // Unit in pixels | |
$column_width : ($max-width / $column_count) - ($column_gutter * 2); // Unit in percentages | |
/* Column Wrapper */ |