mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-08-30 11:14:27 +08:00
jQuery: JSDoc'd unbind
and added test suite
This commit is contained in:
@@ -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.');
|
||||
|
||||
Vendored
+23
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user