Skip to content

Commit d9a3e00

Browse files
committed
Fix broken selector code from last commit.
1 parent 424500b commit d9a3e00

File tree

3 files changed

+83
-50
lines changed

3 files changed

+83
-50
lines changed

src/sizzle-jquery.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ jQuery.find = Sizzle;
22
jQuery.expr = Sizzle.selectors;
33
jQuery.expr[":"] = jQuery.expr.filters;
44
jQuery.unique = Sizzle.uniqueSort;
5+
jQuery.text = Sizzle.getText;
6+
jQuery.isXMLDoc = Sizzle.isXML;
7+
jQuery.contains = Sizzle.contains;

test/index.html

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,20 @@ <h2 id="qunit-banner"></h2>
4848
<div id="qunit-testrunner-toolbar"></div>
4949
<h2 id="qunit-userAgent"></h2>
5050
<ol id="qunit-tests"></ol>
51-
51+
5252
<!-- Test HTML -->
5353
<div id="nothiddendiv" style="height:1px;background:white;" class="nothiddendiv">
5454
<div id="nothiddendivchild"></div>
5555
</div>
5656
<!-- this iframe is outside the #main so it won't reload constantly wasting time, but it means the tests must be "safe" and clean up after themselves -->
5757
<iframe id="loadediframe" name="loadediframe" style="display:none;" src="data/iframe.html"></iframe>
58-
<dl id="dl" style="display:none;">
59-
<div id="main" style="display: none;">
58+
<dl id="dl" style="position:absolute;top:-32767px;left:-32767px;">
59+
<div id="main">
6060
<p id="firstp">See <a id="simon1" href="http://simon.incutio.com/archive/2003/03/25/#getElementsBySelector" rel="bookmark">this blog entry</a> for more information.</p>
6161
<p id="ap">
62-
Here are some links in a normal paragraph: <a id="google" href="http://www.google.com/" title="Google!">Google</a>,
63-
<a id="groups" href="http://groups.google.com/" class="GROUPS">Google Groups (Link)</a>.
64-
This link has <code><a href="http://smin" id="anchor1">class="blog"</a></code>:
62+
Here are some links in a normal paragraph: <a id="google" href="http://www.google.com/" title="Google!">Google</a>,
63+
<a id="groups" href="http://groups.google.com/" class="GROUPS">Google Groups (Link)</a>.
64+
This link has <code><a href="http://smin" id="anchor1">class="blog"</a></code>:
6565
<a href="http://diveintomark.org/" class="blog" hreflang="en" id="mark">diveintomark</a>
6666

6767
</p>
@@ -87,14 +87,14 @@ <h2 id="qunit-userAgent"></h2>
8787

