Changeset 4143
- Timestamp:
- 12/13/07 22:24:59 (1 year ago)
- Location:
- trunk/jquery
- Files:
-
- 5 modified
-
src/core.js (modified) (2 diffs)
-
src/selector.js (modified) (1 diff)
-
test/index.html (modified) (3 diffs)
-
test/unit/core.js (modified) (1 diff)
-
test/unit/selector.js (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/jquery/src/core.js
r4135 r4143 343 343 344 344 not: function( selector ) { 345 return this.pushStack( 346 selector.constructor == String && 347 jQuery.multiFilter( selector, this, true ) || 348 349 jQuery.grep(this, function(elem) { 350 return selector.constructor == Array || selector.jquery ? 351 jQuery.inArray( elem, selector ) < 0 : 352 elem != selector; 353 }) ); 345 if (selector.constructor == String) 346 // test special case where just one selector is passed in 347 if ( /^.[^:#\[\.]*$/.test(selector) ) 348 return this.pushStack( jQuery.multiFilter( selector, this, true ) ); 349 else 350 selector = jQuery.multiFilter( selector, this ); 351 352 return this.pushStack( jQuery.removeFromArray( selector, this ) ); 354 353 }, 355 354 … … 1094 1093 }, 1095 1094 1095 removeFromArray: function( remove, from ) { 1096 var isArrayLike = remove.length && remove[remove.length - 1] !== undefined; 1097 return jQuery.grep(from, function(elem) { 1098 return isArrayLike ? jQuery.inArray( elem, remove ) < 0 : elem != from; 1099 }); 1100 }, 1101 1096 1102 merge: function( first, second ) { 1097 1103 // We have to loop this way because IE & Opera overwrite the length -
trunk/jquery/src/selector.js
r4062 r4143 321 321 // keeping it out of the expression list 322 322 if ( m[1] == ":" && m[2] == "not" ) 323 r = jQuery.filter(m[3], r, true).r; 323 // optimize if only one selector found (most common case) 324 if ( /^.[^:#\[\.]*$/.test(m[3]) ) 325 r = jQuery.filter(m[3], r, true).r; 326 else 327 r = jQuery.removeFromArray(jQuery.multiFilter(m[3], r), r); 324 328 325 329 // We can get a big speed boost by filtering by class here -
trunk/jquery/test/index.html
r4062 r4143 62 62 63 63 <select name="select1" id="select1"> 64 <option id="option1a" value="">Nothing</option>64 <option id="option1a" class="emptyopt" value="">Nothing</option> 65 65 <option id="option1b" value="1">1</option> 66 66 <option id="option1c" value="2">2</option> … … 68 68 </select> 69 69 <select name="select2" id="select2"> 70 <option id="option2a" value="">Nothing</option>70 <option id="option2a" class="emptyopt" value="">Nothing</option> 71 71 <option id="option2b" value="1">1</option> 72 72 <option id="option2c" value="2">2</option> … … 74 74 </select> 75 75 <select name="select3" id="select3" multiple="multiple"> 76 <option id="option3a" value="">Nothing</option>76 <option id="option3a" class="emptyopt" value="">Nothing</option> 77 77 <option id="option3b" selected="selected" value="1">1</option> 78 78 <option id="option3c" selected="selected" value="2">2</option> -
trunk/jquery/test/unit/core.js
r4112 r4143 1053 1053 1054 1054 test("not()", function() { 1055 expect( 3);1055 expect(5); 1056 1056 ok( $("#main > p#ap > a").not("#google").length == 2, "not('selector')" ); 1057 isSet( $("p").not(".result").get(), q("firstp", "ap", "sndp", "en", "sap", "first"), "not('.class')" ); 1057 1058 isSet( $("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" ); 1058 1059 isSet( $("p").not($("#ap, #sndp, .result")).get(), q("firstp", "en", "sap", "first"), "not(jQuery)" ); 1060 isSet( $("#form option").not("option.emptyopt:contains('Nothing'),[selected],[value='1']").get(), q("option1c", "option1d", "option2c", "option3d" ), "not('complex selector')"); 1059 1061 }); 1060 1062 -
trunk/jquery/test/unit/selector.js
r3839 r4143 183 183 184 184 test("pseudo (:) selectors", function() { 185 expect(3 2);185 expect(35); 186 186 t( "First Child", "p:first-child", ["firstp","sndp"] ); 187 187 t( "Last Child", "p:last-child", ["sap"] ); … … 196 196 t( "Element Preceded By", "p ~ div", ["foo","fx-queue","fx-tests", "moretests"] ); 197 197 t( "Not", "a.blog:not(.link)", ["mark"] ); 198 t( "Not - multiple", "#form option:not(:contains('Nothing'),#option1b,:selected)", ["option1c", "option1d", "option2b", "option2c", "option3d"] ); 199 t( "Not - complex", "#form option:not([id^='opt']:gt(0):nth-child(-n+3))", [ "option1a", "option1d", "option2d", "option3d"] ); 200 t( "Not - recursive", "#form option:not(:not(:selected))[id^='option3']", [ "option3b", "option3c"] ); 198 201 199 202 t( "nth Element", "p:nth(1)", ["ap"] );
