|
| 1 | +// Type definitions for GStime 2.0.0 |
| 2 | + |
| 3 | +export interface AjaxSettings { |
| 4 | + url: string; |
| 5 | + method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD" | string; |
| 6 | + headers?: Record<string, string>; |
| 7 | + data?: unknown; |
| 8 | + timeout?: number; |
| 9 | + credentials?: RequestCredentials; |
| 10 | + mode?: RequestMode; |
| 11 | + cache?: RequestCache; |
| 12 | + redirect?: RequestRedirect; |
| 13 | + referrer?: string; |
| 14 | + integrity?: string; |
| 15 | + beforeSend?: () => boolean | void; |
| 16 | + success?: (data: unknown) => void; |
| 17 | + error?: (error: Error) => void; |
| 18 | + complete?: () => void; |
| 19 | +} |
| 20 | + |
| 21 | +export interface Offset { |
| 22 | + top: number; |
| 23 | + left: number; |
| 24 | +} |
| 25 | + |
| 26 | +export type GStimeSelector = |
| 27 | + | string |
| 28 | + | Element |
| 29 | + | Document |
| 30 | + | Window |
| 31 | + | NodeList |
| 32 | + | HTMLCollection |
| 33 | + | Element[] |
| 34 | + | (() => void) |
| 35 | + | null |
| 36 | + | undefined; |
| 37 | + |
| 38 | +export class GStime { |
| 39 | + constructor(selector?: GStimeSelector); |
| 40 | + elements: Element[]; |
| 41 | + |
| 42 | + createHTML(html: string): Element[]; |
| 43 | + each(callback: (this: Element, index: number, el: Element) => void): this; |
| 44 | + |
| 45 | + on(event: string, callback: (this: Element, e: Event) => void): this; |
| 46 | + on(event: string, selector: string, callback: (this: Element, e: Event) => void): this; |
| 47 | + off(event: string, callback?: (this: Element, e: Event) => void): this; |
| 48 | + |
| 49 | + val(): string | undefined; |
| 50 | + val(newVal: string): this; |
| 51 | + |
| 52 | + append(html: string): this; |
| 53 | + prepend(html: string): this; |
| 54 | + before(html: string): this; |
| 55 | + after(html: string): this; |
| 56 | + remove(): this; |
| 57 | + |
| 58 | + html(): string | undefined; |
| 59 | + html(html: string): this; |
| 60 | + |
| 61 | + css(prop: string): string | undefined; |
| 62 | + css(prop: string, value: string | number): this; |
| 63 | + css(properties: Record<string, string | number>): this; |
| 64 | + |
| 65 | + hide(): this; |
| 66 | + show(): this; |
| 67 | + toggle(): this; |
| 68 | + clone(): GStime; |
| 69 | + |
| 70 | + animate(properties: Record<string, number | string>, duration: number, callback?: () => void): this; |
| 71 | + fadeIn(duration: number, callback?: () => void): this; |
| 72 | + fadeOut(duration: number, callback?: () => void): this; |
| 73 | + slideUp(duration: number, callback?: (this: Element) => void): this; |
| 74 | + slideDown(duration: number, callback?: (this: Element) => void): this; |
| 75 | + slideToggle(duration: number, callback?: (this: Element) => void): this; |
| 76 | + colorAnimate(properties: Record<string, string>, duration: number, callback?: () => void): this; |
| 77 | + |
| 78 | + hasClass(className: string): boolean; |
| 79 | + addClass(className: string): this; |
| 80 | + removeClass(className: string): this; |
| 81 | + toggleClass(className: string): this; |
| 82 | + |
| 83 | + attr(name: string): string | null | undefined; |
| 84 | + attr(name: string, value: string): this; |
| 85 | + removeAttr(name: string): this; |
| 86 | + |
| 87 | + width(): number | undefined; |
| 88 | + width(value: number | string): this; |
| 89 | + height(): number | undefined; |
| 90 | + height(value: number | string): this; |
| 91 | + |
| 92 | + offset(): Offset | undefined; |
| 93 | + position(): Offset | undefined; |
| 94 | + |
| 95 | + parent(): GStime; |
| 96 | + children(): GStime; |
| 97 | + siblings(): GStime; |
| 98 | + find(selector: string): GStime; |
| 99 | + closest(selector: string): GStime; |
| 100 | + |
| 101 | + static ajax(settings: AjaxSettings): Promise<unknown>; |
| 102 | + static get(url: string, data?: unknown, options?: Partial<AjaxSettings>): Promise<unknown>; |
| 103 | + static post(url: string, data?: unknown, options?: Partial<AjaxSettings>): Promise<unknown>; |
| 104 | + static put(url: string, data?: unknown, options?: Partial<AjaxSettings>): Promise<unknown>; |
| 105 | + static delete(url: string, data?: unknown, options?: Partial<AjaxSettings>): Promise<unknown>; |
| 106 | + |
| 107 | + static each<T>(obj: T[] | Record<string, T>, callback: (this: T, key: string | number, value: T) => void): typeof obj; |
| 108 | + static map<T, U>(obj: T[], callback: (value: T, index: number) => U): U[]; |
| 109 | + static map<T, U>(obj: Record<string, T>, callback: (this: T, key: string, value: T) => U): Record<string, U>; |
| 110 | + static ready(callback: () => void): void; |
| 111 | + static noConflict(): GStimeFactory; |
| 112 | +} |
| 113 | + |
| 114 | +export interface GStimeFactory { |
| 115 | + (selector?: GStimeSelector): GStime; |
| 116 | + fn: GStime; |
| 117 | + ajax: typeof GStime.ajax; |
| 118 | + get: typeof GStime.get; |
| 119 | + post: typeof GStime.post; |
| 120 | + put: typeof GStime.put; |
| 121 | + delete: typeof GStime.delete; |
| 122 | + each: typeof GStime.each; |
| 123 | + map: typeof GStime.map; |
| 124 | + ready: typeof GStime.ready; |
| 125 | + noConflict: typeof GStime.noConflict; |
| 126 | +} |
| 127 | + |
| 128 | +declare const _default: { GStime: typeof GStime; $: GStimeFactory }; |
| 129 | +export default _default; |
| 130 | +export const $: GStimeFactory; |
| 131 | + |
| 132 | +declare global { |
| 133 | + interface Window { |
| 134 | + GStime: typeof GStime; |
| 135 | + $: GStimeFactory; |
| 136 | + } |
| 137 | +} |
0 commit comments