Skip to content

Commit 6baada5

Browse files
committed
jQuery: JSDoc'd width + added width test suite
1 parent f6e89c9 commit 6baada5

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

jquery/jquery-tests.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,6 +1642,33 @@ function test_height() {
16421642
});
16431643
}
16441644

1645+
function test_width() {
1646+
// Returns width of browser viewport
1647+
$(window).width();
1648+
1649+
// Returns width of HTML document
1650+
$(document).width();
1651+
1652+
function showWidth(ele, w) {
1653+
$("div").text("The width for the " + ele + " is " + w + "px.");
1654+
}
1655+
$("#getp").click(function () {
1656+
showWidth("paragraph", $("p").width());
1657+
});
1658+
$("#getd").click(function () {
1659+
showWidth("document", $(document).width());
1660+
});
1661+
$("#getw").click(function () {
1662+
showWidth("window", $(window).width());
1663+
});
1664+
1665+
var modWidth = 50;
1666+
$("div").one("click", function () {
1667+
$(this).width(modWidth).addClass("mod");
1668+
modWidth -= 8;
1669+
});
1670+
}
1671+
16451672
function test_hide() {
16461673
$('.target').hide();
16471674
$('#clickme').click(function () {

jquery/jquery.d.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1041,10 +1041,46 @@ interface JQuery {
10411041
scrollTop(): number;
10421042
scrollTop(value: number): JQuery;
10431043

1044+
/**
1045+
* Get the current computed width for the first element in the set of matched elements.
1046+
*/
10441047
width(): number;
1048+
/**
1049+
* Set the CSS width of each element in the set of matched elements.
1050+
*
1051+
* @param value An integer representing the number of pixels, or an integer along with an optional unit of measure appended (as a string).
1052+
*/
10451053
width(value: number): JQuery;
1054+
/**
1055+
* Set the CSS width of each element in the set of matched elements.
1056+
*
1057+
* @param value An integer representing the number of pixels, or an integer along with an optional unit of measure appended (as a string).
1058+
*/
10461059
width(value: string): JQuery;
1047-
width(func: (index: any, height: any) => any): JQuery;
1060+
/**
1061+
* Set the CSS width of each element in the set of matched elements.
1062+
*
1063+
* @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.
1064+
*/
1065+
width(func: (index: number, width: number) => number): JQuery;
1066+
/**
1067+
* Set the CSS width of each element in the set of matched elements.
1068+
*
1069+
* @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.
1070+
*/
1071+
width(func: (index: number, width: string) => string): JQuery;
1072+
/**
1073+
* Set the CSS width of each element in the set of matched elements.
1074+
*
1075+
* @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.
1076+
*/
1077+
width(func: (index: number, width: string) => number): JQuery;
1078+
/**
1079+
* Set the CSS width of each element in the set of matched elements.
1080+
*
1081+
* @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.
1082+
*/
1083+
width(func: (index: number, width: number) => string): JQuery;
10481084

10491085
// Data
10501086
clearQueue(queueName?: string): JQuery;

0 commit comments

Comments
 (0)