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
/** | |
* Get a random int between two values | |
* @param {Int} min | |
* @param {Int} max | |
* @return {Int} | |
*/ | |
export function randomBetween(min = 0, max = 0) { | |
return Math.floor(Math.random() * (max - min + 1) + min) | |
} |
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
export function getMousePosition (e) { | |
let posX = 0 | |
let posY = 0 | |
if (!e) { | |
e = window.event | |
} | |
if (e.pageX || e.pageY) { | |
posX = e.pageX |
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
/* If js doesnt load or just before it does: hide element for 2 seconds. */ | |
.no-js .u-showIfNoJs { | |
animation: showAfterLong 2000ms; | |
} | |
/* Hide when js loads and remove animation */ | |
.js .u-showIfNoJs { | |
animation: none; | |
display: none; | |
} |
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
/* global define, Image */ | |
(function (root, factory) { | |
if (typeof define === 'function' && define.amd) { | |
define([], function () { | |
return factory() | |
}) | |
} else if (typeof exports === 'object') { | |
module.exports = factory() | |
} 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
/** | |
* Get element offset | |
* @param {Element} obj | |
* @return {Boolean} | |
*/ | |
export function getElementViewportOffset (element) { | |
let left = element.offsetLeft, | |
top = element.offsetTop, | |
elementParent = element.parentNode |
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 onVisibilityChange (callbackHidden, callbackVisible) { | |
var browserPrefixes = ['moz', 'ms', 'o', 'webkit'] | |
var isVisible = true // internal flag, defaults to true | |
// get the correct attribute name | |
function getHiddenPropertyName (prefix) { | |
return (prefix ? prefix + 'Hidden' : 'hidden') | |
} | |
// get the correct event name |
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 observer = new MutationObserver(function (mutations) { | |
// Do the things | |
}); | |
let targetEl = document.documentElement; // Can be any element | |
observer.observe(targetEl, { | |
childList: true, | |
subtree: true, | |
attributes: true, |
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 orientationEls = doc.querySelectorAll('.js-orientation'); | |
window.addEventListener('deviceorientation', function(eventData) { | |
var yTilt = Math.round((-eventData.beta + 90) * (40/180) - 40); | |
var xTilt = Math.round(-eventData.gamma * (20/180) - 20); | |
if (xTilt > 0) { | |
xTilt = -xTilt; | |
} else if (xTilt < -40) { | |
xTilt = -(xTilt + 80); |
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
/** | |
* Slugify a string | |
* @param {String} text | |
* @return {String} | |
*/ | |
export function slugify(text) { | |
return text.toString().toLowerCase() | |
.replace(/([å,ä])/g, 'a') // Replace å and ä with aa | |
.replace(/(ö)/g, 'o') // Replace ö with o | |
.replace(/\s+/g, '-') // Replace spaces with - |
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 postcss = require('postcss') | |
module.exports = postcss.plugin('postcss-zindex', (options) => { | |
return (css) => { | |
let nodes = [] | |
// TODO: Some options? | |
// Get all z-index declarations | |
css.walkDecls('z-index', (decl, i) => { |