jQuery: JSDoc'd coordinates and added test suite

Added interface to cover coordinates definition.
This commit is contained in:
johnnyreilly
2014-01-01 16:05:06 +00:00
parent 6baada500f
commit 925a1282a8
2 changed files with 39 additions and 3 deletions

View File

@@ -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 () {

27
jquery/jquery.d.ts vendored
View File

@@ -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;