8888
<input type="hidden" name="hidden" id="hidden1"/>
8989
<input type="text" style="display:none;" name="foo[bar]" id="hidden2"/>
90-
90+
9191
<input type="text" id="name" name="name" value="name" />
9292
<input type="search" id="search" name="search" value="search" />
93-
93+
9494
<button id="button" name="button" type="button">Button</button>
95-
95+
9696
<textarea id="area1" maxlength="30">foobar</textarea>
97-
97+
9898
<select name="select1" id="select1">
9999
<option id="option1a" class="emptyopt" value="">Nothing</option>
100100
<option id="option1b" value="1">1</option>
@@ -114,19 +114,33 @@ <h2 id="qunit-userAgent"></h2>
114114
<option id="option3d" value="3">3</option>
115115
<option id="option3e">no value</option>
116116
</select>
117-
117+
<select name="select4" id="select4" multiple="multiple">
118+
<optgroup disabled="disabled">
119+
<option id="option4a" class="emptyopt" value="">Nothing</option>
120+
<option id="option4b" disabled="disabled" selected="selected" value="1">1</option>
121+
<option id="option4c" selected="selected" value="2">2</option>
122+
</optgroup>
123+
<option selected="selected" disabled="disabled" id="option4d" value="3">3</option>
124+
<option id="option4e">no value</option>
125+
</select>
126+
<select name="select5" id="select5">
127+
<option id="option5a" value="3">1</option>
128+
<option id="option5b" value="2">2</option>
129+
<option id="option5c" value="1">3</option>
130+
</select>
131+
118132
<object id="object1" codebase="stupid">
119133
<param name="p1" value="x1" />
120134
<param name="p2" value="x2" />
121135
</object>
122-
136+
123137
<span id="台北Táiběi"></span>
124138
<span id="台北" lang="中文"></span>
125139
<span id="utf8class1" class="台北Táiběi 台北"></span>
126140
<span id="utf8class2" class="台北"></span>
127141
<span id="foo:bar" class="foo:bar"></span>
128142
<span id="test.foo[5]bar" class="test.foo[5]bar"></span>
129-
143+
130144
<foo_bar id="foobar">test element</foo_bar>
131145
</form>
132146
<b id="floatTest">Float test.</b>
@@ -143,7 +157,7 @@ <h2 id="qunit-userAgent"></h2>
143157
<input name="types[]" id="types_anime" type="checkbox" value="anime" />
144158
<input name="types[]" id="types_movie" type="checkbox" value="movie" />
145159
</form>
146-
160+
147161
<form id="testForm" action="#" method="get">
148162
<textarea name="T3" rows="2" cols="15">?
149163
Z</textarea>
@@ -199,15 +213,15 @@ <h2 id="qunit-userAgent"></h2>
199213
<div><div class="hidden">hidden</div></div>
200214
</div>
201215
</div>
202-
216+
203217
<div id="tabindex-tests">
204218
<ol id="listWithTabIndex" tabindex="5">
205219
<li id="foodWithNegativeTabIndex" tabindex="-1">Rice</li>
206220
<li id="foodNoTabIndex">Beans</li>
207221
<li>Blinis</li>
208222
<li>Tofu</li>
209223
</ol>
210-
224+
211225
<div id="divWithNoTabIndex">I'm hungry. I should...</div>
212226
<span>...</span><a href="#" id="linkWithNoTabIndex">Eat lots of food</a><span>...</span> |
213227
<span>...</span><a href="#" id="linkWithTabIndex" tabindex="2">Eat a little food</a><span>...</span> |
@@ -216,7 +230,7 @@ <h2 id="qunit-userAgent"></h2>
216230
<span>...</span><a id="linkWithNoHrefWithTabIndex" tabindex="1">Eat some funyuns</a><span>...</span>
217231
<span>...</span><a id="linkWithNoHrefWithNegativeTabIndex" tabindex="-1">Eat some funyuns</a><span>...</span>
218232
</div>
219-
233+
220234
<div id="liveHandlerOrder">
221235
<span id="liveSpan1"><a href="#" id="liveLink1"></a></span>
222236
<span id="liveSpan2"><a href="#" id="liveLink2"></a></span>
@@ -232,21 +246,26 @@ <h2 id="qunit-userAgent"></h2>
232246
<div id="fx-queue" name="test">
233247
<div id="fadein" class='chain test' name='div'>fadeIn<div>fadeIn</div></div>
234248
<div id="fadeout" class='chain test out'>fadeOut<div>fadeOut</div></div>
235-
249+
236250
<div id="show" class='chain test'>show<div>show</div></div>
237251
<div id="hide" class='chain test out'>hide<div>hide</div></div>
238-
252+
239253
<div id="togglein" class='chain test'>togglein<div>togglein</div></div>
240254
<div id="toggleout" class='chain test out'>toggleout<div>toggleout</div></div>
241-
242-
255+
256+
243257
<div id="slideup" class='chain test'>slideUp<div>slideUp</div></div>
244258
<div id="slidedown" class='chain test out'>slideDown<div>slideDown</div></div>
245-
259+
246260
<div id="slidetogglein" class='chain test'>slideToggleIn<div>slideToggleIn</div></div>
247261
<div id="slidetoggleout" class='chain test out'>slideToggleOut<div>slideToggleOut</div></div>
262+
263+
<div id="fadetogglein" class='chain test'>fadeToggleIn<div>fadeToggleIn</div></div>
264+
<div id="fadetoggleout" class='chain test out'>fadeToggleOut<div>fadeToggleOut</div></div>
265+
266+
<div id="fadeto" class='chain test'>fadeTo<div>fadeTo</div></div>
248267
</div>
249-
268+
250269
<div id="fx-tests"></div>
251270
</div>
252271
</body>

test/unit/selector.js

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module("selector");
22

