-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Adrien LESÉNÉCHAL
committed
Mar 8, 2024
1 parent
6f818b6
commit 6fe67cc
Showing
2 changed files
with
86 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {}; |