Ticket #6418: 6418.patch
| File 6418.patch, 4.4 kB (added by liucougar, 9 months ago) |
|---|
-
_base/query.js
683 683 // based version might be more accurate, but since 684 684 // jQuery and DomQuery also potentially get this wrong, 685 685 // I'm leaving it for now. 686 if(condition.charAt(0)=='"' || condition.charAt(0)=="'"){//remove quote 687 condition=condition.substr(1,condition.length-2); 688 } 686 689 return (elem.innerHTML.indexOf(condition) >= 0); 687 690 } 688 691 }, … … 695 698 "nth-child": function(name, condition){ 696 699 var pi = parseInt; 697 700 if(condition == "odd"){ 698 return function(elem){ 699 return ( 700 ((getNodeIndex(elem)) % 2) == 1 701 ); 701 condition = "2n+1"; 702 }else if(condition == "even"){ 703 condition = "2n"; 704 } 705 if(condition.indexOf("n") != -1){ 706 var tparts = condition.split("n", 2); 707 var pred = tparts[0]?(tparts[0]=='-'?-1:pi(tparts[0])):1; 708 var idx = tparts[1]?pi(tparts[1]):0; 709 var lb = 0, ub = -1; 710 if(pred>0){ 711 if(idx<0){ 712 idx = idx%pred && (pred + idx%pred); 713 }else if(idx>0){ 714 if(idx >= pred){ 715 lb = idx - idx % pred; 716 } 717 idx = idx % pred; 718 } 719 }else if(pred<0){ 720 pred *= -1; 721 if(idx>0){ 722 ub = idx; 723 idx = idx % pred; 724 } //idx has to be greater than 0 when pred is negative; shall we throw an error here? 702 725 } 703 }else if((condition == "2n")|| 704 (condition == "even")){ 705 return function(elem){ 706 return ((getNodeIndex(elem) % 2) == 0); 726 if(pred>0){ 727 return function(elem){ 728 var i=getNodeIndex(elem); 729 return i>=lb && (ub<0 || i<=ub) && ((i % pred) == idx); 730 } 731 }else{ 732 condition=idx; 707 733 } 708 }else if(condition.indexOf("0n+") == 0){709 var ncount = pi(condition.substr(3));710 return function(elem){711 return (elem.parentNode[childNodesName][ncount-1] === elem);712 }713 }else if( (condition.indexOf("n+") > 0) &&714 (condition.length > 3) ){715 var tparts = condition.split("n+", 2);716 var pred = pi(tparts[0]);717 var idx = pi(tparts[1]);718 return function(elem){719 return ((getNodeIndex(elem) % pred) == idx);720 }721 }else if(condition.indexOf("n") == -1){722 var ncount = pi(condition);723 return function(elem){724 return (getNodeIndex(elem) == ncount);725 }726 734 } 735 //if(condition.indexOf("n") == -1){ 736 var ncount = pi(condition); 737 return function(elem){ 738 return (getNodeIndex(elem) == ncount); 739 } 727 740 } 728 741 }; 729 742 … … 809 822 if(query.tag && query.id && !query.hasLoops){ 810 823 // we got a filtered ID search (e.g., "h4#thinger") 811 824 retFunc = function(root){ 812 var te = d.byId(query.id );825 var te = d.byId(query.id,root.ownerDocument||root); //root itself may be a document 813 826 if(filterFunc(te)){ 814 827 return [ te ]; 815 828 } -
tests/_base/query.html
89 89 "doh.is(3, dojo.query('#t h3:nth-child(2n+1)').length);", 90 90 "doh.is(1, dojo.query('#t h3:nth-child(even)').length);", 91 91 "doh.is(1, dojo.query('#t h3:nth-child(2n)').length);", 92 "doh.is( 0, dojo.query('#t h3:nth-child(2n+3)').length);",92 "doh.is(1, dojo.query('#t h3:nth-child(2n+3)').length);", 93 93 "doh.is(2, dojo.query('#t h3:nth-child(1)').length);", 94 94 "doh.is(1, dojo.query('#t > h3:nth-child(1)').length);", 95 95 "doh.is(3, dojo.query('#t :nth-child(3)').length);", 96 96 "doh.is(0, dojo.query('#t > div:nth-child(1)').length);", 97 97 "doh.is(7, dojo.query('#t span').length);", 98 "doh.is(3, dojo.query('#t > *:nth-child(n+10)').length);", 99 "doh.is(1, dojo.query('#t > *:nth-child(n+12)').length);", 100 "doh.is(10, dojo.query('#t > *:nth-child(-n+10)').length);", 101 "doh.is(5, dojo.query('#t > *:nth-child(-2n+10)').length);", 102 "doh.is(6, dojo.query('#t > *:nth-child(2n+2)').length);", 103 "doh.is(5, dojo.query('#t > *:nth-child(2n+4)').length);", 104 "doh.is(5, dojo.query('#t > *:nth-child(2n+4)').length);", 105 "doh.is(12, dojo.query('#t > *:nth-child(n-5)').length);", 106 "doh.is(6, dojo.query('#t > *:nth-child(2n-5)').length);", 107 98 108 // :empty pseudo-selector 99 109 "doh.is(4, dojo.query('#t > span:empty').length);", 100 110 "doh.is(6, dojo.query('#t span:empty').length);",