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
/** Determines if passed value is empty or not. | |
* Works on multiple data types. | |
**/ | |
const isEmpty = data => { | |
let count = 0; | |
if (typeof (data) === 'number' || typeof (data) === 'boolean') { return false; } | |
if (typeof (data) === 'undefined' || data === null) { return true; } | |
if (typeof (data.length) !== 'undefined') { return data.length === 0; } | |
Object.keys(data).forEach(() => { count += 1; }); | |
return count === 0; |
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
/* Locates the first parent element | |
* that has a given attribute. | |
*/ | |
const findParentElement = (node, attribute) => { | |
if (isEmpty(node) || isEmpty(attribute)) return null; | |
let element = node; | |
/* eslint-disable no-cond-assign, no-empty */ | |
while ( | |
(element = element.parentElement) && |
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
/* Returns the absolute page position | |
* of a given element. | |
*/ | |
const absoluteElementPosition = node => { | |
if (isEmpty(node)) return null | |
let element = node | |
let left = 0 | |
let top = 0 | |
do { |
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
/** | |
see https://codepen.io/chrisbfusion/pen/oNbyppO | |
sample tree visual | |
30 | |
| | |
------- | |
| | | |
8 52 | |
| |
OlderNewer