Merge pull request #7480 from code-chris/master

Added extended-listbox.d.ts
This commit is contained in:
Masahiro Wakame
2016-01-11 16:33:15 +09:00
2 changed files with 162 additions and 0 deletions
@@ -0,0 +1,77 @@
/// <reference path="extended-listbox.d.ts" />
var $test = $("#test");
// Create Listbox with defaults
var rootElement: any = $test.listbox();
// Create with options
var options = <ListBoxOptions>{};
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 = <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");
+85
View File
@@ -0,0 +1,85 @@
// Type definitions for extended-listbox 1.0.6
// Project: https://github.com/code-chris/extended-listbox
// Definitions by: Christian Kotzbauer <https://github.com/code-chris>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../jquery/jquery.d.ts" />
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;
}