@progress/kendo-angular-navigation
Version:
Kendo UI Navigation for Angular
64 lines (63 loc) • 2.01 kB
JavaScript
/**-----------------------------------------------------------------------------------------
* Copyright © 2025 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the project root for more information
*-------------------------------------------------------------------------------------------*/
import { closestInScope, focusableSelector } from "@progress/kendo-angular-common";
/**
* @hidden
*/
export const isPresent = (value) => value !== null && value !== undefined;
/**
* @hidden
*/
export const outerWidth = (element) => {
const style = getComputedStyle(element);
let width = parseFloat(style.width);
width += (parseFloat(style.marginLeft) || 0) + (parseFloat(style.marginRight) || 0);
return width;
};
/**
* @hidden
*/
export const getFirstAndLastFocusable = (parent) => {
const all = getAllFocusableChildren(parent);
const firstFocusable = all.length > 0 ? all[0] : parent;
const lastFocusable = all.length > 0 ? all[all.length - 1] : parent;
return [firstFocusable, lastFocusable];
};
/**
* @hidden
*/
const getAllFocusableChildren = (parent) => {
return parent.querySelectorAll(focusableSelector);
};
/**
* @hidden
*/
let idx = 0;
/**
* @hidden
*/
export const hexColorRegex = /^#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/;
/**
* @hidden
*/
export const getId = (prefix) => {
return `${prefix}${++idx}`;
};
/**
* @hidden
*/
export const ACTIONSHEET_ITEM_INDEX_ATTRIBUTE = 'kendo-actionsheet-item-index';
/**
* @hidden
*/
export const getActionSheetItemIndex = (target, targetAttr, scope) => {
const item = closestItem(target, targetAttr, scope);
if (item) {
return itemIndex(item, targetAttr);
}
};
const itemIndex = (item, indexAttr) => +item.getAttribute(indexAttr);
const hasItemIndex = (item, indexAttr) => isPresent(item.getAttribute(indexAttr));
const closestItem = (target, targetAttr, scope) => closestInScope(target, el => hasItemIndex(el, targetAttr), scope);