This file contains hidden or 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
/** | |
* Set URL Parameter | |
* @param { String } key | |
* @param { String } value | |
* @param { String } url | |
*/ | |
export function setUrlParameter(key, value, url = window.location.href) { | |
let reg = new RegExp("([?&])" + key + "=.*?(&|$)", "i") | |
let separator = url.indexOf('?') !== -1 ? "&" : "?" |
This file contains hidden or 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
/** | |
* Turns a list of nodes into an array | |
* @param { NodeList } nodeList | |
* @return { Array } | |
*/ | |
export function nodesToArray(nodeList) { | |
return [...nodeList]; | |
return Array.from(nodeList); | |
return [].slice.call(nodeList); | |
return Array.prototype.slice.call(nodeList); |
This file contains hidden or 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
/** | |
* Dependencies | |
*/ | |
const breakpoints = { | |
xs: 300, | |
sm: 600, | |
md: 800, | |
lg: 1200, | |
xl: 1600 | |
}; |
This file contains hidden or 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 closest DOM element up the tree that contains a class, ID, or data attribute | |
* @param {Node} elem The base element | |
* @param {String} selector The class, id, data attribute, or tag to look for | |
* @return {Node} Element or Null if no match | |
*/ | |
export function getClosest (elem, selector) { | |
let firstChar = selector.charAt(0); | |
// Get closest match |
This file contains hidden or 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
/** | |
* Check if element is in viewport | |
* @param {Node} el | |
* @return {Object} | |
*/ | |
export function elementInViewport(el) { | |
let top = el.offsetTop; | |
let left = el.offsetLeft; | |
let width = el.offsetWidth; | |
let height = el.offsetHeight; |
This file contains hidden or 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
/** | |
* isUndefined | |
* Check if object is undefined | |
* @param {Anything} value | |
* @return {Boolean} Returns `true` if `value` is `undefined`, else `false`. | |
*/ | |
export function isUndefined(value) { | |
return value === undefined; | |
} |
This file contains hidden or 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 distance = distanceBetween({ | |
lat: 59.329323, | |
lng: 18.068581 | |
}, { | |
lat: 57.708870, | |
lng: 11.974560 | |
}); | |
function getRadius(x) { | |
return x * Math.PI / 180; |
This file contains hidden or 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
<?php | |
/** | |
* Check if on posts-page | |
*/ | |
function is_page_for_posts () { | |
return ( is_home() || (is_archive() && ! is_post_type_archive() ) ); | |
} | |
This file contains hidden or 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 PREFIXES = ['', 'Moz', 'webkit', 'Webkit', 'O', 'ms']; | |
function applyStyle(prop, value, element) { | |
const first = prop[0]; | |
const trail = prop.slice(1); | |
PREFIXES.forEach(prefix => { | |
let name = prefix ? (prefix + first.toUpperCase()) : first.toLowerCase(); | |
name += trail; |
This file contains hidden or 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 stringToElements (string) { | |
const div = document.createElement('div') | |
div.innerHTML = string | |
if (div.childNodes.length > 1) { | |
return div.childNodes | |
} | |
return div.firstChild | |
} |