Fix structure of TS definition file

This commit is contained in:
Behind The Math
2018-03-15 16:02:45 -04:00
parent 7a07a435bc
commit 8dabf6b9a0

61
pjax.d.ts vendored
View File

@@ -1,8 +1,8 @@
export = class Pjax {
constructor(options?: Partial<IOptions>);
declare class Pjax {
constructor(options?: Partial<Pjax.IOptions>);
static switches: {
[key: string]: Switch
[key in DefaultSwitches]: Pjax.Switch
};
static isSupported: () => boolean;
@@ -23,45 +23,58 @@ export = class Pjax {
forEachSelectors(cb: ElementFunction, context: Pjax, DOMcontext?: Element | Document): void;
switchesSelectors(selectors: string[], fromEl: Element | Document, toEl: Element | Document, options: IOptions): void;
switchesSelectors(selectors: string[], fromEl: Element | Document, toEl: Element | Document, options: Pjax.IOptions): void;
latestChance(href: string): void;
onSwitch: VoidFunction;
loadContent(html: string, options: IOptions): void;
loadContent(html: string, options: Pjax.IOptions): void;
abortRequest(request: XMLHttpRequest): void;
doRequest(location: string, options: IOptions | null,
doRequest(location: string, options: Pjax.IOptions | null,
callback: (requestText: string, request: XMLHttpRequest, href: string) => void): XMLHttpRequest;
handleResponse(requestText: string, request: XMLHttpRequest, href: string): void;
loadUrl(href: string, options?: IOptions): void;
loadUrl(href: string, options?: Pjax.IOptions): void;
afterAllSwitches: VoidFunction;
// Allows reassignment of existing prototype functions to be able to do something before calling the original function
[key: string]: Function;
}
export interface StringKeyedObject<T = any> {
declare namespace Pjax {
export interface IOptions {
elements: string;
selectors: string[];
switches: StringKeyedObject<Switch>;
switchesOptions: StringKeyedObject;
history: boolean;
analytics: Function | false;
scrollTo: number | [number, number] | false;
scrollRestoration: boolean;
cacheBust: boolean;
debug: boolean;
timeout: number;
currentUrlFullReload: boolean;
}
export type Switch = (oldEl: Element, newEl: Element, options?: IOptions, switchesOptions?: StringKeyedObject) => void;
}
interface StringKeyedObject<T = any> {
[key: string]: T
}
export interface IOptions {
elements: string;
selectors: string[];
switches: StringKeyedObject<Switch>;
switchesOptions: StringKeyedObject;
history: boolean;
analytics: Function | false;
scrollTo: number | number[] | false;
scrollRestoration: boolean;
cacheBust: boolean;
debug: boolean;
timeout: number
currentUrlFullReload: boolean;
type ElementFunction = (el: Element) => void;
declare enum DefaultSwitches {
innerHTML = "innerHTML",
ouetrHTML = "outerHTML",
sideBySide = "sideBySide"
}
export type Switch = (oldEl: Element, newEl: Element, options?: IOptions, switchesOptions?: StringKeyedObject) => void;
export type ElementFunction = (el: Element) => void;
export = Pjax;