Bug Tracker

Changeset 4537 for trunk/jquery/src

Show
Ignore:
Timestamp:
01/26/08 00:26:28 (1 year ago)
Author:
jeresig
Message:

De-eval'd selectors and the various DOM methods (will marginally help our speed and make us more compatible with projects like Caja and Adobe AIR). Left a selector eval in for backwards compatibility support of selector plugins.

Location:
trunk/jquery/src
Files:
2 modified

Legend:

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

    r4513 r4537  
    11541154 
    11551155    grep: function( elems, callback, inv ) { 
    1156         // If a string is passed in for the function, make a function 
    1157         // for it (a handy shortcut) 
    1158         if ( typeof callback == "string" ) 
    1159             callback = eval("false||function(a,i){return " + callback + "}"); 
    1160  
    11611156        var ret = []; 
    11621157 
     
    12311226 
    12321227jQuery.each({ 
    1233     parent: "elem.parentNode", 
    1234     parents: "jQuery.dir(elem,'parentNode')", 
    1235     next: "jQuery.nth(elem,2,'nextSibling')", 
    1236     prev: "jQuery.nth(elem,2,'previousSibling')", 
    1237     nextAll: "jQuery.dir(elem,'nextSibling')", 
    1238     prevAll: "jQuery.dir(elem,'previousSibling')", 
    1239     siblings: "jQuery.sibling(elem.parentNode.firstChild,elem)", 
    1240     children: "jQuery.sibling(elem.firstChild)", 
    1241     contents: "jQuery.nodeName(elem,'iframe')?elem.contentDocument||elem.contentWindow.document:jQuery.makeArray(elem.childNodes)" 
     1228    parent: function(elem){return elem.parentNode;}, 
     1229    parents: function(elem){return jQuery.dir(elem,"parentNode");}, 
     1230    next: function(elem){return jQuery.nth(elem,2,"nextSibling");}, 
     1231    prev: function(elem){return jQuery.nth(elem,2,"previousSibling");}, 
     1232    nextAll: function(elem){return jQuery.dir(elem,"nextSibling");}, 
     1233    prevAll: function(elem){return jQuery.dir(elem,"previousSibling");}, 
     1234    siblings: function(elem){return jQuery.sibling(elem.parentNode.firstChild,elem);}, 
     1235    children: function(elem){return jQuery.sibling(elem.firstChild);}, 
     1236    contents: function(elem){return jQuery.nodeName(elem,"iframe")?elem.contentDocument||elem.contentWindow.document:jQuery.makeArray(elem.childNodes);} 
    12421237}, function(name, fn){ 
    1243     fn = eval("false||function(elem){return " + fn + "}"); 
    1244  
    12451238    jQuery.fn[ name ] = function( selector ) { 
    12461239        var ret = jQuery.map( this, fn ); 
  • trunk/jquery/src/selector.js

    r4239 r4537  
    99jQuery.extend({ 
    1010    expr: { 
    11         "": "m[2]=='*'||jQuery.nodeName(a,m[2])", 
    12         "#": "a.getAttribute('id')==m[2]", 
     11        "": function(a,i,m){return m[2]=="*"||jQuery.nodeName(a,m[2]);}, 
     12        "#": function(a,i,m){return a.getAttribute("id")==m[2];}, 
    1313        ":": { 
    1414            // Position Checks 
    15             lt: "i<m[3]-0", 
    16             gt: "i>m[3]-0", 
    17             nth: "m[3]-0==i", 
    18             eq: "m[3]-0==i", 
    19             first: "i==0", 
    20             last: "i==r.length-1", 
    21             even: "i%2==0", 
    22             odd: "i%2", 
     15            lt: function(a,i,m){return i<m[3]-0;}, 
     16            gt: function(a,i,m){return i>m[3]-0;}, 
     17            nth: function(a,i,m){return m[3]-0==i;}, 
     18            eq: function(a,i,m){return m[3]-0==i;}, 
     19            first: function(a,i){return i==0;}, 
     20            last: function(a,i,m,r){return i==r.length-1;}, 
     21            even: function(a,i){return i%2==0;}, 
     22            odd: function(a,i){return i%2;}, 
    2323 
    2424            // Child Checks 
    25             "first-child": "a.parentNode.getElementsByTagName('*')[0]==a", 
    26             "last-child": "jQuery.nth(a.parentNode.lastChild,1,'previousSibling')==a", 
    27             "only-child": "!jQuery.nth(a.parentNode.lastChild,2,'previousSibling')", 
     25            "first-child": function(a){return a.parentNode.getElementsByTagName("*")[0]==a;}, 
     26            "last-child": function(a){return jQuery.nth(a.parentNode.lastChild,1,"previousSibling")==a;}, 
     27            "only-child": function(a){return !jQuery.nth(a.parentNode.lastChild,2,"previousSibling");}, 
    2828 
    2929            // Parent Checks 
    30             parent: "a.firstChild", 
    31             empty: "!a.firstChild", 
     30            parent: function(a){return a.firstChild;}, 
     31            empty: function(a){return !a.firstChild;}, 
    3232 
    3333            // Text Check 
    34             contains: "(a.textContent||a.innerText||jQuery(a).text()||'').indexOf(m[3])>=0", 
     34            contains: function(a,i,m){return (a.textContent||a.innerText||jQuery(a).text()||"").indexOf(m[3])>=0;}, 
    3535 
    3636            // Visibility 
    37             visible: '"hidden"!=a.type&&jQuery.css(a,"display")!="none"&&jQuery.css(a,"visibility")!="hidden"', 
    38             hidden: '"hidden"==a.type||jQuery.css(a,"display")=="none"||jQuery.css(a,"visibility")=="hidden"', 
     37            visible: function(a){return "hidden"!=a.type&&jQuery.css(a,"display")!="none"&&jQuery.css(a,"visibility")!="hidden";}, 
     38            hidden: function(a){return "hidden"==a.type||jQuery.css(a,"display")=="none"||jQuery.css(a,"visibility")=="hidden";}, 
    3939 
    4040            // Form attributes 
    41             enabled: "!a.disabled", 
    42             disabled: "a.disabled", 
    43             checked: "a.checked", 
    44             selected: "a.selected||jQuery.attr(a,'selected')", 
     41            enabled: function(a){return !a.disabled;}, 
     42            disabled: function(a){return a.disabled;}, 
     43            checked: function(a){return a.checked;}, 
     44            selected: function(a){return a.selected||jQuery.attr(a,"selected");}, 
    4545 
    4646            // Form elements 
    47             text: "'text'==a.type", 
    48             radio: "'radio'==a.type", 
    49             checkbox: "'checkbox'==a.type", 
    50             file: "'file'==a.type", 
    51             password: "'password'==a.type", 
    52             submit: "'submit'==a.type", 
    53             image: "'image'==a.type", 
    54             reset: "'reset'==a.type", 
    55             button: '"button"==a.type||jQuery.nodeName(a,"button")', 
    56             input: "/input|select|textarea|button/i.test(a.nodeName)", 
     47            text: function(a){return "text"==a.type;}, 
     48            radio: function(a){return "radio"==a.type;}, 
     49            checkbox: function(a){return "checkbox"==a.type;}, 
     50            file: function(a){return "file"==a.type;}, 
     51            password: function(a){return "password"==a.type;}, 
     52            submit: function(a){return "submit"==a.type;}, 
     53            image: function(a){return "image"==a.type;}, 
     54            reset: function(a){return "reset"==a.type;}, 
     55            button: function(a){return "button"==a.type||jQuery.nodeName(a,"button");}, 
     56            input: function(a){return /input|select|textarea|button/i.test(a.nodeName);}, 
    5757 
    5858            // :has() 
    59             has: "jQuery.find(m[3],a).length", 
     59            has: function(a,i,m){return jQuery.find(m[3],a).length;}, 
    6060 
    6161            // :header 
    62             header: "/h\\d/i.test(a.nodeName)", 
     62            header: function(a){return /h\d/i.test(a.nodeName);}, 
    6363 
    6464            // :animated 
    65             animated: "jQuery.grep(jQuery.timers,function(fn){return a==fn.elem;}).length" 
     65            animated: function(a){return jQuery.grep(jQuery.timers,function(fn){return a==fn.elem;}).length;} 
    6666        } 
    6767    }, 
     
    391391            // Otherwise, find the expression to execute 
    392392            } else { 
    393                 var f = jQuery.expr[m[1]]; 
    394                 if ( typeof f != "string" ) 
    395                     f = jQuery.expr[m[1]][m[2]]; 
    396  
    397                 // Build a custom macro to enclose it 
    398                 f = eval("false||function(a,i){return " + f + "}"); 
     393                var fn = jQuery.expr[ m[1] ]; 
     394                if ( typeof fn == "object" ) 
     395                    fn = fn[ m[2] ]; 
     396 
     397                if ( typeof fn == "string" ) 
     398                    fn = eval("false||function(a,i){return " + fn + ";}"); 
    399399 
    400400                // Execute it against the current filter 
    401                 r = jQuery.grep( r, f, not ); 
     401                r = jQuery.grep( r, function(elem, i){ 
     402                    return fn(elem, i, m, r); 
     403                }, not ); 
    402404            } 
    403405        }