Chosen.js update types for v1.8.5 (#25238)

Add new options: group_search, hide_results_on_select, rtl
Activate `strictNullChecks`
Remove colon after `@default`
Add jsDoc to `on` and `trigger` function
Add line return before jsDoc first line
Remove all exception rules to tslint (unified-signatures,
max-line-length)
This commit is contained in:
denisname 2018-04-25 00:54:31 +02:00 committed by Wesley Wigham
parent 482390bbe7
commit 2f5d1477b9
4 changed files with 104 additions and 121 deletions

View File

@ -1,5 +1,3 @@
// Options
$(".my_select_box").chosen();
@ -12,14 +10,23 @@ $(".my_select_box").chosen({
width: "95%"
});
$(".chosen-select").chosen({
rtl: true
});
// Destroy
$(".my_select_box").chosen("destroy");
// Triggered Events
$(".my_select_box").on("change", function(evt, params) {
$(".my_select_box").on("change", (evt, params) => {
evt.preventDefault();
let s = params.selected;
console.log(s);
const s: string = params.selected;
const d: string = params.deselected;
console.log(s, d);
});
$(".chosen-select").on("chosen:maxselected", () => {
alert("Max selected");
});
// Triggerable Events

View File

@ -1,9 +1,11 @@
// Type definitions for Chosen.JQuery 1.6.1
// Type definitions for Chosen 1.8
// Project: http://harvesthq.github.com/chosen/
// Definitions by: Boris Yankov <https://github.com/borisyankov>, denis <https://github.com/denisname>
// Definitions by: Boris Yankov <https://github.com/borisyankov>, denisname <https://github.com/denisname>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
// Validated against Chosen version 1.8.5
/// <reference types="jquery"/>
declare namespace Chosen {
@ -11,71 +13,107 @@ declare namespace Chosen {
type TriggerEvent = "chosen:updated" | "chosen:activate" | "chosen:open" | "chosen:close";
interface Options {
/**When set to true on a single select, Chosen adds a UI element which selects the first element (if it is blank).
* @default: false
/**
* When set to true on a single select, Chosen adds a UI element which selects the first element (if it is blank).
* @default false
*/
allow_single_deselect?: boolean;
/**By default Chosen's search is case-insensitive. Setting this option to true makes the search case-sensitive.
* @default: false
/**
* By default, Chosen's search is case-insensitive. Setting this option to true makes the search case-sensitive.
* @default false
*/
case_sensitive_search?: boolean;
/**When set to true, Chosen will not display the search field (single selects only).
* @default: false
/**
* When set to true, Chosen will not display the search field (single selects only).
* @default false
*/
disable_search?: boolean;
/**Hide the search input on single selects if there are n or fewer options.
* @default: 0
/**
* Hide the search input on single selects if there are n or fewer options.
* @default 0
*/
disable_search_threshold?: number;
/**By default, searching will match on any word within an option tag. Set this option to false if you want to only match on the entire text of an option tag.
* @default: true
/**
* By default, searching will match on any word within an option tag. Set this option to false if you want to only match on the entire text of an option tag.
* @default true
*/
enable_split_word_search?: boolean;
/**When set to true, Chosen will grab any classes on the original select field and add them to Chosens container div.
* @default: false
/**
* By default, Chosen will search group labels as well as options, and filter to show all options below matching groups. Set this to false to search only in the options.
* @default true
*/
group_search?: boolean;
/**
* By default, Chosen's results are hidden after a option is selected. Setting this option to false will keep the results open after selection. This only applies to multiple selects.
* @default true
*/
hide_results_on_select?: boolean;
/**
* When set to true, Chosen will grab any classes on the original select field and add them to Chosens container div.
* @default false
*/
inherit_select_classes?: boolean;
/**Limits how many options the user can select. When the limit is reached, the chosen:maxselected event is triggered.
* @default: Infinity
/**
* Limits how many options the user can select. When the limit is reached, the `chosen:maxselected` event is triggered.
* @default Infinity
*/
max_selected_options?: number;
/**The text to be displayed when no matching results are found. The current search is shown at the end of the text (e.g., No results match "Bad Search").
* @default: "No results match"
/**
* The text to be displayed when no matching results are found. The current search is shown at the end of the text (e.g., No results match "Bad Search").
* @default "No results match"
*/
no_results_text?: string;
/**The text to be displayed as a placeholder when no options are selected for a multiple select.
* @default: "Select Some Options"
/**
* The text to be displayed as a placeholder when no options are selected for a multiple select.
* @default "Select Some Options"
*/
placeholder_text_multiple?: string;
/**The text to be displayed as a placeholder when no options are selected for a single select.
* @default: "Select an Option"
/**
* The text to be displayed as a placeholder when no options are selected for a single select.
* @default "Select an Option"
*/
placeholder_text_single?: string;
/**By default, Chosens search matches starting at the beginning of a word. Setting this option to true allows matches starting from anywhere within a word. This is especially useful for options that include a lot of special characters or phrases in ()s and []s.
* @default: false
/**
* Chosen supports right-to-left text in select boxes. Set this option to true to support right-to-left text options.
* @default false
*/
rtl?: boolean;
/**
* By default, Chosens search matches starting at the beginning of a word. Setting this option to true allows matches starting from anywhere within a word.
* This is especially useful for options that include a lot of special characters or phrases in ()s and []s.
* @default false
*/
search_contains?: boolean;
/**By default, pressing delete/backspace on multiple selects will remove a selected choice. When false, pressing delete/backspace will highlight the last choice, and a second press deselects it.
* @default: true
/**
* By default, pressing delete/backspace on multiple selects will remove a selected choice.
* When false, pressing delete/backspace will highlight the last choice, and a second press deselects it.
* @default true
*/
single_backstroke_delete?: boolean;
/**The width of the Chosen select box. By default, Chosen attempts to match the width of the select box you are replacing. If your select is hidden when Chosen is instantiated, you must specify a width or the select will show up with a width of 0. */
/**
* The width of the Chosen select box. By default, Chosen attempts to match the width of the select box you are replacing.
* If your select is hidden when Chosen is instantiated, you must specify a width or the select will show up with a width of 0.
*/
width?: string;
/**By default, Chosen includes disabled options in search results with a special styling. Setting this option to false will hide disabled results and exclude them from searches.
* @default: true
/**
* By default, Chosen includes disabled options in search results with a special styling. Setting this option to false will hide disabled results and exclude them from searches.
* @default true
*/
display_disabled_options?: boolean;
/**By default, Chosen includes selected options in search results with a special styling. Setting this option to false will hide selected results and exclude them from searches.
/**
* By default, Chosen includes selected options in search results with a special styling. Setting this option to false will hide selected results and exclude them from searches.
* Note: this is for multiple selects only. In single selects, the selected result will always be displayed.
* @default: true
* @default true
*/
display_selected_options?: boolean;
/**By default, Chosen only shows the text of a selected option. Setting this option to true will show the text and group (if any) of the selected option.
* @default: false
/**
* By default, Chosen only shows the text of a selected option. Setting this option to true will show the text and group (if any) of the selected option.
* @default false
*/
include_group_label_in_selected?: boolean;
/**Only show the first (n) matching options in the results. This can be used to increase performance for selects with very many options.
* @default: Infinity
/**
* Only show the first (n) matching options in the results. This can be used to increase performance for selects with very many options.
* @default Infinity
*/
max_shown_results?: number;
}
@ -87,13 +125,27 @@ declare namespace Chosen {
}
interface JQuery {
chosen(): JQuery;
chosen(options: Chosen.Options | "destroy"): JQuery;
chosen(options?: Chosen.Options | "destroy"): JQuery;
/**Chosen triggers the standard DOM event whenever a selection is made (it also sends a selected or deselected parameter that tells you which option was changed). */
/**
* Chosen triggers the standard DOM event whenever a selection is made (it also sends a selected or deselected parameter that tells you which option was changed).
*/
on(events: "change", handler: (eventObject: JQueryEventObject, args: Chosen.SelectedData) => any): JQuery;
/**
* * `chosen:ready` Triggered after Chosen has been fully instantiated.
* * `chosen:maxselected` Triggered if max_selected_options is set and that total is broken.
* * `chosen:showing_dropdown` Triggered when Chosens dropdown is opened.
* * `chosen:hiding_dropdown` Triggered when Chosens dropdown is closed.
* * `chosen:no_results` Triggered when a search returns no matching results.
*/
on(events: Chosen.OnEvent, handler: (eventObject: JQueryEventObject) => any): JQuery;
/**
* * `chosen:updated` This event should be triggered whenever Chosens underlying select element changes (such as a change in selected options).
* * `chosen:activate` This is the equivalant of focusing a standard HTML select field. When activated, Chosen will capure keypress events as if you had clicked the field directly.
* * `chosen:open` This event activates Chosen and also displays the search results.
* * `chosen:close` This event deactivates Chosen and hides the search results.
*/
trigger(eventType: Chosen.TriggerEvent): JQuery;
}

View File

@ -7,7 +7,7 @@
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": false,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [

View File

@ -1,79 +1,3 @@
{
"extends": "dtslint/dt.json",
"rules": {
"adjacent-overload-signatures": false,
"array-type": false,
"arrow-return-shorthand": false,
"ban-types": false,
"callable-types": false,
"comment-format": false,
"dt-header": false,
"eofline": false,
"export-just-namespace": false,
"import-spacing": false,
"interface-name": false,
"interface-over-type-literal": false,
"jsdoc-format": false,
"max-line-length": false,
"member-access": false,
"new-parens": false,
"no-any-union": false,
"no-boolean-literal-compare": false,
"no-conditional-assignment": false,
"no-consecutive-blank-lines": false,
"no-construct": false,
"no-declare-current-package": false,
"no-duplicate-imports": false,
"no-duplicate-variable": false,
"no-empty-interface": false,
"no-for-in-array": false,
"no-inferrable-types": false,
"no-internal-module": false,
"no-irregular-whitespace": false,
"no-mergeable-namespace": false,
"no-misused-new": false,
"no-namespace": false,
"no-object-literal-type-assertion": false,
"no-padding": false,
"no-redundant-jsdoc": false,
"no-redundant-jsdoc-2": false,
"no-redundant-undefined": false,
"no-reference-import": false,
"no-relative-import-in-test": false,
"no-self-import": false,
"no-single-declare-module": false,
"no-string-throw": false,
"no-unnecessary-callback-wrapper": false,
"no-unnecessary-class": false,
"no-unnecessary-generics": false,
"no-unnecessary-qualifier": false,
"no-unnecessary-type-assertion": false,
"no-useless-files": false,
"no-var-keyword": false,
"no-var-requires": false,
"no-void-expression": false,
"no-trailing-whitespace": false,
"object-literal-key-quotes": false,
"object-literal-shorthand": false,
"one-line": false,
"one-variable-per-declaration": false,
"only-arrow-functions": false,
"prefer-conditional-expression": false,
"prefer-const": false,
"prefer-declare-function": false,
"prefer-for-of": false,
"prefer-method-signature": false,
"prefer-template": false,
"radix": false,
"semicolon": false,
"space-before-function-paren": false,
"space-within-parens": false,
"strict-export-declare-modifiers": false,
"trim-file": false,
"triple-equals": false,
"typedef-whitespace": false,
"unified-signatures": false,
"void-return": false,
"whitespace": false
}
"extends": "dtslint/dt.json"
}