From 8dabf6b9a03eac56e6a3bb899baa9db56992c862 Mon Sep 17 00:00:00 2001 From: Behind The Math Date: Thu, 15 Mar 2018 16:02:45 -0400 Subject: [PATCH] Fix structure of TS definition file --- pjax.d.ts | 61 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/pjax.d.ts b/pjax.d.ts index ac73f3b..513ea39 100644 --- a/pjax.d.ts +++ b/pjax.d.ts @@ -1,8 +1,8 @@ -export = class Pjax { - constructor(options?: Partial); +declare class Pjax { + constructor(options?: Partial); 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 { +declare namespace Pjax { + export interface IOptions { + elements: string; + selectors: string[]; + switches: StringKeyedObject; + 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 { [key: string]: T } -export interface IOptions { - elements: string; - selectors: string[]; - switches: StringKeyedObject; - 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;