dabbjs
Version:
general javascript library
180 lines (179 loc) • 5.41 kB
TypeScript
/**
* returns true if an element if an HTML or SVG DOM element
* @param e {any} an element
*/
export declare const isDOM: (e: any) => e is HTMLElement;
/**
* css(el, { background: 'green', display: 'none', 'border-radius': '5px' });
* @param el HTMLElement
* @param styles object of styles
*/
export declare const css: (el: HTMLElement, styles: {
[id: string]: any;
} | string) => string | HTMLElement;
/**
* get/set html element attribute
* @param el HTML element
* @param attrs string to get it's attribute, or an object with attributes to set
* @param value when defined
*
* should be attr(el: HTMLElement, attr: { [id: string]: any } | string, value?: string)
*
* when attr is an object, it sets all attributes in the object
*
* when value is undefined, it returns the attribute value if any
* when value is an string
*/
export declare const attr: (el: HTMLElement, attrs: {
[id: string]: any;
} | string, value?: string) => string | HTMLElement | null;
/**
* adds an event listener to an element
* @param el element
* @param type event name
* @param fn listener function
* @param b boolean | AddEventListenerOptions | undefined
*/
export declare const aEL: (el: HTMLElement, type: string, fn: Function, b?: boolean | AddEventListenerOptions) => void;
/**
* removes an event listener from an element
* @param el element
* @param type event name
* @param fn
* @param b
*/
export declare const rEL: (el: HTMLElement, type: string, fn: Function, b?: boolean | AddEventListenerOptions) => void;
/**
* adds an event listener to the document
* @param type event name
* @param fn listener function
* @param b boolean | AddEventListenerOptions | undefined
*/
export declare const daEl: (type: string, fn: Function, b?: boolean | AddEventListenerOptions) => void;
/**
* removes an event listener from the document
* @param el element
* @param type event name
* @param fn
* @param b
*/
export declare const drEL: (type: string, fn: Function, b?: boolean | AddEventListenerOptions) => void;
/**
* appends a child element to it's new parent
* @param parent parent element
* @param child child element
*/
export declare const aChld: (parent: any, child: any) => any;
/**
* test for class
* @param el Element
* @param className className cannot contain spaces
* @returns true if present, false otherwise
*/
export declare const hCl: (el: Element, className: string) => boolean;
/**
* adds a class to an Element
* @param el Element
* @param className className cannot contain spaces
*/
export declare const aCl: (el: Element, className: string) => void;
/**
* removes a class from an Element
* @param el Element
* @param className className cannot contain spaces
*/
export declare const rCl: (el: Element, className: string) => void;
/**
* toggles a class from an Element
* @param el Element
* @param className className cannot contain spaces
* @param force undefined is toggle, true is add, false is remove
* @returns true if present, false if not
*/
export declare const tCl: (el: Element, className: string, force?: boolean) => boolean;
/**
* add class safe
* @param el HTMLElement
* @param className class names separated by space
*/
export declare const aClx: (el: Element, className: string) => Element;
/**
* calls a function when DOM is ready
* @param fn function to be called
*/
export declare const ready: (fn: Function) => boolean;
/**
* document.querySelector shortcut
* @param selectors query string
* @param elem HTMLElement or document if undefined
*/
export declare const qS: (selectors: string, elem?: HTMLElement) => HTMLElement;
/**
* document.querySelectorAll shortcut
* @param selectors query string
* @param elem HTMLElement or document if undefined
*/
export declare const qSA: (selectors: string, elem?: HTMLElement) => HTMLElement[];
/**
* document.getElementById shortcut
* @param s #id
*/
export declare const gEId: (id: string) => HTMLElement | null;
/**
* extracts a base-name from page metadata
*/
export declare const basePath: () => string | null;
/**
* creates an SVG element by tag name
* @param tagName tag name
* @param id optional name
* @param nsAttrs attributes
*/
export declare const tag: (tagName: string, id: string, nsAttrs: {
[id: string]: any;
}) => SVGElement;
/**
* creates an SVG element by an string
* @param html html string representation
*/
export declare const svg: (html: string) => SVGElement;
/**
* creates an HTML element by an string
* @param html html string representation
*/
export declare const html: (html: string) => HTMLElement;
export declare const registerCustomElement: (name: string, constructor: CustomElementConstructor) => boolean;
/**
*
* @param text
* @returns
*/
export declare const decodeHTMLEntities: (text: string) => string;
/**
*
* @param text
* @returns
*/
export declare const encodeHTMLEntities: (text: string) => string;
/**
*
* @param str
* @returns
*/
export declare const escapeChars: (str: string) => string;
/**
* saves CSS in Document DOM inside SVG element styles
* @param dom
* @returns
*/
export declare const svgStyles: (dom: HTMLElement) => HTMLElement;
/**
* retrieves all DOM script templates
*
* script with attribute data-tmpl="id" are returned as an object with [id] as key.
*
* it removes any CDATA, LF, NL, Tabs from result
*/
export declare const DOMTemplates: () => {
[key: string]: any;
};