33
test("element", function() {
4-
expect(19);
5-
reset();
4+
expect(18);
5+
QUnit.reset();
66

77
ok( jQuery("*").size() >= 30, "Select all" );
88
var all = jQuery("*"), good = true;
@@ -21,14 +21,13 @@ test("element", function() {
2121
same( jQuery("p", jQuery("div")).get(), q("firstp","ap","sndp","en","sap","first"), "Finding elements with a context." );
2222
same( jQuery("div").find("p").get(), q("firstp","ap","sndp","en","sap","first"), "Finding elements with a context." );
2323

24-
same( jQuery("#form").find("select").get(), q("select1","select2","select3"), "Finding selects with a context." );
24+
same( jQuery("#form").find("select").get(), q("select1","select2","select3","select4","select5"), "Finding selects with a context." );
2525

2626
ok( jQuery("#length").length, '&lt;input name="length"&gt; cannot be found under IE, see #945' );
2727
ok( jQuery("#lengthtest input").length, '&lt;input name="length"&gt; cannot be found under IE, see #945' );
2828

2929
// Check for unique-ness and sort order
30-
same( jQuery("*").get(), jQuery("*, *").get(), "Check for duplicates: *, *" );
31-
same( jQuery("p").get(), jQuery("p, div p").get(), "Check for duplicates: p, div p" );
30+
same( jQuery("p, div p").get(), jQuery("p").get(), "Check for duplicates: p, div p" );
3231

3332
t( "Checking sort order", "h2, h1", ["qunit-header", "qunit-banner", "qunit-userAgent"] );
3433
t( "Checking sort order", "h2:first, h1:first", ["qunit-header", "qunit-banner"] );
@@ -37,7 +36,7 @@ test("element", function() {
3736

3837
if ( location.protocol != "file:" ) {
3938
test("XML Document Selectors", function() {
40-
expect(7);
39+
expect(8);
4140
stop();
4241
jQuery.get("data/with_fries.xml", function(xml) {
4342
equals( jQuery("foo_bar", xml).length, 1, "Element Selector with underscore" );
@@ -47,6 +46,7 @@ if ( location.protocol != "file:" ) {
4746
equals( jQuery("[name=prop2]", xml).length, 1, "Attribute selector with name" );
4847
equals( jQuery("#seite1", xml).length, 1, "Attribute selector with ID" );
4948
equals( jQuery("component#seite1", xml).length, 1, "Attribute selector with ID" );
49+
equals( jQuery("component", xml).filter("#seite1").length, 1, "Attribute selector filter with ID" );
5050
start();
5151
});
5252
});
@@ -154,7 +154,7 @@ test("class", function() {
154154
});
155155

156156
test("name", function() {
157-
expect(14);
157+
expect(15);
158158

159159
t( "Name selector", "input[name=action]", ["text1"] );
160160
t( "Name selector with single quotes", "input[name='action']", ["text1"] );
@@ -169,13 +169,19 @@ test("name", function() {
169169
same( jQuery("#form").find("input[name=action]").get(), q("text1"), "Name selector within the context of another element" );
170170
same( jQuery("#form").find("input[name='foo[bar]']").get(), q("hidden2"), "Name selector for grouped form element within the context of another element" );
171171

172+
var form = jQuery("<form><input name='id'/></form>").appendTo("body");
173+
174+
equals( form.find("input").length, 1, "Make sure that rooted queries on forms (with possible expandos) work." );
175+
176+
form.remove();
177+
172178
var a = jQuery('<div><a id="tName1ID" name="tName1">tName1 A</a><a id="tName2ID" name="tName2">tName2 A</a><div id="tName1">tName1 Div</div></div>').appendTo('#main').children();
173179

174180
equals( a.length, 3, "Make sure the right number of elements were inserted." );
175181
equals( a[1].id, "tName2ID", "Make sure the right number of elements were inserted." );
176182

177-
t( "Find elements that have similar IDs", "[name=tName1]", ["tName1ID"] );
178-
t( "Find elements that have similar IDs", "[name=tName2]", ["tName2ID"] );
183+
equals( jQuery("[name=tName1]")[0], a[0], "Find elements that have similar IDs" );
184+
equals( jQuery("[name=tName2]")[0], a[1], "Find elements that have similar IDs" );
179185
t( "Find elements that have similar IDs", "#tName2ID", ["tName2ID"] );
180186

181187
a.remove();
@@ -191,7 +197,7 @@ test("multiple", function() {
191197
});
192198

193199
test("child and adjacent", function() {
194-
expect(29);
200+
expect(27);
195201
t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
196202
t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
197203
t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );
@@ -203,7 +209,6 @@ test("child and adjacent", function() {
203209
t( "Adjacent", "a +a", ["groups"] );
204210
t( "Adjacent", "a+ a", ["groups"] );
205211
t( "Adjacent", "a+a", ["groups"] );
206-
t( "Adjacent", "a:eq(1)+a", ["groups"] );
207212
t( "Adjacent", "p + p", ["ap","en","sap"] );
208213
t( "Adjacent", "p#firstp + p", ["ap"] );
209214
t( "Adjacent", "p[lang=en] + p", ["sap"] );
@@ -214,7 +219,6 @@ test("child and adjacent", function() {
214219
t( "Element Preceded By", "#groups ~ a", ["mark"] );
215220
t( "Element Preceded By", "#length ~ input", ["idTest"] );
216221
t( "Element Preceded By", "#siblingfirst ~ em", ["siblingnext"] );
217-
t( "Element Preceded By", "#siblingfirst:first ~ em", ["siblingnext"] );
218222

219223
t( "Verify deep class selector", "div.blah > p > a", [] );
220224

@@ -228,7 +232,7 @@ test("child and adjacent", function() {
228232
});
229233

230234
test("attributes", function() {
231-
expect(34);
235+
expect(35);
232236
t( "Attribute Exists", "a[title]", ["google"] );
233237
t( "Attribute Exists", "*[title]", ["google"] );
234238
t( "Attribute Exists", "[title]", ["google"] );
@@ -266,6 +270,9 @@ test("attributes", function() {
266270
t( "Attribute Contains", "a[href *= 'google']", ["google","groups"] );
267271
t( "Attribute Is Not Equal", "#ap a[hreflang!='en']", ["google","groups","anchor1"] );
268272

273+
var opt = document.getElementById("option1a");
274+
ok( (window.Sizzle || window.jQuery.find).matchesSelector( opt, "[id*=option1][type!=checkbox]" ), "Attribute Is Not Equal Matches" );
275+
269276
t("Empty values", "#select1 option[value='']", ["option1a"]);
270277
t("Empty values", "#select1 option[value!='']", ["option1b","option1c","option1d"]);
271278

@@ -280,7 +287,7 @@ test("pseudo - child", function() {
280287
expect(31);
281288
t( "First Child", "p:first-child", ["firstp","sndp"] );
282289
t( "Last Child", "p:last-child", ["sap"] );
283-
t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2","liveLink1","liveLink2"] );
290+
t( "Only Child", "#main a:only-child", ["simon1","anchor1","yahoo","anchor2","liveLink1","liveLink2"] );
284291
t( "Empty", "ul:empty", ["firstUL"] );
285292
t( "Is A Parent", "p:parent", ["firstp","ap","sndp","en","sap","first"] );
286293

@@ -294,10 +301,10 @@ test("pseudo - child", function() {
294301

295302
t( "First Child", "p:first-child", [] );
296303

297-
reset();
304+
QUnit.reset();
298305

299306
t( "Last Child", "p:last-child", ["sap"] );
300-
t( "Last Child", "a:last-child", ["simon1","anchor1","mark","yahoo","anchor2","simon","liveLink1","liveLink2"] );
307+
t( "Last Child", "#main a:last-child", ["simon1","anchor1","mark","yahoo","anchor2","simon","liveLink1","liveLink2"] );
301308

302309
t( "Nth-child", "#main form#form > *:nth-child(2)", ["text1"] );
303310
t( "Nth-child", "#main form#form > :nth-child(2)", ["text1"] );
@@ -323,23 +330,27 @@ test("pseudo - child", function() {
323330
});
324331

325332
test("pseudo - misc", function() {
326-
expect(6);
333+
expect(7);
327334

328335
t( "Headers", ":header", ["qunit-header", "qunit-banner", "qunit-userAgent"] );
329336
t( "Has Children - :has()", "p:has(a)", ["firstp","ap","en","sap"] );
337+
338+
var select = document.getElementById("select1");
339+
ok( (window.Sizzle || window.jQuery.find).matchesSelector( select, ":has(option)" ), "Has Option Matches" );
330340

331-
t( "Text Contains", "a:contains('Google')", ["google","groups"] );
332-
t( "Text Contains", "a:contains('Google Groups')", ["groups"] );
341+
t( "Text Contains", "a:contains(Google)", ["google","groups"] );
342+
t( "Text Contains", "a:contains(Google Groups)", ["groups"] );
333343

334-
t( "Text Contains", "a:contains('Google Groups (Link)')", ["groups"] );
335-
t( "Text Contains", "a:contains('(Link)')", ["groups"] );
344+
t( "Text Contains", "a:contains(Google Groups (Link))", ["groups"] );
345+
t( "Text Contains", "a:contains((Link))", ["groups"] );
336346
});
337347

338348

339349
test("pseudo - :not", function() {
340350
expect(24);
341351
t( "Not", "a.blog:not(.link)", ["mark"] );
342-
t( "Not - multiple", "#form option:not(:contains('Nothing'),#option1b,:selected)", ["option1c", "option1d", "option2b", "option2c", "option3d", "option3e"] );
352+
353+
t( "Not - multiple", "#form option:not(:contains(Nothing),#option1b,:selected)", ["option1c", "option1d", "option2b", "option2c", "option3d", "option3e", "option4e", "option5b", "option5c"] );
343354
t( "Not - recursive", "#form option:not(:not(:selected))[id^='option3']", [ "option3b", "option3c"] );
344355

345356
t( ":not() failing interior", "p:not(.foo)", ["firstp","ap","sndp","en","sap","first"] );
@@ -360,9 +371,9 @@ test("pseudo - :not", function() {
360371

361372
t( "No element not selector", ".container div:not(.excluded) div", [] );
362373

363-
t( ":not() Existing attribute", "#form select:not([multiple])", ["select1", "select2"]);
364-
t( ":not() Equals attribute", "#form select:not([name=select1])", ["select2", "select3"]);
365-
t( ":not() Equals quoted attribute", "#form select:not([name='select1'])", ["select2", "select3"]);
374+
t( ":not() Existing attribute", "#form select:not([multiple])", ["select1", "select2", "select5"]);
375+
t( ":not() Equals attribute", "#form select:not([name=select1])", ["select2", "select3", "select4","select5"]);
376+
t( ":not() Equals quoted attribute", "#form select:not([name='select1'])", ["select2", "select3", "select4", "select5"]);
366377

367378
t( ":not() Multiple Class", "#foo a:not(.blog)", ["yahoo","anchor2"] );
368379
t( ":not() Multiple Class", "#foo a:not(.link)", ["yahoo","anchor2"] );
@@ -428,13 +439,13 @@ test("pseudo - visibility", function() {
428439
test("pseudo - form", function() {
429440
expect(8);
430441

431-
t( "Form element :input", "#form :input", ["text1", "text2", "radio1", "radio2", "check1", "check2", "hidden1", "hidden2", "name", "search", "button", "area1", "select1", "select2", "select3"] );
442+
t( "Form element :input", "#form :input", ["text1", "text2", "radio1", "radio2", "check1", "check2", "hidden1", "hidden2", "name", "search", "button", "area1", "select1", "select2", "select3", "select4", "select5"] );
432443
t( "Form element :radio", "#form :radio", ["radio1", "radio2"] );
433444
t( "Form element :checkbox", "#form :checkbox", ["check1", "check2"] );
434445
t( "Form element :text", "#form :text:not(#search)", ["text1", "text2", "hidden2", "name"] );
435446
t( "Form element :radio:checked", "#form :radio:checked", ["radio2"] );
436447
t( "Form element :checkbox:checked", "#form :checkbox:checked", ["check1"] );
437448
t( "Form element :radio:checked, :checkbox:checked", "#form :radio:checked, #form :checkbox:checked", ["radio2", "check1"] );
438449

439-
t( "Selected Option Element", "#form option:selected", ["option1a","option2d","option3b","option3c"] );
450+
t( "Selected Option Element", "#form option:selected", ["option1a","option2d","option3b","option3c","option4b","option4c","option4d","option5a"] );
440451
});

0 commit comments

Comments
 (0)