mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
#6797: Implement new sidebar
This commit is contained in:
@@ -56,6 +56,13 @@ export function isTruthy<V extends string | number | boolean | null | undefined>
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Type guard to determine if a value is an `Element`.
|
||||
*/
|
||||
export function isElement(obj: Element | null | undefined): obj is Element {
|
||||
return typeof obj !== null && typeof obj !== 'undefined';
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the CSRF token from cookie storage.
|
||||
*/
|
||||
@@ -152,6 +159,22 @@ export function getElement<E extends HTMLElement>(id: string): Nullable<E> {
|
||||
return document.getElementById(id) as Nullable<E>;
|
||||
}
|
||||
|
||||
export function removeElements(...selectors: string[]): void {
|
||||
for (const element of getElements(...selectors)) {
|
||||
element.remove();
|
||||
}
|
||||
}
|
||||
|
||||
export function elementWidth<E extends HTMLElement>(element: Nullable<E>): number {
|
||||
let width = 0;
|
||||
if (element !== null) {
|
||||
const style = getComputedStyle(element);
|
||||
const pre = style.width.replace('px', '');
|
||||
width = parseFloat(pre);
|
||||
}
|
||||
return width;
|
||||
}
|
||||
|
||||
/**
|
||||
* scrollTo() wrapper that calculates a Y offset relative to `element`, but also factors in an
|
||||
* offset relative to div#content-title. This ensures we scroll to the element, but leave enough
|
||||
|
||||
Reference in New Issue
Block a user