From d0e48fb748255caa4b1065ee8d55b8b54c263172 Mon Sep 17 00:00:00 2001 From: TotPeRo Date: Wed, 23 Aug 2017 19:42:25 +0300 Subject: [PATCH] added jquery.filterTable --- types/jquery.filtertable/index.d.ts | 144 ++++++++++++++++++ .../jquery.filtertable-tests.ts | 16 ++ types/jquery.filtertable/tsconfig.json | 23 +++ 3 files changed, 183 insertions(+) create mode 100644 types/jquery.filtertable/index.d.ts create mode 100644 types/jquery.filtertable/jquery.filtertable-tests.ts create mode 100644 types/jquery.filtertable/tsconfig.json diff --git a/types/jquery.filtertable/index.d.ts b/types/jquery.filtertable/index.d.ts new file mode 100644 index 0000000000..138c2dfc43 --- /dev/null +++ b/types/jquery.filtertable/index.d.ts @@ -0,0 +1,144 @@ +/// +// Type definitions for jquery.filterTable v1.5.7 +// Project: https://github.com/sunnywalker/jQuery.FilterTable +// Definitions by: TotPeRo +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare namespace FilterTable { + + interface FilterTableOptions { + /** + * Makes the filter input field autofocused (not recommended for accessibility reasons) + * Default: 'false' + */ + autofocus?: boolean; + /** + * Callback function after a filter is performed. + * Default: 'null' + * @param term filter term (string) + * @param table table being filtered (jQuery object) + * @returns {void} + */ + callback?: (term, table) => void; + /** + * Class applied to the main filter input container + * Default: 'filter-table' + */ + containerClass?: string; + /** + * Tag name of the main filter input container + * Default: 'p' + */ + containerTag?: string; + /** + * Controls whether the table's tfoot(s) will be hidden when the table is filtered + * Default: 'false' + */ + hideTFootOnFilter?: boolean; + /** + * Class applied to cells containing the filter term + * Default: 'alt' + */ + highlightClass?: string; + /** + * Ignore these columns (0-indexed) when filtering + * Default: '[]' + */ + ignoreColumns?: number[]; + /** + * Use this selector to find the filter input instead of creating a new one (only works if selector returns a single element) + * Default: 'null' + */ + inputSelector?: string; + /** + * Name attribute of the filter input field + * Default: 'filter-table' + */ + inputName?: string; + /** + * Tag name of the filter input itself + * Default: 'search' + */ + inputType?: string; + /** + * Text to precede the filter input + * Default: 'Filter:' + */ + label?: string; + /** + * Filter only when at least this number of characters are in the filter input field + * Default: '1' + */ + minChars?: number; + /** + * Only show the filter on tables with this number of rows or more + * Default: '8' + */ + minRows?: number; + /** + * HTML5 placeholder text for the filter input + * Default: 'search this table' + */ + placeholder?: string; + /** + * Trap the return key in the filter input field to prevent form submission + * Default: 'true' + */ + preventReturnKey?: boolean; + /** + * List of clickable phrases to quick fill the search + * Default: '[]' + */ + quickList?: string[]; + /** + * Class of each quick list item + * Default: 'quick' + */ + quickListClass?: string; + /** + * Label for the clear filtering quick list item (or none if blank) + * Default: '' + */ + quickListClear?: string; + /** + * Tag name surrounding quick list items (e.g., ul) + * Default: '' + */ + quickListGroupTag?: string; + /** + * Tag name of each quick list item (e.g., a or li) + * Default: 'a' + */ + quickListTag?: string; // "a" | "li" + /** + * Class applied to visible rows + * Default: 'visible' + */ + visibleClass?: string; + } + + interface FilterTableStatic { + + /** + * init with default options + * @returns {JQuery} + */ + (): JQuery; + + /** + * init with custom options + * @param options + * @returns {JQuery} + */ + (options: FilterTableOptions): JQuery; + } +} + +interface JQuery { + + /** + * if this code appears after your tables; otherwise, include it in your document.ready() code. + * $('table').filterTable() + */ + filterTable: FilterTable.FilterTableStatic; +} diff --git a/types/jquery.filtertable/jquery.filtertable-tests.ts b/types/jquery.filtertable/jquery.filtertable-tests.ts new file mode 100644 index 0000000000..adfbe853fe --- /dev/null +++ b/types/jquery.filtertable/jquery.filtertable-tests.ts @@ -0,0 +1,16 @@ +//import $ = require('jquery'); + +$(() => { + // examples from http://sunnywalker.github.io/jQuery.FilterTable/ + + $('table').filterTable(); + + $('table').filterTable({ quickList: ['class', 'tag'] }); + + $('table').filterTable({ + callback(term, table) { + table.find('tr').removeClass('striped').filter(':visible:even').addClass('striped'); + } + }); + +}); \ No newline at end of file diff --git a/types/jquery.filtertable/tsconfig.json b/types/jquery.filtertable/tsconfig.json new file mode 100644 index 0000000000..2560a6e1cc --- /dev/null +++ b/types/jquery.filtertable/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "jquery.filtertable-tests.ts" + ] +} \ No newline at end of file