UNPKG

clientnode

Version:

upgrade to object orientated rock solid plugins

302 lines (301 loc) • 13.7 kB
import { $DomNodes, $T, Mapping, Options, ParametersExceptFirst, RecursivePartial, RelativePosition } from './type'; export declare let JAVASCRIPT_DEPENDENT_CONTENT_HANDLED: boolean; /** * This plugin provides such interface logic like generic controller logic for * integrating plugins into $, mutual exclusion for dependent gui elements, * logging additional string, array or function handling. A set of helper * functions to parse option objects dom trees or handle events is also * provided. * @property _defaultOptions - Static fallback options if not overwritten by * the options given to the constructor method. * @property _defaultOptions.logging {boolean} - Static indicator whether * logging should be active. * @property _defaultOptions.domNodeSelectorInfix {string} - Static selector * infix for all needed dom nodes. * @property _defaultOptions.domNodeSelectorPrefix {string} - Static selector * prefix for all needed dom nodes. * @property _defaultOptions.domNodes {Object.<string, string>} - Static * mapping of names to needed dom nodes referenced by their selector. * @property _defaultOptions.domNodes.hideJavaScriptEnabled {string} - Static * selector to dom nodes which should be hidden if javaScript is available. * @property _defaultOptions.domNodes.showJavaScriptEnabled {string} - Static * selector to dom nodes which should be visible if javaScript is available. * @property $domNode - $-extended dom node if one was given to the constructor * method. * @property options - Options given to the constructor. */ export declare class Tools<TElement = HTMLElement> { static _defaultOptions: Partial<Options>; $domNode: null | $T<TElement>; options: Options; /** * Triggered if current object is created via the "new" keyword. The dom * node selector prefix enforces to not globally select any dom nodes which * aren't in the expected scope of this plugin. "{1}" will be automatically * replaced with this plugin name suffix ("tools"). You don't have to use * "{1}" but it can help you to write code which is more reconcilable with * the dry concept. * @param $domNode - $-extended dom node to use as reference in various * methods. */ constructor($domNode?: $T<TElement>); /** * This method could be overwritten normally. It acts like a destructor. * @returns Returns the current instance. */ destructor(): this; /** * This method should be overwritten normally. It is triggered if current * object was created via the "new" keyword and is called now. * @param options - An options object. * @returns Returns the current instance. */ initialize<R = this>(options?: RecursivePartial<Options>): R; /** * Defines a generic controller for dom node aware plugins. * @param object - The object or class to control. If "object" is a class * an instance will be generated. * @param parameters - The initially given arguments object. * @param $domNode - Optionally a $-extended dom node to use as reference. * @returns Returns whatever the initializer method returns. */ static controller<TElement = HTMLElement>(object: unknown, parameters: unknown, $domNode?: null | $T<TElement>): unknown; /** * Shows the given object's representation in the browsers console if * possible or in a standalone alert-window as fallback. * @param object - Any object to print. * @param force - If set to "true" given input will be shown independently * of current logging configuration or interpreter's console * implementation. * @param avoidAnnotation - If set to "true" given input has no module or * log level specific annotations. * @param level - Description of log messages importance. * @param additionalArguments - Additional arguments are used for string * formatting. */ log(object: unknown, force?: boolean, avoidAnnotation?: boolean, level?: keyof Console, ...additionalArguments: Array<unknown>): void; /** * Wrapper method for the native console method usually provided by * interpreter. * @param object - Any object to print. * @param additionalArguments - Additional arguments are used for string * formatting. */ info(object: unknown, ...additionalArguments: Array<unknown>): void; /** * Wrapper method for the native console method usually provided by * interpreter. * @param object - Any object to print. * @param additionalArguments - Additional arguments are used for string * formatting. */ debug(object: unknown, ...additionalArguments: Array<unknown>): void; /** * Wrapper method for the native console method usually provided by * interpreter. * @param object - Any object to print. * @param additionalArguments - Additional arguments are used for string * formatting. */ error(object: unknown, ...additionalArguments: Array<unknown>): void; /** * Wrapper method for the native console method usually provided by * interpreter. * @param object - Any object to print. * @param additionalArguments - Additional arguments are used for string * formatting. */ critical(object: unknown, ...additionalArguments: Array<unknown>): void; /** * Wrapper method for the native console method usually provided by * interpreter. * @param object - Any object to print. * @param additionalArguments - Additional arguments are used for string * formatting. */ warn(object: unknown, ...additionalArguments: Array<unknown>): void; /** * Dumps a given object in a human-readable format. * @param object - Any object to show. * @param level - Number of levels to dig into given object recursively. * @param currentLevel - Maximal number of recursive function calls to * represent given object. * @returns Returns the serialized version of given object. */ static show(object: unknown, level?: number, currentLevel?: number): string; /** * Normalizes class name order of current dom node. * @returns Current instance. */ get normalizedClassNames(): this; /** * Normalizes style attributes order of current dom node. * @returns Returns current instance. */ get normalizedStyles(): this; /** * Retrieves a mapping of computed style attributes to their corresponding * values. * @returns The computed style mapping. */ get style(): Mapping<number | string>; /** * Get text content of current element without it children's text contents. * @returns The text string. */ get text(): string; /** * Checks whether given html or text strings are equal. * @param first - First html, selector to dom node or text to compare. * @param second - Second html, selector to dom node or text to compare. * @param forceHTMLString - Indicates whether given contents are * interpreted as html string (otherwise an automatic detection will be * triggered). * @returns Returns true if both dom representations are equivalent. */ static isEquivalentDOM(first: Node | string | $T | $T<Node>, second: Node | string | $T | $T<Node>, forceHTMLString?: boolean): boolean; /** * Determines where current dom node is relative to current view port * position. * @param givenDelta - Allows deltas for "top", "left", "bottom" and * "right" for determining positions. * @param givenDelta.bottom - Bottom delta. * @param givenDelta.left - Left delta. * @param givenDelta.right - Right delta. * @param givenDelta.top - Top delta. * @returns Returns one of "above", "left", "below", "right" or "in". */ getPositionRelativeToViewport(givenDelta?: { bottom?: number; left?: number; right?: number; top?: number; }): RelativePosition; /** * Generates a directive name corresponding selector string. * @param directiveName - The directive name. * @returns Returns generated selector. */ static generateDirectiveSelector(directiveName: string): string; /** * Removes a directive name corresponding class or attribute. * @param directiveName - The directive name. * @returns Returns current dom node. */ removeDirective(directiveName: string): null | $T<TElement>; /** * Hide or show all marked nodes which should be displayed depending on * javascript availability. */ renderJavaScriptDependentVisibility(): void; /** * Determines a normalized camel case directive name representation. * @param directiveName - The directive name. * @returns Returns the corresponding name. */ static getNormalizedDirectiveName(directiveName: string): string; /** * Determines a directive attribute value. * @param directiveName - The directive name. * @returns Returns the corresponding attribute value or "null" if no * attribute value exists. */ getDirectiveValue(directiveName: string): null | string; /** * Removes a selector prefix from a given selector. These methods search in * the options object for a given "domNodeSelectorPrefix". * @param domNodeSelector - The dom node selector to slice. * @returns Returns the sliced selector. */ sliceDomNodeSelectorPrefix(domNodeSelector: string): string; /** * Determines the dom node name of a given dom node string. * @param domNodeSelector - A given to dom node selector to determine its * name. * @returns Returns The dom node name. * @example * // returns 'div' * $.Tools.getDomNodeName('&lt;div&gt;') * @example * // returns 'div' * $.Tools.getDomNodeName('&lt;div&gt;&lt;/div&gt;') * @example * // returns 'br' * $.Tools.getDomNodeName('&lt;br/&gt;') */ static getDomNodeName(domNodeSelector: string): null | string; /** * Converts an object of dom selectors to an array of $ wrapped dom nodes. * Note if selector description as one of "class" or "id" as suffix element * will be ignored. * @param domNodeSelectors - An object with dom node selectors. * @param wrapperDomNode - A dom node to be the parent or wrapper of all * retrieved dom nodes. * @returns Returns All $ wrapped dom nodes corresponding to given * selectors. */ grabDomNodes(domNodeSelectors: Mapping, wrapperDomNode?: Node | null | string | $T<Node>): $DomNodes; /** * Searches for internal event handler methods and runs them by default. In * addition, this method searches for a given event method by the options * object. Additional arguments are forwarded to respective event * functions. * @param eventName - An event name. * @param callOnlyOptionsMethod - Prevents from trying to call an internal * event handler. * @param scope - The scope from where the given event handler should be * called. * @param additionalArguments - Additional arguments to forward to * corresponding event handlers. * @returns - Returns result of an options event handler (when called) and * "true" otherwise. */ fireEvent(eventName: string, callOnlyOptionsMethod?: boolean, scope?: unknown, ...additionalArguments: Array<unknown>): unknown; /** * A wrapper method for "$.on()". It sets current plugin name as event * scope if no scope is given. Given arguments are modified and passed * through "$.on()". * @param parameters - Parameter to forward. * @returns Returns $'s grabbed dom node. */ on<TElement = HTMLElement>(...parameters: Array<unknown>): $T<TElement>; /** * A wrapper method fo "$.off()". It sets current plugin name as event * scope if no scope is given. Given arguments are modified and passed * through "$.off()". * @param parameters - Parameter to forward. * @returns Returns $'s grabbed dom node. */ off<TElement = HTMLElement>(...parameters: Array<unknown>): $T<TElement>; /** * Helper method for attach/remove event handler methods. * @param parameters - Arguments object given to methods like "on()" or * "off()". * @param removeEvent - Indicates if handler should be attached or removed. * @param eventFunctionName - Name of function to wrap. * @returns Returns $'s wrapped dom node. */ _bindEventHelper: <TElement_1 = HTMLElement>(parameters: Array<unknown>, removeEvent?: boolean, eventFunctionName?: string) => $T<TElement_1>; } /** * Dom bound version of Tools class. */ export declare class BoundTools<TElement = HTMLElement> extends Tools<TElement> { $domNode: $T<TElement>; readonly self: typeof BoundTools; /** * This method should be overwritten normally. It is triggered if current * object is created via the "new" keyword. The dom node selector prefix * enforces to not globally select any dom nodes which aren't in the * expected scope of this plugin. "{1}" will be automatically replaced with * this plugin name suffix ("tools"). You don't have to use "{1}" but it * can help you to write code which is more reconcilable with the dry * concept. * @param $domNode - $-extended dom node to use as reference in various * methods. * @param additionalParameters - Additional parameters to call super method * with. */ constructor($domNode: $T<TElement>, ...additionalParameters: ParametersExceptFirst<Tools['constructor']>); } export default Tools;