ice.fo.utils
Version:
23 lines (19 loc) • 592 B
JavaScript
export const COMPONENT_MENU_ANCHOR_PREFIX = 'ice-menu-anchor'
/**
* Generate anchor ID for Element to scroll to.
*/
export function makeAnchorId (text) {
return `anchor_${text.replaceAll(' ', '_')}`
}
/**
* Check whether the string is a generated anchor id.
*/
export function checkIsAnchor (value) {
return value && ['anchor_', '#'].some(i => value.startsWith(i))
}
/**
* Return HTML Element of target anchor id.
*/
export function findTargetAnchorElement (text) {
return document.getElementById(text) || document.querySelector(`*[${COMPONENT_MENU_ANCHOR_PREFIX}=${text}]`)
}