UNPKG

@progress/kendo-angular-listview

Version:

Kendo UI Angular listview component

104 lines (103 loc) 3.12 kB
/**----------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the project root for more information *-------------------------------------------------------------------------------------------*/ import { isDocumentAvailable } from '@progress/kendo-angular-common'; const LISTVIEW_ITEM_SELECTOR = '.k-listview-item'; /** * @hidden */ export const isPresent = (item) => item !== null && item !== undefined; /** * @hidden */ export const isObject = (item) => isPresent(item) && typeof item === 'object'; /** * @hidden * * Polyfill for `Element.matches`. * https://developer.mozilla.org/en-US/docs/Web/API/Element/matches */ export const match = (element, selector) => { const matcher = element.matches || element.msMatchesSelector || element.webkitMatchesSelector; if (!isPresent(matcher)) { return false; } return matcher.call(element, selector); }; /** * @hidden * * Checks if a target element has the `.k-listview-item` CSS class. */ export const isListViewItem = (element) => { if (!isPresent(element)) { return false; } return match(element, LISTVIEW_ITEM_SELECTOR); }; /** * @hidden * * Extracts and parses to a number the `data-kendo-listview-item-index` attribute value from the targeted element. */ export const getListItemIndex = (item) => { if (!isPresent(item)) { return null; } return Number(item.getAttribute('data-kendo-listview-item-index')); }; /** * @hidden * * Gets the new focus target from a blur event. * Queries both event.relatedTarget and document.activeElement for compatibility with IE. */ export const relatedTarget = (event) => { if (!isPresent(event.relatedTarget) || !isDocumentAvailable()) { return null; } return event.relatedTarget || document.activeElement; }; /** * @hidden * * If the given contender number is not defined or lower than the specified min - returns min, if its above the specified max - returns max. * If the number is in the given bounds, it is returned. */ export const fitIntoRange = (contender, min, max) => { if (!isPresent(contender) || contender <= min) { return min; } else if (contender >= max) { return max; } else { return contender; } }; /** * @hidden */ export const closestWithMatch = (element, selector) => { let parent = element; while (parent !== null && parent.nodeType === 1) { if (match(parent, selector)) { return parent; } parent = parent.parentElement || parent.parentNode; } return null; }; /** * @hidden * * Extracts and parses to a number the `data-kendo-listview-item-index` attribute value from the targeted element. */ export const getClosestListItemIndex = (element) => { if (!isPresent(element)) { return null; } const closestListViewItem = closestWithMatch(element, LISTVIEW_ITEM_SELECTOR); return getListItemIndex(closestListViewItem); };