public
Description: Prototype JavaScript framework
Homepage: http://prototypejs.org/
Clone URL: git://github.com/sstephenson/prototype.git
Enhance Selector#match to support a "group" (comma-separated) selector. [#318 
state:resolved]
Fri Nov 28 20:31:01 -0800 2008
commit  afd74ce1c72a17666d8c9d86131463ad73cafe9e
tree    e4c08b9e9b2dcb8dffd675b8f3c50c24f9212010
parent  50c7ec58fdd25ced89c29d79697cb3df3b22d2d3
...
 
 
1
2
3
...
1
2
3
4
5
0
@@ -1,3 +1,5 @@
0
+* Enhance Selector#match to support a "group" (comma-separated) selector. (wiktor, Andrew Dupont)
0
+
0
 * Fix issue where certain versions of Safari treat class names case-insensitively in Selector/$$ queries. (Andrew Dupont, kangax, Brice)
0
 
0
 * Fix issue where Function#argumentNames returned incorrect results in IE when comments were intermixed with argument names. (Christophe Porteneuve, T.J. Crowder)
...
135
136
137
 
 
 
 
 
 
 
 
 
 
 
138
139
140
...
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
0
@@ -135,6 +135,17 @@ var Selector = Class.create({
0
   },
0
   
0
   match: function(element) {
0
+    if (this.expression.include(',')) {
0
+      // If the expression includes a comma, it might be a union of several
0
+      // selectors. Split and check each one.
0
+      var expressions = Selector.split(this.expression);
0
+      if (expressions.length > 1) {
0
+        return expressions.any( function(expression) {
0
+          return new Selector(expression).match(element);
0
+        });
0
+      }
0
+    }
0
+    
0
     this.tokens = [];
0
 
0
     var e = this.expression, ps = Selector.patterns, as = Selector.assertions;
...
155
156
157
 
 
 
 
 
158
159
160
...
155
156
157
158
159
160
161
162
163
164
165
0
@@ -155,6 +155,11 @@ new Test.Unit.Runner({
0
     
0
     this.assert(span.match({ match: function(element) { return true }}), 'custom selector');
0
     this.assert(!span.match({ match: function(element) { return false }}), 'custom selector');
0
+    
0
+    this.assert(span.match("div, span"), "comma-joined selector");
0
+    this.assert(span.match("span, div"), "comma-joined selector");
0
+    this.assert(!span.match("span span, div"), "comma-joined selector with one complex selector");
0
+    this.assert(span.match("span span, span"), "comma-joined selector with one complex selector");
0
   },
0
 
0
   testSelectorWithSpaceInAttributeValue: function() {

Comments