Skip to content

Commit

Permalink
Add types for jquery.spinner
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrien LESÉNÉCHAL committed Mar 8, 2024
1 parent 6f818b6 commit 6fe67cc
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 1 deletion.
2 changes: 1 addition & 1 deletion jquery/makeCollapsible.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ declare global {
* - The inner content is wrapped in a "div.mw-collapsible-content" (except for tables and lists).
*
* @param {Options} [options]
* @return {JQuery}
* @returns {JQuery}
*/
makeCollapsible(options?: Options): this;
}
Expand Down
85 changes: 85 additions & 0 deletions jquery/spinner.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
declare global {
interface JQueryStatic {
/**
* Create a spinner element
*
* The argument is an object with options used to construct the spinner (see below).
*
* It is a good practice to keep a reference to the created spinner to be able to remove it
* later. Alternatively, one can use the 'id' option and #removeSpinner (but make sure to choose
* an id that's unlikely to cause conflicts, e.g. with extensions, gadgets or user scripts).
*
* CSS classes used:
*
* - .mw-spinner for every spinner
* - .mw-spinner-small / .mw-spinner-large for size
* - .mw-spinner-block / .mw-spinner-inline for display types
*
* @example
* ```js
* // Create a large spinner reserving all available horizontal space.
* var $spinner = $.createSpinner( { size: 'large', type: 'block' } );
* // Insert above page content.
* $( '#mw-content-text' ).prepend( $spinner );
*
* // Place a small inline spinner next to the "Save" button
* var $spinner = $.createSpinner( { size: 'small', type: 'inline' } );
* // Alternatively, just `$.createSpinner();` as these are the default options.
* $( '#wpSave' ).after( $spinner );
*
* // The following two are equivalent:
* $.createSpinner( 'magic' );
* $.createSpinner( { id: 'magic' } );
* ```
*
* @param {string|Options} [opts] Options. If a string is given, it will be treated as the value
* of the `id` option.
* @returns {JQuery}
*/
createSpinner(opts?: string | Options): JQuery;

/**
* Remove a spinner element.
*
* @param {string} id Id of the spinner, as passed to {@link createSpinner}
* @returns {JQuery} The (now detached) spinner element
*/
removeSpinner(id: string): JQuery;
}

interface JQuery {
/**
* Inject a spinner after each element in the collection
*
* Inserts spinner as siblings (not children) of the target elements.
* Collection contents remain unchanged.
*
* @param {string|Object} [opts] Options. If a string is given, it will be treated as the value
* of the `id` option.
* @returns {JQuery}
*/
injectSpinner(opts?: string | Options): this;
}
}

type Size = "large" | "small";
type Type = "block" | "inline";

interface Options {
/**
* If given, spinner will be given an id of "mw-spinner-{id}".
*/
id?: string | undefined;

/**
* 'small' or 'large' for a 20-pixel or 32-pixel spinner.
*/
size?: Size;

/**
* 'inline' or 'block'. Inline creates an inline-block with width and height equal to spinner size. Block is a block-level element with width 100%, height equal to spinner size.
*/
type?: Type;
}

export {};

0 comments on commit 6fe67cc

Please sign in to comment.