From 6b3caa46ac73a62f39f64f4df00df393eaaa48a2 Mon Sep 17 00:00:00 2001 From: Neil Stalker Date: Sat, 24 Aug 2013 10:54:36 +0100 Subject: [PATCH 1/3] Select2: add method function overloads --- select2/select2-tests.ts | 35 +++++++++++++++++++++- select2/select2.d.ts | 65 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 94 insertions(+), 6 deletions(-) diff --git a/select2/select2-tests.ts b/select2/select2-tests.ts index 9f38782e0..665618daf 100644 --- a/select2/select2-tests.ts +++ b/select2/select2-tests.ts @@ -71,6 +71,27 @@ $("#e6").select2({ formatSelection: movieFormatSelection, dropdownCssClass: "bigdrop" }); +$("#e6").select2({ + placeholder: "Search for a movie", + minimumInputLength: 1, + ajax: { + url: () => { return "http://api.rottentomatoes.com/api/public/v1.0/movies.json"; }, + dataType: 'jsonp', + data: function (term, page) { + return { + q: term, + page_limit: 10, + apikey: "ju6z9mjyajq2djue3gbvv26t" + }; + }, + results: function (data, page) { + return { results: data.movies }; + } + }, + formatResult: movieFormatResult, + formatSelection: movieFormatSelection, + dropdownCssClass: "bigdrop" +}); $("#e7").select2({ placeholder: "Search for a movie", minimumInputLength: 3, @@ -161,4 +182,16 @@ $("#e17_2").select2({ } }); $("#e18,#e18_2").select2(); -alert("Selected value is: " + $("#e8").select2("val")); $("#e8").select2("val", { id: "CA", text: "Califoria" }); \ No newline at end of file +alert("Selected value is: " + $("#e8").select2("val")); $("#e8").select2("val", { id: "CA", text: "Califoria" }); + +$("#e8").select2("val"); +$("#e8").select2("val", "CA"); +$("#e8").select2("data"); +$("#e8").select2("data", { id: "CA", text: "Califoria" }); +$("#e8").select2("destroy"); +$("#e8").select2("open"); +$("#e8").select2("enable", false); +$("#e8").select2("readonly", false); +$("#e8").select2('container'); +$("#e8").select2('onSortStart'); +$("#e8").select2('onSortEnd'); \ No newline at end of file diff --git a/select2/select2.d.ts b/select2/select2.d.ts index e5fb16571..886ae6d34 100644 --- a/select2/select2.d.ts +++ b/select2/select2.d.ts @@ -20,7 +20,10 @@ interface AjaxFunction { interface Select2AjaxOptions { transport?: AjaxFunction; - url?: string; + /** + * Url to make request to, Can be string or a function returning a string. + */ + url?: any; dataType?: string; quietMillis?: number; data?: (term: string, page: number, context: any) => any; @@ -72,8 +75,60 @@ interface JQuery { select2(): JQuery; select2(it: IdTextPair): JQuery; select2(options: Select2Options): JQuery; - select2(method: string, something: string): JQuery; - select2(method: string, something: string[]): JQuery; - select2(method: string, something: IdTextPair[]): JQuery; - select2(method: string, options: IdTextPair): JQuery; + select2(method: string): any; + select2(method: string, value: any, trigger?: boolean): any; + /** + * Get the id value of the current selection + */ + select2(method: 'val'): any; + /** + * Set the id value of the current selection + * @params value Value to set the id to + * @params triggerChange Should a change event be triggered + */ + select2(method: 'val', value: any, triggerChange?: boolean): any; + /** + * Get the data object of the current selection + */ + select2(method: 'data'): any; + /** + * Set the data of the current selection + * @params value Object to set the data to + * @params triggerChange Should a change event be triggered + */ + select2(method: 'data', value: any, triggerChange?: boolean): any; + /** + * Reverts changes to DOM done by Select2. Any selection done via Select2 will be preserved. + */ + select2(method: 'destroy'): void; + /** + * Opens the dropdown + */ + select2(method: 'open'): void; + /** + * Closes the dropdown + */ + select2(method: 'close'): void; + /** + * Enables or disables Select2 and its underlying form component + * @param value True if it should be enabled false if it should be disabled + */ + select2(method: 'enable', value: boolean): void; + /** + * Toggles readonly mode on Select2 and its underlying form component + * @param value True if it should be readonly false if it should be read write + */ + select2(method: 'readonly', value: boolean): void; + /** + * Retrieves the main container element that wraps all of DOM added by Select2 + */ + select2(method: 'container'): HTMLElement; + /** + * Notifies Select2 that a drag and drop sorting operation has started + */ + select2(method: 'onSortStart'): void; + /** + * Notifies Select2 that a drag and drop sorting operation has finished + */ + select2(method: 'onSortEnd'): void; } From f88d9a05ed6184e553f221d8fcf84e7694293732 Mon Sep 17 00:00:00 2001 From: Neil Stalker Date: Sat, 24 Aug 2013 11:08:15 +0100 Subject: [PATCH 2/3] jquery.timepicker: add method function overloads --- jquery.timepicker/jquery.timepicker.d.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/jquery.timepicker/jquery.timepicker.d.ts b/jquery.timepicker/jquery.timepicker.d.ts index b43a7212d..a63e073bb 100644 --- a/jquery.timepicker/jquery.timepicker.d.ts +++ b/jquery.timepicker/jquery.timepicker.d.ts @@ -64,7 +64,11 @@ interface TimePickerOptions { interface JQuery { timepicker(): JQuery; timepicker(options: TimePickerOptions): JQuery; - timepicker(methodName: string): JQuery; + timepicker(methodName: string): any; + timepicker(methodName: 'getTime'): string; + timepicker(methodName: 'getTimeAsDate'): Date; + timepicker(methodName: 'getHour'): number; + timepicker(methodName: 'getMinute'): number; timepicker(methodName: string, methodParameter: any): any; timepicker(optionLiteral: string, optionName: string): any; } From b8fe34a484fe196a64e431818db5e0abfaa0ccdc Mon Sep 17 00:00:00 2001 From: Neil Stalker Date: Sat, 24 Aug 2013 11:29:25 +0100 Subject: [PATCH 3/3] jquery.simplePagination: Add method function overloads and tests --- .../jquery.simplePagination-tests.ts | 52 +++++++++++++++++++ .../jquery.simplePagination.d.ts | 14 ++++- 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 jquery.simplePagination/jquery.simplePagination-tests.ts diff --git a/jquery.simplePagination/jquery.simplePagination-tests.ts b/jquery.simplePagination/jquery.simplePagination-tests.ts new file mode 100644 index 000000000..f804f8760 --- /dev/null +++ b/jquery.simplePagination/jquery.simplePagination-tests.ts @@ -0,0 +1,52 @@ +/// +/// + +var selector = '#elementId'; + +$(function () { + $(selector).pagination({ + items: 100, + itemsOnPage: 10, + cssStyle: 'light-theme' + }); +}); + +$(function () { + $(selector).pagination('selectPage', 1); +}); + +$(function () { + $(selector).pagination('prevPage'); +}); + +$(function () { + $(selector).pagination('nextPage'); +}); + +$(function () { + $(selector).pagination('getPagesCount'); +}); + +$(function () { + $(selector).pagination('getCurrentPage'); +}); + +$(function () { + $(selector).pagination('disable'); +}); + +$(function () { + $(selector).pagination('enable'); +}); + +$(function () { + $(selector).pagination('destroy'); +}); + +$(function () { + $(selector).pagination('redraw'); +}); + +$(function () { + $(selector).pagination('updateItems', 100); +}); \ No newline at end of file diff --git a/jquery.simplePagination/jquery.simplePagination.d.ts b/jquery.simplePagination/jquery.simplePagination.d.ts index 3c3cdaa09..d3c52b8c7 100644 --- a/jquery.simplePagination/jquery.simplePagination.d.ts +++ b/jquery.simplePagination/jquery.simplePagination.d.ts @@ -18,10 +18,22 @@ interface SimplePaginationOptions { nextText?: string; cssStyle?: string; selectOnClick?: boolean; - onPageClick?: (interger) => void; + onPageClick?: (page?: number, event?: any) => void; onInit?: () => void; } interface JQuery { pagination(options?: SimplePaginationOptions): JQuery; + pagination(method: string): any; + pagination(method: string, value: any): any; + pagination(method: 'selectPage', pageNumber: number): void; + pagination(method: 'prevPage'): void; + pagination(method: 'nextPage'): void; + pagination(method: 'getPagesCount'): number; + pagination(method: 'getCurrentPage'): number; + pagination(method: 'disable'): void; + pagination(method: 'enable'): void; + pagination(method: 'destroy'): void; + pagination(method: 'redraw'): void; + pagination(method: 'updateItems', items: number): void; }