From 9f7b30fce9e6196733fa3cb993f919b2f7666f0c Mon Sep 17 00:00:00 2001 From: johnnyreilly Date: Sun, 29 Dec 2013 21:27:56 +0000 Subject: [PATCH 1/3] jQuery: JSDoc'd prop --- jquery/jquery.d.ts | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/jquery/jquery.d.ts b/jquery/jquery.d.ts index 984f06616e..522b8d1bc3 100644 --- a/jquery/jquery.d.ts +++ b/jquery/jquery.d.ts @@ -788,10 +788,46 @@ interface JQuery { html(htmlContent: (index: number, oldhtml: string) => string): JQuery; html(obj: JQuery): JQuery; + /** + * Get the value of a property for the first element in the set of matched elements. + * + * @param propertyName The name of the property to get. + */ prop(propertyName: string): any; - prop(propertyName: string, value: any): JQuery; - prop(map: any): JQuery; - prop(propertyName: string, func: (index: any, oldPropertyValue: any) => any): JQuery; + /** + * Set one or more properties for the set of matched elements. + * + * @param propertyName The name of the property to set. + * @param value A value to set for the property. + */ + prop(propertyName: string, value: string): JQuery; + /** + * Set one or more properties for the set of matched elements. + * + * @param propertyName The name of the property to set. + * @param value A value to set for the property. + */ + prop(propertyName: string, value: number): JQuery; + /** + * Set one or more properties for the set of matched elements. + * + * @param propertyName The name of the property to set. + * @param value A value to set for the property. + */ + prop(propertyName: string, value: boolean): JQuery; + /** + * Set one or more properties for the set of matched elements. + * + * @param properties An object of property-value pairs to set. + */ + prop(properties: Object): JQuery; + /** + * Set one or more properties for the set of matched elements. + * + * @param propertyName The name of the property to set. + * @param func A function returning the value to set. Receives the index position of the element in the set and the old property value as arguments. Within the function, the keyword this refers to the current element. + */ + prop(propertyName: string, func: (index: number, oldPropertyValue: any) => any): JQuery; /** * Remove an attribute from each element in the set of matched elements. From 3f51b9c7b2c351137bd51e69eb0a6cdcb9322fdc Mon Sep 17 00:00:00 2001 From: johnnyreilly Date: Sun, 29 Dec 2013 21:29:55 +0000 Subject: [PATCH 2/3] jQuery: removeProp --- jquery/jquery.d.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/jquery/jquery.d.ts b/jquery/jquery.d.ts index 522b8d1bc3..4f16a03f91 100644 --- a/jquery/jquery.d.ts +++ b/jquery/jquery.d.ts @@ -849,6 +849,11 @@ interface JQuery { */ removeClass(func: (index: number, className: string) => string): JQuery; + /** + * Remove a property for the set of matched elements. + * + * @param propertyName The name of the property to remove. + */ removeProp(propertyName: string): JQuery; /** From 609712265ed4473f1428520f14edcf2f12121f21 Mon Sep 17 00:00:00 2001 From: johnnyreilly Date: Sun, 29 Dec 2013 21:42:55 +0000 Subject: [PATCH 3/3] jQuery: brought val into line with documentation Plus added val test suite --- jquery/jquery-tests.ts | 50 ++++++++++++++++++++++++++++++++++++++++++ jquery/jquery.d.ts | 23 ++++++++++++++++--- 2 files changed, 70 insertions(+), 3 deletions(-) diff --git a/jquery/jquery-tests.ts b/jquery/jquery-tests.ts index e56893d3bf..35210e4bb7 100644 --- a/jquery/jquery-tests.ts +++ b/jquery/jquery-tests.ts @@ -2309,6 +2309,56 @@ function test_prop() { var title: string = $('option:selected', this).prop('title'); } +function test_val() { + // Get the value from a dropdown select + $("select.foo option:selected").val(); + + // Get the value from a dropdown select even easier + $("select.foo").val(); + + // Get the value from a checked checkbox + $("input:checkbox:checked").val(); + + // Get the value from a set of radio buttons + $("input:radio[name=bar]:checked").val(); + + function displayVals() { + var singleValues = $("#single").val(); + var multipleValues = $("#multiple").val() || []; + $("p").html("Single: " + singleValues + + " Multiple: " + multipleValues.join(", ")); + } + + $("select").change(displayVals); + displayVals(); + + + $("input") + .keyup(function () { + var value = $(this).val(); + $("p").text(value); + }) + .keyup(); + + $("input:text.items").val(function (index, value) { + return value + " " + this.className; + }); + + $("button").click(function () { + var text = $(this).text(); + $("input").val(text); + }); + + $("input").on("blur", function () { + $(this).val(function (i, val) { + return val.toUpperCase(); + }); + }); + + $("#single").val("Single2"); + $("#multiple").val(["Multiple2", "Multiple3"]); + $("input").val(["check1", "check2", "radio1"]); +} function test_selector() { var $main = $('#main'); diff --git a/jquery/jquery.d.ts b/jquery/jquery.d.ts index 4f16a03f91..379368601e 100644 --- a/jquery/jquery.d.ts +++ b/jquery/jquery.d.ts @@ -877,11 +877,28 @@ interface JQuery { */ toggleClass(func: (index: number, className: string, swtch: boolean) => string, swtch?: boolean): JQuery; + /** + * Get the current value of the first element in the set of matched elements. + */ val(): any; - val(value: string[]): JQuery; + /** + * Set the value of each element in the set of matched elements. + * + * @param value A string of text or an array of strings corresponding to the value of each matched element to set as selected/checked. + */ val(value: string): JQuery; - val(value: number): JQuery; - val(func: (index: any, value: any) => any): JQuery; + /** + * Set the value of each element in the set of matched elements. + * + * @param value A string of text or an array of strings corresponding to the value of each matched element to set as selected/checked. + */ + val(value: string[]): JQuery; + /** + * Set the value of each element in the set of matched elements. + * + * @param func A function returning the value to set. this is the current element. Receives the index position of the element in the set and the old value as arguments. + */ + val(func: (index: number, value: any) => any): JQuery; /** * Get the value of style properties for the first element in the set of matched elements.