naja
Version:
Modern AJAX library for Nette Framework
61 lines (60 loc) • 2.23 kB
TypeScript
import { Naja, Options } from '../Naja';
import { TypedEventListener } from '../utils';
declare const originalTitleKey: unique symbol;
declare module '../Naja' {
interface Options {
history?: HistoryMode;
href?: string;
[originalTitleKey]?: string;
}
interface Payload {
postGet?: boolean;
url?: string;
}
}
export interface HistoryState extends Record<string, any> {
source: string;
cursor: number;
href: string;
}
export interface HistoryAdapter {
replaceState(state: HistoryState, title: string, url: string): void;
pushState(state: HistoryState, title: string, url: string): void;
}
export type HistoryMode = boolean | 'replace';
export declare class HistoryHandler extends EventTarget {
private readonly naja;
private initialized;
private cursor;
popStateHandler: (event: PopStateEvent) => void;
historyAdapter: HistoryAdapter;
constructor(naja: Naja);
set uiCache(value: boolean);
private handlePopState;
private initialize;
private saveOriginalTitle;
private saveUrl;
private saveRedirectedUrl;
private replaceInitialState;
private configureMode;
static normalizeMode(mode: string | boolean | null | undefined): HistoryMode;
private pushNewState;
private buildState;
addEventListener: <K extends keyof HistoryHandlerEventMap | string>(type: K, listener: TypedEventListener<HistoryHandler, K extends keyof HistoryHandlerEventMap ? HistoryHandlerEventMap[K] : CustomEvent>, options?: boolean | AddEventListenerOptions) => void;
removeEventListener: <K extends keyof HistoryHandlerEventMap | string>(type: K, listener: TypedEventListener<HistoryHandler, K extends keyof HistoryHandlerEventMap ? HistoryHandlerEventMap[K] : CustomEvent>, options?: boolean | AddEventListenerOptions) => void;
}
export type BuildStateEvent = CustomEvent<{
state: HistoryState;
operation: 'pushState' | 'replaceState';
options: Options;
}>;
export type RestoreStateEvent = CustomEvent<{
state: HistoryState;
direction: number;
options: Options;
}>;
interface HistoryHandlerEventMap {
buildState: BuildStateEvent;
restoreState: RestoreStateEvent;
}
export {};