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
/** | |
* @module holy-albatross | |
* @description | |
* A custom element for switching between horizontal and vertical layouts | |
* using Flexbox, where the switch property defines the minimum container width | |
* for the horizontal layout | |
* @property {string} switch A CSS width value | |
* @property {string} margin A CSS margin value | |
*/ |
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
// set heading level based on the closest heading before the node | |
const setLevel = (node, nodeSelector) => { | |
// Get all relevant nodes and reverse the array (destructive) | |
let allNodes = [...document.querySelectorAll(`h1, h2, h3, h4, h5, h6, ${nodeSelector}`)].reverse(); | |
// Truncate the array to make the target node the first item | |
let index = allNodes.indexOf(allNodes.find(n => n.contains(node))); | |
let truncated = allNodes.slice(index); | |
// Find the next node thats a heading |
OlderNewer