mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
jQuery: JSDoc'd undelegate
added delegate / undelegate test suites
This commit is contained in:
+43
-3
@@ -1183,7 +1183,6 @@ function test_delay() {
|
||||
});
|
||||
}
|
||||
|
||||
/* Not existing, but not recommended either
|
||||
function test_delegate() {
|
||||
$("table").delegate("td", "click", function () {
|
||||
$(this).toggleClass("chosen");
|
||||
@@ -1201,7 +1200,7 @@ function test_delegate() {
|
||||
$("body").delegate("a", "click", function (event) {
|
||||
event.preventDefault();
|
||||
});
|
||||
$("body").delegate("p", "myCustomEvent", function (e, myName, myValue) {
|
||||
$("body").delegate("p", "myCustomEvent", function (e, myName?, myValue?) {
|
||||
$(this).text("Hi there!");
|
||||
$("span").stop().css("opacity", 1)
|
||||
.text("myName = " + myName)
|
||||
@@ -1211,7 +1210,48 @@ function test_delegate() {
|
||||
$("p").trigger("myCustomEvent");
|
||||
});
|
||||
}
|
||||
*/
|
||||
|
||||
function test_undelegate() {
|
||||
function aClick() {
|
||||
$("div").show().fadeOut("slow");
|
||||
}
|
||||
$("#bind").click(function () {
|
||||
$("body")
|
||||
.delegate("#theone", "click", aClick)
|
||||
.find("#theone").text("Can Click!");
|
||||
});
|
||||
$("#unbind").click(function () {
|
||||
$("body")
|
||||
.undelegate("#theone", "click", aClick)
|
||||
.find("#theone").text("Does nothing...");
|
||||
});
|
||||
|
||||
$("p").undelegate();
|
||||
|
||||
$("p").undelegate("click");
|
||||
|
||||
var foo = function () {
|
||||
// Code to handle some kind of event
|
||||
};
|
||||
|
||||
// ... Now foo will be called when paragraphs are clicked ...
|
||||
$("body").delegate("p", "click", foo);
|
||||
|
||||
// ... foo will no longer be called.
|
||||
$("body").undelegate("p", "click", foo);
|
||||
|
||||
var foo = function () {
|
||||
// Code to handle some kind of event
|
||||
};
|
||||
|
||||
// Delegate events under the ".whatever" namespace
|
||||
$("form").delegate(":button", "click.whatever", foo);
|
||||
|
||||
$("form").delegate("input[type='text'] ", "keypress.whatever", foo);
|
||||
|
||||
// Unbind all events delegated under the ".whatever" namespace
|
||||
$("form").undelegate(".whatever");
|
||||
}
|
||||
|
||||
function test_dequeue() {
|
||||
$("button").click(function () {
|
||||
|
||||
Vendored
+23
-2
@@ -2634,9 +2634,30 @@ interface JQuery {
|
||||
*/
|
||||
unbind(evt: any): JQuery;
|
||||
|
||||
/**
|
||||
* Remove a handler from the event for all elements which match the current selector, based upon a specific set of root elements.
|
||||
*/
|
||||
undelegate(): JQuery;
|
||||
undelegate(selector: any, eventType: string, handler?: (eventObject: JQueryEventObject) => any): JQuery;
|
||||
undelegate(selector: any, events: any): JQuery;
|
||||
/**
|
||||
* Remove a handler from the event for all elements which match the current selector, based upon a specific set of root elements.
|
||||
*
|
||||
* @param selector A selector which will be used to filter the event results.
|
||||
* @param eventType A string containing a JavaScript event type, such as "click" or "keydown"
|
||||
* @param handler A function to execute at the time the event is triggered.
|
||||
*/
|
||||
undelegate(selector: string, eventType: string, handler?: (eventObject: JQueryEventObject) => any): JQuery;
|
||||
/**
|
||||
* Remove a handler from the event for all elements which match the current selector, based upon a specific set of root elements.
|
||||
*
|
||||
* @param selector A selector which will be used to filter the event results.
|
||||
* @param events An object of one or more event types and previously bound functions to unbind from them.
|
||||
*/
|
||||
undelegate(selector: string, events: Object): JQuery;
|
||||
/**
|
||||
* Remove a handler from the event for all elements which match the current selector, based upon a specific set of root elements.
|
||||
*
|
||||
* @param namespace A string containing a namespace to unbind all events from.
|
||||
*/
|
||||
undelegate(namespace: string): JQuery;
|
||||
|
||||
unload(handler: (eventObject: JQueryEventObject) => any): JQuery;
|
||||
|
||||
Reference in New Issue
Block a user