jQuery: JSDoc'd unbind

and added test suite
This commit is contained in:
John Reilly
2014-02-24 14:49:28 +00:00
parent f4e9a367db
commit 50bc863d8c
2 changed files with 87 additions and 0 deletions
+64
View File
@@ -590,6 +590,70 @@ function test_bind() {
});
}
function test_unbind() {
$("#foo").unbind();
$("#foo").unbind("click");
var handler = function () {
alert("The quick brown fox jumps over the lazy dog.");
};
$("#foo").bind("click", handler);
$("#foo").unbind("click", handler);
$("#foo").bind("click", function () {
alert("The quick brown fox jumps over the lazy dog.");
});
// Will NOT work
$("#foo").unbind("click", function () {
alert("The quick brown fox jumps over the lazy dog.");
});
$("#foo").bind("click.myEvents", handler);
$("#foo").unbind("click");
$("#foo").unbind("click.myEvents");
$("#foo").unbind(".myEvents");
var timesClicked = 0;
$("#foo").bind("click", function (event) {
alert("The quick brown fox jumps over the lazy dog.");
timesClicked++;
if (timesClicked >= 3) {
$(this).unbind(event);
}
});
function aClick() {
$("div").show().fadeOut("slow");
}
$("#bind").click(function () {
$("#theone")
.bind("click", aClick)
.text("Can Click!");
});
$("#unbind").click(function () {
$("#theone")
.unbind("click", aClick)
.text("Does nothing...");
});
$("p").unbind();
$("p").unbind("click");
var foo = function () {
// Code to handle some kind of event
};
$("p").bind("click", foo); // ... Now foo will be called when paragraphs are clicked ...
$("p").unbind("click", foo); // ... foo will no longer be called.
}
function test_blur() {
$('#target').blur(function () {
alert('Handler for .blur() called.');
+23
View File
@@ -2605,10 +2605,33 @@ interface JQuery {
*/
trigger(event: JQueryEventObject, extraParameters?: Object): JQuery;
/**
* Execute all handlers attached to an element for an event.
*
* @param eventType A string containing a JavaScript event type, such as click or submit.
* @param extraParameters An array of additional parameters to pass along to the event handler.
*/
triggerHandler(eventType: string, ...extraParameters: any[]): Object;
/**
* Remove a previously-attached event handler from the elements.
*
* @param eventType A string containing a JavaScript event type, such as click or submit.
* @param handler The function that is to be no longer executed.
*/
unbind(eventType?: string, handler?: (eventObject: JQueryEventObject) => any): JQuery;
/**
* Remove a previously-attached event handler from the elements.
*
* @param eventType A string containing a JavaScript event type, such as click or submit.
* @param fls Unbinds the corresponding 'return false' function that was bound using .bind( eventType, false ).
*/
unbind(eventType: string, fls: boolean): JQuery;
/**
* Remove a previously-attached event handler from the elements.
*
* @param evt A JavaScript event object as passed to an event handler.
*/
unbind(evt: any): JQuery;
undelegate(): JQuery;