scratch – Diff between revs 58 and 125

Subversion Repositories:
Rev:
Show entire fileRegard whitespace
Rev 58 Rev 125
Line 1... Line 1...
1 define( [ 1 define([
2 "./core", 2 "./core",
3 "./var/indexOf", 3 "./var/indexOf",
4 "./traversing/var/dir", -  
5 "./traversing/var/siblings", -  
6 "./traversing/var/rneedsContext", 4 "./traversing/var/rneedsContext",
7 "./core/init", 5 "./core/init",
8 "./traversing/findFilter", 6 "./traversing/findFilter",
9 "./selector" 7 "./selector"
10 ], function( jQuery, indexOf, dir, siblings, rneedsContext ) { 8 ], function( jQuery, indexOf, rneedsContext ) {
11   -  
12 "use strict"; -  
Line 13... Line 9...
13   9  
14 var rparentsprev = /^(?:parents|prev(?:Until|All))/, -  
15   10 var rparentsprev = /^(?:parents|prev(?:Until|All))/,
16 // Methods guaranteed to produce a unique set when starting from a unique set 11 // Methods guaranteed to produce a unique set when starting from a unique set
17 guaranteedUnique = { 12 guaranteedUnique = {
18 children: true, 13 children: true,
19 contents: true, 14 contents: true,
20 next: true, 15 next: true,
21 prev: true 16 prev: true
Line -... Line 17...
-   17 };
-   18  
-   19 jQuery.extend({
-   20 dir: function( elem, dir, until ) {
-   21 var matched = [],
-   22 truncate = until !== undefined;
-   23  
-   24 while ( (elem = elem[ dir ]) && elem.nodeType !== 9 ) {
-   25 if ( elem.nodeType === 1 ) {
-   26 if ( truncate && jQuery( elem ).is( until ) ) {
-   27 break;
-   28 }
-   29 matched.push( elem );
-   30 }
-   31 }
-   32 return matched;
-   33 },
-   34  
-   35 sibling: function( n, elem ) {
-   36 var matched = [];
-   37  
-   38 for ( ; n; n = n.nextSibling ) {
-   39 if ( n.nodeType === 1 && n !== elem ) {
-   40 matched.push( n );
-   41 }
-   42 }
-   43  
-   44 return matched;
-   45 }
22 }; 46 });
23   47  
24 jQuery.fn.extend( { 48 jQuery.fn.extend({
25 has: function( target ) { 49 has: function( target ) {
Line 39... Line 63...
39 closest: function( selectors, context ) { 63 closest: function( selectors, context ) {
40 var cur, 64 var cur,
41 i = 0, 65 i = 0,
42 l = this.length, 66 l = this.length,
43 matched = [], 67 matched = [],
44 targets = typeof selectors !== "string" && jQuery( selectors ); 68 pos = rneedsContext.test( selectors ) || typeof selectors !== "string" ?
-   69 jQuery( selectors, context || this.context ) :
-   70 0;
Line 45... Line -...
45   -  
46 // Positional selectors never match, since there's no _selection_ context -  
47 if ( !rneedsContext.test( selectors ) ) { 71  
48 for ( ; i < l; i++ ) { 72 for ( ; i < l; i++ ) {
49 for ( cur = this[ i ]; cur && cur !== context; cur = cur.parentNode ) { -  
50   73 for ( cur = this[i]; cur && cur !== context; cur = cur.parentNode ) {
51 // Always skip document fragments 74 // Always skip document fragments
52 if ( cur.nodeType < 11 && ( targets ? 75 if ( cur.nodeType < 11 && (pos ?
Line 53... Line 76...
53 targets.index( cur ) > -1 : 76 pos.index(cur) > -1 :
54   77  
55 // Don't pass non-elements to Sizzle 78 // Don't pass non-elements to Sizzle
Line 56... Line 79...
56 cur.nodeType === 1 && 79 cur.nodeType === 1 &&
57 jQuery.find.matchesSelector( cur, selectors ) ) ) { 80 jQuery.find.matchesSelector(cur, selectors)) ) {
58   81  
59 matched.push( cur ); 82 matched.push( cur );
60 break; 83 break;
61 } -  
Line 62... Line 84...
62 } 84 }
63 } 85 }
Line 64... Line 86...
64 } 86 }
65   87  
Line 87... Line 109...
87 ); 109 );
88 }, 110 },
Line 89... Line 111...
89   111  
90 add: function( selector, context ) { 112 add: function( selector, context ) {
91 return this.pushStack( 113 return this.pushStack(
92 jQuery.uniqueSort( 114 jQuery.unique(
93 jQuery.merge( this.get(), jQuery( selector, context ) ) 115 jQuery.merge( this.get(), jQuery( selector, context ) )
94 ) 116 )
95 ); 117 );
Line 111... Line 133...
111 parent: function( elem ) { 133 parent: function( elem ) {
112 var parent = elem.parentNode; 134 var parent = elem.parentNode;
113 return parent && parent.nodeType !== 11 ? parent : null; 135 return parent && parent.nodeType !== 11 ? parent : null;
114 }, 136 },
115 parents: function( elem ) { 137 parents: function( elem ) {
116 return dir( elem, "parentNode" ); 138 return jQuery.dir( elem, "parentNode" );
117 }, 139 },
118 parentsUntil: function( elem, i, until ) { 140 parentsUntil: function( elem, i, until ) {
119 return dir( elem, "parentNode", until ); 141 return jQuery.dir( elem, "parentNode", until );
120 }, 142 },
121 next: function( elem ) { 143 next: function( elem ) {
122 return sibling( elem, "nextSibling" ); 144 return sibling( elem, "nextSibling" );
123 }, 145 },
124 prev: function( elem ) { 146 prev: function( elem ) {
125 return sibling( elem, "previousSibling" ); 147 return sibling( elem, "previousSibling" );
126 }, 148 },
127 nextAll: function( elem ) { 149 nextAll: function( elem ) {
128 return dir( elem, "nextSibling" ); 150 return jQuery.dir( elem, "nextSibling" );
129 }, 151 },
130 prevAll: function( elem ) { 152 prevAll: function( elem ) {
131 return dir( elem, "previousSibling" ); 153 return jQuery.dir( elem, "previousSibling" );
132 }, 154 },
133 nextUntil: function( elem, i, until ) { 155 nextUntil: function( elem, i, until ) {
134 return dir( elem, "nextSibling", until ); 156 return jQuery.dir( elem, "nextSibling", until );
135 }, 157 },
136 prevUntil: function( elem, i, until ) { 158 prevUntil: function( elem, i, until ) {
137 return dir( elem, "previousSibling", until ); 159 return jQuery.dir( elem, "previousSibling", until );
138 }, 160 },
139 siblings: function( elem ) { 161 siblings: function( elem ) {
140 return siblings( ( elem.parentNode || {} ).firstChild, elem ); 162 return jQuery.sibling( ( elem.parentNode || {} ).firstChild, elem );
141 }, 163 },
142 children: function( elem ) { 164 children: function( elem ) {
143 return siblings( elem.firstChild ); 165 return jQuery.sibling( elem.firstChild );
144 }, 166 },
145 contents: function( elem ) { 167 contents: function( elem ) {
146 return elem.contentDocument || jQuery.merge( [], elem.childNodes ); 168 return elem.contentDocument || jQuery.merge( [], elem.childNodes );
147 } 169 }
148 }, function( name, fn ) { 170 }, function( name, fn ) {
Line 156... Line 178...
156 if ( selector && typeof selector === "string" ) { 178 if ( selector && typeof selector === "string" ) {
157 matched = jQuery.filter( selector, matched ); 179 matched = jQuery.filter( selector, matched );
158 } 180 }
Line 159... Line 181...
159   181  
160 if ( this.length > 1 ) { -  
161   182 if ( this.length > 1 ) {
162 // Remove duplicates 183 // Remove duplicates
163 if ( !guaranteedUnique[ name ] ) { 184 if ( !guaranteedUnique[ name ] ) {
164 jQuery.uniqueSort( matched ); 185 jQuery.unique( matched );
Line 165... Line 186...
165 } 186 }
166   187  
167 // Reverse order for parents* and prev-derivatives 188 // Reverse order for parents* and prev-derivatives