From 4d7fdffa2e3c7be893aa14c8138e4d545c14fad9 Mon Sep 17 00:00:00 2001 From: johnnyreilly Date: Wed, 1 Jan 2014 15:30:44 +0000 Subject: [PATCH 1/4] jQuery: JSDoc'd height --- jquery/jquery.d.ts | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/jquery/jquery.d.ts b/jquery/jquery.d.ts index 5b9983339..4a5721660 100644 --- a/jquery/jquery.d.ts +++ b/jquery/jquery.d.ts @@ -972,10 +972,46 @@ interface JQuery { */ css(properties: Object): JQuery; + /** + * Get the current computed height for the first element in the set of matched elements. + */ height(): number; + /** + * Set the CSS height of every matched element. + * + * @param value An integer representing the number of pixels, or an integer with an optional unit of measure appended (as a string). + */ height(value: number): JQuery; + /** + * Set the CSS height of every matched element. + * + * @param value An integer representing the number of pixels, or an integer with an optional unit of measure appended (as a string). + */ height(value: string): JQuery; - height(func: (index: any, height: any) => any): JQuery; + /** + * Set the CSS height of every matched element. + * + * @param func A function returning the height to set. Receives the index position of the element in the set and the old height as arguments. Within the function, this refers to the current element in the set. + */ + height(func: (index: number, height: number) => number): JQuery; + /** + * Set the CSS height of every matched element. + * + * @param func A function returning the height to set. Receives the index position of the element in the set and the old height as arguments. Within the function, this refers to the current element in the set. + */ + height(func: (index: number, height: string) => string): JQuery; + /** + * Set the CSS height of every matched element. + * + * @param func A function returning the height to set. Receives the index position of the element in the set and the old height as arguments. Within the function, this refers to the current element in the set. + */ + height(func: (index: number, height: string) => number): JQuery; + /** + * Set the CSS height of every matched element. + * + * @param func A function returning the height to set. Receives the index position of the element in the set and the old height as arguments. Within the function, this refers to the current element in the set. + */ + height(func: (index: number, height: number) => string): JQuery; innerHeight(): number; innerHeight(value: number): JQuery; From f6e89c970df41cf3fd1f7c8e889cd67641439950 Mon Sep 17 00:00:00 2001 From: johnnyreilly Date: Wed, 1 Jan 2014 15:39:08 +0000 Subject: [PATCH 2/4] jQuery: JSDoc'd innerWidth / innerWidth removed invalid overloads --- jquery/jquery-tests.ts | 2 -- jquery/jquery.d.ts | 8 ++++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/jquery/jquery-tests.ts b/jquery/jquery-tests.ts index 7cbcc3bd0..c96468327 100644 --- a/jquery/jquery-tests.ts +++ b/jquery/jquery-tests.ts @@ -1751,13 +1751,11 @@ function test_index() { function test_innerHeight() { var p = $("p:first"); $("p:last").text("innerHeight:" + p.innerHeight()); - p.innerHeight(p.innerHeight() * 2).innerHeight(); } function test_innerWidth() { var p = $("p:first"); $("p:last").text("innerWidth:" + p.innerWidth()); - p.innerWidth(p.innerWidth() * 2).innerWidth(); } function test_outerHeight() { diff --git a/jquery/jquery.d.ts b/jquery/jquery.d.ts index 4a5721660..5f42dd1af 100644 --- a/jquery/jquery.d.ts +++ b/jquery/jquery.d.ts @@ -1013,11 +1013,15 @@ interface JQuery { */ height(func: (index: number, height: number) => string): JQuery; + /** + * Get the current computed height for the first element in the set of matched elements, including padding but not border. + */ innerHeight(): number; - innerHeight(value: number): JQuery; + /** + * Get the current computed width for the first element in the set of matched elements, including padding but not border. + */ innerWidth(): number; - innerWidth(value: number): JQuery; offset(): { left: number; top: number; }; offset(coordinates: any): JQuery; From 6baada500ff7f42611c5a1ef86d42eb3ea04fcc7 Mon Sep 17 00:00:00 2001 From: johnnyreilly Date: Wed, 1 Jan 2014 15:48:56 +0000 Subject: [PATCH 3/4] jQuery: JSDoc'd width + added width test suite --- jquery/jquery-tests.ts | 27 +++++++++++++++++++++++++++ jquery/jquery.d.ts | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/jquery/jquery-tests.ts b/jquery/jquery-tests.ts index c96468327..5105dc54a 100644 --- a/jquery/jquery-tests.ts +++ b/jquery/jquery-tests.ts @@ -1642,6 +1642,33 @@ function test_height() { }); } +function test_width() { + // Returns width of browser viewport + $(window).width(); + + // Returns width of HTML document + $(document).width(); + + function showWidth(ele, w) { + $("div").text("The width for the " + ele + " is " + w + "px."); + } + $("#getp").click(function () { + showWidth("paragraph", $("p").width()); + }); + $("#getd").click(function () { + showWidth("document", $(document).width()); + }); + $("#getw").click(function () { + showWidth("window", $(window).width()); + }); + + var modWidth = 50; + $("div").one("click", function () { + $(this).width(modWidth).addClass("mod"); + modWidth -= 8; + }); +} + function test_hide() { $('.target').hide(); $('#clickme').click(function () { diff --git a/jquery/jquery.d.ts b/jquery/jquery.d.ts index 5f42dd1af..88dcde5f0 100644 --- a/jquery/jquery.d.ts +++ b/jquery/jquery.d.ts @@ -1041,10 +1041,46 @@ interface JQuery { scrollTop(): number; scrollTop(value: number): JQuery; + /** + * Get the current computed width for the first element in the set of matched elements. + */ width(): number; + /** + * Set the CSS width of each element in the set of matched elements. + * + * @param value An integer representing the number of pixels, or an integer along with an optional unit of measure appended (as a string). + */ width(value: number): JQuery; + /** + * Set the CSS width of each element in the set of matched elements. + * + * @param value An integer representing the number of pixels, or an integer along with an optional unit of measure appended (as a string). + */ width(value: string): JQuery; - width(func: (index: any, height: any) => any): JQuery; + /** + * Set the CSS width of each element in the set of matched elements. + * + * @param func A function returning the width to set. Receives the index position of the element in the set and the old width as arguments. Within the function, this refers to the current element in the set. + */ + width(func: (index: number, width: number) => number): JQuery; + /** + * Set the CSS width of each element in the set of matched elements. + * + * @param func A function returning the width to set. Receives the index position of the element in the set and the old width as arguments. Within the function, this refers to the current element in the set. + */ + width(func: (index: number, width: string) => string): JQuery; + /** + * Set the CSS width of each element in the set of matched elements. + * + * @param func A function returning the width to set. Receives the index position of the element in the set and the old width as arguments. Within the function, this refers to the current element in the set. + */ + width(func: (index: number, width: string) => number): JQuery; + /** + * Set the CSS width of each element in the set of matched elements. + * + * @param func A function returning the width to set. Receives the index position of the element in the set and the old width as arguments. Within the function, this refers to the current element in the set. + */ + width(func: (index: number, width: number) => string): JQuery; // Data clearQueue(queueName?: string): JQuery; From 925a1282a8db6dc2c202fac8d207e71094dca02b Mon Sep 17 00:00:00 2001 From: johnnyreilly Date: Wed, 1 Jan 2014 16:05:06 +0000 Subject: [PATCH 4/4] jQuery: JSDoc'd coordinates and added test suite Added interface to cover coordinates definition. --- jquery/jquery-tests.ts | 15 +++++++++++++++ jquery/jquery.d.ts | 27 ++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/jquery/jquery-tests.ts b/jquery/jquery-tests.ts index 5105dc54a..e8b11f182 100644 --- a/jquery/jquery-tests.ts +++ b/jquery/jquery-tests.ts @@ -1669,6 +1669,21 @@ function test_width() { }); } +function test_coordinates() { + var p = $("p:last"); + var offset = p.offset(); + p.html("left: " + offset.left + ", top: " + offset.top); + + $("*", document.body).click(function (event) { + var offset = $(this).offset(); + event.stopPropagation(); + $("#result").text(this.tagName + + " coords ( " + offset.left + ", " + offset.top + " )"); + }); + + $("p:last").offset({ top: 10, left: 30 }); +} + function test_hide() { $('.target').hide(); $('#clickme').click(function () { diff --git a/jquery/jquery.d.ts b/jquery/jquery.d.ts index 88dcde5f0..e0018f654 100644 --- a/jquery/jquery.d.ts +++ b/jquery/jquery.d.ts @@ -348,6 +348,14 @@ interface JQueryEventConstructor { new (name: string, eventProperties?: any): JQueryEventObject; } +/** + * The interface used to specify coordinates. + */ +interface JQueryCoordinates { + left: number; + top: number; +} + /** * The interface used to specify easing functions. */ @@ -1023,9 +1031,22 @@ interface JQuery { */ innerWidth(): number; - offset(): { left: number; top: number; }; - offset(coordinates: any): JQuery; - offset(func: (index: any, coords: any) => any): JQuery; + /** + * Get the current coordinates of the first element in the set of matched elements, relative to the document. + */ + offset(): JQueryCoordinates; + /** + * An object containing the properties top and left, which are integers indicating the new top and left coordinates for the elements. + * + * @param coordinates An object containing the properties top and left, which are integers indicating the new top and left coordinates for the elements. + */ + offset(coordinates: JQueryCoordinates): JQuery; + /** + * An object containing the properties top and left, which are integers indicating the new top and left coordinates for the elements. + * + * @param func A function to return the coordinates to set. Receives the index of the element in the collection as the first argument and the current coordinates as the second argument. The function should return an object with the new top and left properties. + */ + offset(func: (index: number, coords: JQueryCoordinates) => JQueryCoordinates): JQuery; outerHeight(includeMargin?: boolean): number; outerHeight(value: number, includeMargin?: boolean): JQuery;