Bug Tracker

Changeset 4143

Show
Ignore:
Timestamp:
12/13/07 22:24:59 (1 year ago)
Author:
davidserduke
Message:

Fixed #1854 by using wizzud's suggestion. The only real difference is the code is only called when there is more than a single selector. So there should be no speed decrease in the current working cases. Only additional functionality for cases that used to fail.

Location:
trunk/jquery
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/jquery/src/core.js

    r4135 r4143  
    343343 
    344344    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 ) ); 
    354353    }, 
    355354 
     
    10941093    }, 
    10951094 
     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 
    10961102    merge: function( first, second ) { 
    10971103        // We have to loop this way because IE & Opera overwrite the length 
  • trunk/jquery/src/selector.js

    r4062 r4143  
    321321            // keeping it out of the expression list 
    322322            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); 
    324328 
    325329            // We can get a big speed boost by filtering by class here 
  • trunk/jquery/test/index.html

    r4062 r4143  
    6262             
    6363            <select name="select1" id="select1"> 
    64                 <option id="option1a" value="">Nothing</option> 
     64                <option id="option1a" class="emptyopt" value="">Nothing</option> 
    6565                <option id="option1b" value="1">1</option> 
    6666                <option id="option1c" value="2">2</option> 
     
    6868            </select> 
    6969            <select name="select2" id="select2"> 
    70                 <option id="option2a" value="">Nothing</option> 
     70                <option id="option2a" class="emptyopt" value="">Nothing</option> 
    7171                <option id="option2b" value="1">1</option> 
    7272                <option id="option2c" value="2">2</option> 
     
    7474            </select> 
    7575            <select name="select3" id="select3" multiple="multiple"> 
    76                 <option id="option3a" value="">Nothing</option> 
     76                <option id="option3a" class="emptyopt" value="">Nothing</option> 
    7777                <option id="option3b" selected="selected" value="1">1</option> 
    7878                <option id="option3c" selected="selected" value="2">2</option> 
  • trunk/jquery/test/unit/core.js

    r4112 r4143  
    10531053 
    10541054test("not()", function() { 
    1055     expect(3); 
     1055    expect(5); 
    10561056    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')" ); 
    10571058    isSet( $("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" ); 
    10581059    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')"); 
    10591061}); 
    10601062 
  • trunk/jquery/test/unit/selector.js

    r3839 r4143  
    183183 
    184184test("pseudo (:) selectors", function() { 
    185     expect(32); 
     185    expect(35); 
    186186    t( "First Child", "p:first-child", ["firstp","sndp"] ); 
    187187    t( "Last Child", "p:last-child", ["sap"] ); 
     
    196196    t( "Element Preceded By", "p ~ div", ["foo","fx-queue","fx-tests", "moretests"] ); 
    197197    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"] ); 
    198201     
    199202    t( "nth Element", "p:nth(1)", ["ap"] );