From 5ab2c1040985d6b83738e17cf3419b46019ada2a Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 4 Jan 2016 18:56:35 +0100 Subject: [PATCH] Added extended-listbox.d.ts --- extended-listbox/extended-listbox-tests.ts | 77 ++++++++++++++++++++ extended-listbox/extended-listbox.d.ts | 85 ++++++++++++++++++++++ 2 files changed, 162 insertions(+) create mode 100644 extended-listbox/extended-listbox-tests.ts create mode 100644 extended-listbox/extended-listbox.d.ts diff --git a/extended-listbox/extended-listbox-tests.ts b/extended-listbox/extended-listbox-tests.ts new file mode 100644 index 000000000..cc4eba3fe --- /dev/null +++ b/extended-listbox/extended-listbox-tests.ts @@ -0,0 +1,77 @@ +/// + + +var $test = $("#test"); + +// Create Listbox with defaults +var rootElement: any = $test.listbox(); + + +// Create with options +var options = {}; +options.multiple = true; +options.onItemsChanged = (items: ListboxItem[]): void => { + console.log(items); +}; +options.getItems = function (): any[] { + return ["Test1"]; +}; +options.searchBar = false; +options.searchBarWatermark = "Search"; +options.onFilterChanged = (filter): void => { + console.log(filter); +}; +options.onValueChanged = function (value: any): void { + console.log(value); +}; +options.searchBarButton = { icon: "fa fa-search", visible: true, onClick: function () { alert(); } }; + +rootElement = $test.listbox(options); + + +// Add string item +rootElement.listbox("addItem", "Test2"); + + +// Add item +var item: ListboxItem = {}; +item.selected = true; +item.disabled = false; +item.childItems = ["Test4"]; +item.groupHeader = false; +item.id = "ouetioreit"; +item.index = 0; +item.text = "Test3"; +var id: string = rootElement.listbox("addItem", item); + + +// Remove item +rootElement.listbox("removeItem", id); + + +// Get item +var i: ListboxItem = rootElement.listbox("getItem", id); + + +// Get items +var allItems: ListboxItem[] = rootElement.listbox("getItems"); + + +// Move item up +var newIndex: number = rootElement.listbox("moveItemUp", i.id); + + +// Move item down +newIndex = rootElement.listbox("moveItemDown", i.id); + + +// Clear selection +newIndex = rootElement.listbox("clearSelection"); + + +// Enable +newIndex = rootElement.listbox("enable", false); + + +// Destroy +newIndex = rootElement.listbox("destroy"); diff --git a/extended-listbox/extended-listbox.d.ts b/extended-listbox/extended-listbox.d.ts new file mode 100644 index 000000000..d3f8341f0 --- /dev/null +++ b/extended-listbox/extended-listbox.d.ts @@ -0,0 +1,85 @@ +// Type definitions for extended-listbox 1.0.6 +// Project: https://github.com/code-chris/extended-listbox +// Definitions by: Christian Kotzbauer +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +interface ListboxItem { + /** display text */ + text?: string; + + /** unique identifier, if not set it will be generated */ + id?: string; + + /** index position from the item in the list; only used for manual addItem api calls */ + index?: number; + + /** determines if the item should be clickable */ + disabled?: boolean; + + /** determines if the item is selected */ + selected?: boolean; + + /** determines if the item has childItems */ + groupHeader?: boolean; + + /** display text or id of the parent; only used for manual addItem api calls */ + parentGroupId?: string; + + /** list of childItems */ + childItems?: any[]; +} + +interface ListboxSearchBarButtonOptions { + /** determines if the button is visible */ + visible?: boolean; + + /** css class for the i-tag of the button */ + icon?: string; + + /** callback for button click */ + onClick?: () => void; +} + +interface ListBoxOptions { + /** determines if the searchBar is visible */ + searchBar?: boolean; + + /** watermark (placeholder) for the searchBar */ + searchBarWatermark?: string; + + /** settings for the searchBar button */ + searchBarButton?: ListboxSearchBarButtonOptions; + + /** determines if multiple items can be selected */ + multiple?: boolean; + + /** function which returns a array of items */ + getItems?: () => any; + + /** callback for selection changes */ + onValueChanged?: (value: ListboxItem|ListboxItem[]) => void; + + /** callback for searchBar text changes */ + onFilterChanged?: (value: string) => void; + + /** callback for item changes (item added, item removed, item order) */ + onItemsChanged?: (value: ListboxItem[]) => void; +} + +interface JQuery { + listbox(): JQuery; + listbox(methodName: 'addItem'): string; + listbox(methodName: 'removeItem'): void; + listbox(methodName: 'destroy'): void; + listbox(methodName: 'getItem'): ListboxItem; + listbox(methodName: 'getItems'): ListboxItem[]; + listbox(methodName: 'moveItemUp'): number; + listbox(methodName: 'moveItemDown'): number; + listbox(methodName: 'clearSelection'): void; + listbox(methodName: 'enable'): void; + listbox(methodName: string): any; + listbox(methodName: string, methodParameter: any): any; + listbox(options: ListBoxOptions): JQuery; +}