Skip to content

Commit

Permalink
Fix confirmable options & update some URLs
Browse files Browse the repository at this point in the history
- fix `$().confirmable` not allowing omitting some option properties
- update some jQuery plugin URLs, changed since 1.42 release
  • Loading branch information
Adrien LESÉNÉCHAL committed May 27, 2024
1 parent 3b52099 commit b033eeb
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 21 deletions.
33 changes: 20 additions & 13 deletions jquery/confirmable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,58 +21,65 @@ declare global {
* $( 'button' ).confirmable();
* } );
* ```
* @see https://doc.wikimedia.org/mediawiki-core/master/js/jQueryPlugins.html#.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
type RequiredOrUndefined<T> = {
[P in keyof Required<T>]: undefined extends T[P] ? T[P] | undefined : T[P];
};

interface Confirmable {
/**
* @param {Partial<Options>} [options]
* @param {Options} [options]
*/
(options?: Partial<Options>): this;
(options?: Options): this;

/**
* Default options. Overridable primarily for internationalisation handling.
*/
defaultOptions: Options;
defaultOptions: RequiredOptions;

handler(event: JQuery.Event, options: Options): void;
handler(event: JQuery.Event, options: RequiredOptions): void;
}

type RequiredOptions = Required<Options> & { i18n: RequiredOrUndefined<I18N> };

interface Options {
/**
* Optional selector used for jQuery event delegation.
*/
delegate: string | null;
delegate?: string | null;

/**
* Events to hook to.
*/
events: string;
events?: string;

/**
* Text to use for interface elements.
*/
i18n: I18N;
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;
buttonCallback?($button: JQuery): JQuery;

/**
* Callback to fire when the action is confirmed (user clicks the 'Yes' button).
*/
handler: ((event: JQuery.Event) => void) | null;
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;
wrapperCallback?($interface: JQuery): JQuery;
}

// tslint:disable-next-line:interface-name
Expand All @@ -92,7 +99,7 @@ interface I18N {
/**
* Optional title text to use for the 'No' button.
*/
noTitle: string | undefined;
noTitle?: string | undefined;

/**
* Word separator to place between the three text messages.
Expand All @@ -109,7 +116,7 @@ interface I18N {
/**
* Optional title text to use for the 'Yes' button.
*/
yesTitle: string | undefined;
yesTitle?: string | undefined;
}

export {};
4 changes: 2 additions & 2 deletions jquery/cookie.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ declare global {
* @param {mw.cookie.CookieOptions} [options]
* @returns {string|Object} The current value (if getting a cookie), or an internal `document.cookie`
* expression (if setting or removing).
* @see https://doc.wikimedia.org/mediawiki-core/master/js/jQueryPlugins.html#.cookie
* @see https://doc.wikimedia.org/mediawiki-core/master/js/module-mediawiki.cookie.html#.$.cookie
*/
cookie(key: string, value: string | null, options?: mw.cookie.CookieOptions): string;
cookie(key: string): unknown;
Expand All @@ -34,7 +34,7 @@ declare global {
* @param {string} key
* @param {mw.cookie.CookieOptions} options
* @returns {boolean} True if the cookie previously existed
* @see https://doc.wikimedia.org/mediawiki-core/master/js/jQueryPlugins.html#.removeCookie
* @see https://doc.wikimedia.org/mediawiki-core/master/js/module-mediawiki.cookie.html#.$.removeCookie
*/
removeCookie(key: string, options: mw.cookie.CookieOptions): boolean;
}
Expand Down
2 changes: 1 addition & 1 deletion jquery/highlightText.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ declare global {
* @param {string} matchString String to match
* @param {Options} [options]
* @returns {JQuery}
* @see https://doc.wikimedia.org/mediawiki-core/master/js/jQueryPlugins.html#.highlightText
* @see https://doc.wikimedia.org/mediawiki-core/master/js/module-jquery.highlightText.html#.$.fn.highlightText
*/
highlightText(matchString: string, options?: Options): this;
}
Expand Down
6 changes: 3 additions & 3 deletions jquery/lengthLimit.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ declare global {
* @param {number} byteLimit Number of bytes the value may be in size.
* @param {FilterFunction} [filterFunction] Function to call on the string before assessing the length.
* @returns {TrimResult}
* @see https://doc.wikimedia.org/mediawiki-core/master/js/jQueryPlugins.html#.trimByteLength
* @see https://doc.wikimedia.org/mediawiki-core/master/js/module-jquery.lengthLimit.html#.'$.fn.trimByteLength'
*/
trimByteLength(
safeVal: string,
Expand All @@ -40,7 +40,7 @@ declare global {
* called with fetched value as argument.
* @param {FilterFunction} [filterFunction] Function to call on the string before assessing the length.
* @returns {JQuery}
* @see https://doc.wikimedia.org/mediawiki-core/master/js/jQueryPlugins.html#.byteLimit
* @see https://doc.wikimedia.org/mediawiki-core/master/js/module-jquery.lengthLimit.html#.$.fn.byteLimit
*/
byteLimit(limit: number, filterFunction?: FilterFunction): this;
byteLimit(filterFunction?: FilterFunction): this;
Expand All @@ -62,7 +62,7 @@ declare global {
* called with fetched value as argument.
* @param {FilterFunction} [filterFunction] Function to call on the string before assessing the length.
* @returns {JQuery}
* @see https://doc.wikimedia.org/mediawiki-core/master/js/jQueryPlugins.html#.codePointLimit
* @see https://doc.wikimedia.org/mediawiki-core/master/js/module-jquery.lengthLimit.html#.$.fn.codePointLimit
*/
codePointLimit(limit: number, filterFunction?: FilterFunction): this;
codePointLimit(filterFunction?: FilterFunction): this;
Expand Down
2 changes: 1 addition & 1 deletion jquery/makeCollapsible.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ declare global {
* ```
* @param {Options} [options]
* @returns {JQuery}
* @see https://doc.wikimedia.org/mediawiki-core/master/js/jQueryPlugins.html#.makeCollapsible
* @see https://doc.wikimedia.org/mediawiki-core/master/js/module-jquery.makeCollapsible.html#.$.fn.makeCollapsible
*/
makeCollapsible(options?: Options): this;
}
Expand Down
5 changes: 5 additions & 0 deletions jquery/spinner.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ declare global {
type Size = "large" | "small";
type Type = "block" | "inline";

/**
* Options for {@link JQuery.injectSpinner}.
*
* @see https://doc.wikimedia.org/mediawiki-core/master/js/jQueryPlugins.html#~SpinnerOpts
*/
interface Options {
/**
* If given, spinner will be given an id of "mw-spinner-{id}".
Expand Down
2 changes: 1 addition & 1 deletion jquery/updateTooltipAccessKeys.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface TooltipAccessKeys<This = JQuery> {
* } );
* ```
* @returns {JQuery}
* @see https://doc.wikimedia.org/mediawiki-core/master/js/jQueryPlugins.html#.updateTooltipAccessKeys
* @see https://doc.wikimedia.org/mediawiki-core/REL1_42/js/jQueryPlugins.html#.updateTooltipAccessKeys
*/
(): This;

Expand Down

0 comments on commit b033eeb

Please sign in to comment.