Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to 1.41, fix types & cleanup docs #36

Merged
merged 21 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Edit your project's `tsconfig.json` file so that it includes
]
```

You should be all set! `mw` will be available in the global scope. There is no need to put any import statements in the TypeScript source files.
You should be all set! `mw` will be available in the global scope. There is no need to put any import statements in the TypeScript source files.

**If you find any errors or have suggestions for more specific typings, please open a PR or file an issue.**

Expand Down Expand Up @@ -58,4 +58,3 @@ import type { ApiEditPageParams, ApiParseParams } from "types-mediawiki/api_para
```

Since it is just a type import, it doesn't generate any JavaScript. Hence, such imports can also be used in non-modular applications.

127 changes: 77 additions & 50 deletions jquery/client.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
declare global {
interface JQueryStatic {
/**
* User-agent detection
*/
client: Client;
}
}
Expand All @@ -10,26 +13,30 @@ interface Client {
*
* The resulting client object will be in the following format:
*
* {
* 'name': 'firefox',
* 'layout': 'gecko',
* 'layoutVersion': 20101026,
* 'platform': 'linux'
* 'version': '3.5.1',
* 'versionBase': '3',
* 'versionNumber': 3.5,
* }
* ```js
* {
* 'name': 'firefox',
* 'layout': 'gecko',
* 'layoutVersion': 20101026,
* 'platform': 'linux'
* 'version': '3.5.1',
* 'versionBase': '3',
* 'versionNumber': 3.5,
* }
* ```
*
* Example:
*
* if ( $.client.profile().layout == 'gecko' ) {
* // This will only run in Gecko browsers, such as Mozilla Firefox.
* }
* ```js
* if ( $.client.profile().layout == 'gecko' ) {
* // This will only run in Gecko browsers, such as Mozilla Firefox.
* }
*
* var profile = $.client.profile();
* if ( profile.layout == 'gecko' && profile.platform == 'linux' ) {
* // This will only run in Gecko browsers on Linux.
* }
* var profile = $.client.profile();
* if ( profile.layout == 'gecko' && profile.platform == 'linux' ) {
* // This will only run in Gecko browsers on Linux.
* }
* ```
*
* Recognised browser names:
*
Expand Down Expand Up @@ -71,7 +78,7 @@ interface Client {
* Defaults to the global `navigator` object.
* @return {Object} The client object
*/
profile(nav?: { userAgent: string; platform: string }): ClientProfile;
profile(nav?: ClientNavigator): ClientProfile;

/**
* Checks the current browser against a support map object.
Expand All @@ -82,53 +89,73 @@ interface Client {
*
* A browser map is in the following format:
*
* {
* // Multiple rules with configurable operators
* 'msie': [['>=', 7], ['!=', 9]],
* // Match no versions
* 'iphone': false,
* // Match any version
* 'android': null
* }
* ```js
* {
* // Multiple rules with configurable operators
* 'msie': [['>=', 7], ['!=', 9]],
* // Match no versions
* 'iphone': false,
* // Match any version
* 'android': null
* }
* ```
*
* It can optionally be split into ltr/rtl sections:
*
* {
* 'ltr': {
* 'android': null,
* 'iphone': false
* },
* 'rtl': {
* 'android': false,
* // rules are not inherited from ltr
* 'iphone': false
* }
* ```js
* {
* 'ltr': {
* 'android': null,
* 'iphone': false
* },
* 'rtl': {
* 'android': false,
* // rules are not inherited from ltr
* 'iphone': false
* }
* }
* ```
*
* @param {Object} map Browser support map
* @param {Object} [profile] A client-profile object
* @param {boolean} [exactMatchOnly=false] Only return true if the browser is matched,
* otherwise returns true if the browser is not found.
*
* @return {boolean} The current browser is in the support map
*/
test(map: any, profile?: ClientProfile, exactMatchOnly?: boolean): boolean;
test(
map: ClientSupportMap | { ltr: ClientSupportMap; rtl: ClientSupportMap },
profile?: ClientProfile,
exactMatchOnly?: boolean
): boolean;
}

export interface ClientNavigator {
userAgent: string;
platform: string;
}

type ClientProfileName =
| "android"
| "chrome"
| "crios"
| "edge"
| "firefox"
| "fxios"
| "konqueror"
| "msie"
| "opera"
| "rekong"
| "safari"
| "silk";

type ClientSupportMap = Partial<Record<ClientProfileName, false | null | ClientSupportCondition[]>>;
type ClientSupportCondition = [
"==" | "===" | "!=" | "!==" | "<" | "<=" | ">" | ">=",
string | number
];

interface ClientProfile {
name:
| "android"
| "chrome"
| "crios"
| "edge"
| "firefox"
| "fxios"
| "konqueror"
| "msie"
| "opera"
| "rekong"
| "safari"
| "silk";
name: ClientProfileName;
layout: "edge" | "gecko" | "khtml" | "presto" | "trident" | "webkit";
layoutVersion: number;
platform: "ipad" | "iphone" | "linux" | "mac" | "solaris" | "win";
Expand Down
16 changes: 12 additions & 4 deletions jquery/collapsibleTabs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,21 @@ declare global {
}
}

/** A jQuery plugin that makes collapsible tabs for the Vector skin. */
/**
* A jQuery plugin that makes collapsible tabs for the Vector skin.
*/
interface CollapsibleTabsOptions {
/** Optional tab selector. Defaults to `#p-views ul`. */
/**
* Optional tab selector. Defaults to `#p-views ul`.
*/
expandedContainer: string;
/** Optional menu item selector. Defaults to `#p-cactions ul`. */
/**
* Optional menu item selector. Defaults to `#p-cactions ul`.
*/
collapsedContainer: string;
/** Optional selector for tabs that are collapsible. Defaults to `li.collapsible`. */
/**
* Optional selector for tabs that are collapsible. Defaults to `li.collapsible`.
*/
collapsible: string;
shifting: boolean;
expandedWidth: number;
Expand Down
10 changes: 6 additions & 4 deletions jquery/colorUtil.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ interface ColorUtil {
*
* Usage:
*
* $.colorUtil.getColorBrightness( 'red', +0.1 );
* // > "rgb(255,50,50)"
* $.colorUtil.getColorBrightness( 'rgb(200,50,50)', -0.2 );
* // > "rgb(118,29,29)"
* ```js
* $.colorUtil.getColorBrightness( 'red', +0.1 );
* // > "rgb(255,50,50)"
* $.colorUtil.getColorBrightness( 'rgb(200,50,50)', -0.2 );
* // > "rgb(118,29,29)"
* ```
*
* @param {Mixed} currentColor Current value in css
Derugon marked this conversation as resolved.
Show resolved Hide resolved
* @param {number} mod Wanted brightness modification between -1 and 1
Expand Down
4 changes: 2 additions & 2 deletions jquery/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "jquery";

import "./textSelection";
import "./collapsibleTabs";
import "./client";
import "./collapsibleTabs";
import "./colorUtil";
import "./textSelection";
Loading
Loading