Changeset 4537 for trunk/jquery/src
- Timestamp:
- 01/26/08 00:26:28 (1 year ago)
- Location:
- trunk/jquery/src
- Files:
-
- 2 modified
-
core.js (modified) (2 diffs)
-
selector.js (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/jquery/src/core.js
r4513 r4537 1154 1154 1155 1155 grep: function( elems, callback, inv ) { 1156 // If a string is passed in for the function, make a function1157 // for it (a handy shortcut)1158 if ( typeof callback == "string" )1159 callback = eval("false||function(a,i){return " + callback + "}");1160 1161 1156 var ret = []; 1162 1157 … … 1231 1226 1232 1227 jQuery.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);} 1242 1237 }, function(name, fn){ 1243 fn = eval("false||function(elem){return " + fn + "}");1244 1245 1238 jQuery.fn[ name ] = function( selector ) { 1246 1239 var ret = jQuery.map( this, fn ); -
trunk/jquery/src/selector.js
r4239 r4537 9 9 jQuery.extend({ 10 10 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];}, 13 13 ":": { 14 14 // 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;}, 23 23 24 24 // 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");}, 28 28 29 29 // Parent Checks 30 parent: "a.firstChild",31 empty: "!a.firstChild",30 parent: function(a){return a.firstChild;}, 31 empty: function(a){return !a.firstChild;}, 32 32 33 33 // 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;}, 35 35 36 36 // 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";}, 39 39 40 40 // 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");}, 45 45 46 46 // 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);}, 57 57 58 58 // :has() 59 has: "jQuery.find(m[3],a).length",59 has: function(a,i,m){return jQuery.find(m[3],a).length;}, 60 60 61 61 // :header 62 header: "/h\\d/i.test(a.nodeName)",62 header: function(a){return /h\d/i.test(a.nodeName);}, 63 63 64 64 // :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;} 66 66 } 67 67 }, … … 391 391 // Otherwise, find the expression to execute 392 392 } 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 it398 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 + ";}"); 399 399 400 400 // 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 ); 402 404 } 403 405 }
