From 5a6029c9fe3618a6cc6b43356598ee4bfc4c2f2a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=B6rn=20Zaefferer?=
Date: Mon, 1 Jan 2007 15:22:10 +0000
Subject: [PATCH] Added test and documentation for filter(Function)
---
src/jquery/coreTest.js | 1 +
src/jquery/jquery.js | 25 +++++++++++++++++++++++--
2 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/src/jquery/coreTest.js b/src/jquery/coreTest.js
index 287d7098..2692715f 100644
--- a/src/jquery/coreTest.js
+++ b/src/jquery/coreTest.js
@@ -261,6 +261,7 @@ test("clone()", function() {
test("filter()", function() {
isSet( $("input").filter(":checked").get(), q("radio2", "check1"), "filter(String)" );
isSet( $("p").filter(["#ap", "#sndp"]).get(), q("ap", "sndp"), "filter(Array<String>)" );
+ isSet( $("p").filter(function(el) { return !$("a", el).length }).get(), q("sndp", "first"), "filter(Function)" );
});
test("not(String)", function() {
diff --git a/src/jquery/jquery.js b/src/jquery/jquery.js
index 8b28fdbc..14d2e0a3 100644
--- a/src/jquery/jquery.js
+++ b/src/jquery/jquery.js
@@ -852,13 +852,34 @@ jQuery.fn = jQuery.prototype = {
*
* @example $("p").filter(".selected")
* @before Hello
How are you?
- * @result $("p").filter(".selected") == [ Hello
]
+ * @result [ Hello
]
*
* @name filter
* @type jQuery
* @param String expr An expression to search with.
* @cat DOM/Traversing
*/
+
+ /**
+ * Removes all elements from the set of matched elements that do not
+ * pass the specified filter. This method is used to narrow down
+ * the results of a search.
+ *
+ * The elements to filter are passed as the first argument, their
+ * index inside the set as the second.
+ *
+ * @example $("p").filter(function(element, index) {
+ * return $("ol", element).length == 0;
+ * })
+ * @before - Hello
How are you?
+ * @result [ How are you?
]
+ * @desc Remove all elements that have a child ol element
+ *
+ * @name filter
+ * @type jQuery
+ * @param Function filter A function to use for filtering
+ * @cat DOM/Traversing
+ */
/**
* Removes all elements from the set of matched elements that do not
@@ -871,7 +892,7 @@ jQuery.fn = jQuery.prototype = {
*
* @example $("p").filter([".selected", ":first"])
* @before Hello
Hello Again
And Again
- * @result $("p").filter([".selected", ":first"]) == [ Hello
, And Again
]
+ * @result [ Hello
, And Again
]
*
* @name filter
* @type jQuery