declare global {
interface JQuery {
/**
* Enable inline confirmation for given clickable element (like `` or ``).
*
* An additional inline confirmation step being shown before the default action is carried out on
* click.
*
* Calling `.confirmable( { handler: function () { … } } )` will fire the handler only after the
* confirmation step.
*
* The element will have the `jquery-confirmable-element` class added to it when it's clicked for
* the first time, which has `white-space: nowrap;` and `display: inline-block;` defined in CSS.
* If the computed values for the element are different when you make it confirmable, you might
* encounter unexpected behavior.
*
* To use this {@link jQuery} plugin, load the `jquery.confirmable` module with {@link mw.loader}.
*
* @example
* ```js
* mw.loader.using( 'jquery.confirmable' ).then( () => {
* $( 'button' ).confirmable();
* } );
* ```
* @see https://doc.wikimedia.org/mediawiki-core/master/js/module-jquery.confirmable.html#.$.fn.confirmable
*/
confirmable: Confirmable;
}
}
// make all properties required, replacing optional values with undefined,
// whether "exactOptionalPropertyTypes" is enabled or not.
type RequiredOrUndefined = {
[P in keyof Required]: T[P];
};
interface Confirmable {
(options?: Options): this;
/**
* Default options. Overridable primarily for internationalisation handling.
*/
defaultOptions: RequiredOptions;
handler(event: JQuery.Event, options: RequiredOptions): void;
}
type RequiredOptions = Required & { i18n: RequiredOrUndefined };
interface Options {
/**
* Optional selector used for jQuery event delegation.
*/
delegate?: string | null;
/**
* Events to hook to.
*/
events?: string;
/**
* Text to use for interface elements.
*/
i18n?: I18N;
/**
* Callback to fire when preparing confirmable buttons. It is fired separately for the 'Yes' and 'No' button.
* Receives the button jQuery object as the first parameter and 'yes' or 'no' as the second.
*/
buttonCallback?($button: JQuery): JQuery;
/**
* Callback to fire when the action is confirmed (user clicks the 'Yes' button).
*/
handler?: ((event: JQuery.Event) => void) | null;
/**
* Callback to fire when preparing confirmable interface.
* Receives the interface jQuery object as the only parameter.
*/
wrapperCallback?($interface: JQuery): JQuery;
}
// tslint:disable-next-line:interface-name
interface I18N {
/**
* Text to use for the confirmation question.
* Defaults to `Are you sure?`.
*/
confirm: string;
/**
* Text to use for the 'No' button.
* Defaults to `No`.
*/
no: string;
/**
* Optional title text to use for the 'No' button.
*/
noTitle?: string;
/**
* Word separator to place between the three text messages.
* Defaults to ` `.
*/
space: string;
/**
* Text to use for the 'Yes' button.
* Defaults to `Yes`.
*/
yes: string;
/**
* Optional title text to use for the 'Yes' button.
*/
yesTitle?: string;
}
export {};