scratch – Diff between revs 58 and 125

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 58 Rev 125
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"; -  
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
22 }; 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 }
-   46 });
23   47  
24 jQuery.fn.extend( { 48 jQuery.fn.extend({
25 has: function( target ) { 49 has: function( target ) {
26 var targets = jQuery( target, this ), 50 var targets = jQuery( target, this ),
27 l = targets.length; 51 l = targets.length;
28   52  
29 return this.filter( function() { 53 return this.filter(function() {
30 var i = 0; 54 var i = 0;
31 for ( ; i < l; i++ ) { 55 for ( ; i < l; i++ ) {
32 if ( jQuery.contains( this, targets[ i ] ) ) { 56 if ( jQuery.contains( this, targets[i] ) ) {
33 return true; 57 return true;
34 } 58 }
35 } 59 }
36 } ); 60 });
37 }, 61 },
38   62  
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;
45   71  
-   72 for ( ; i < l; i++ ) {
46 // Positional selectors never match, since there's no _selection_ context 73 for ( cur = this[i]; cur && cur !== context; cur = cur.parentNode ) {
-   74 // Always skip document fragments
47 if ( !rneedsContext.test( selectors ) ) { 75 if ( cur.nodeType < 11 && (pos ?
-   76 pos.index(cur) > -1 :
-   77  
-   78 // Don't pass non-elements to Sizzle
48 for ( ; i < l; i++ ) { 79 cur.nodeType === 1 &&
49 for ( cur = this[ i ]; cur && cur !== context; cur = cur.parentNode ) { 80 jQuery.find.matchesSelector(cur, selectors)) ) {
50   -  
51 // Always skip document fragments -  
52 if ( cur.nodeType < 11 && ( targets ? -  
53 targets.index( cur ) > -1 : -  
54   -  
55 // Don't pass non-elements to Sizzle -  
56 cur.nodeType === 1 && -  
57 jQuery.find.matchesSelector( cur, selectors ) ) ) { -  
58   81  
59 matched.push( cur ); 82 matched.push( cur );
60 break; -  
61 } 83 break;
62 } 84 }
63 } 85 }
64 } 86 }
65   87  
66 return this.pushStack( matched.length > 1 ? jQuery.uniqueSort( matched ) : matched ); 88 return this.pushStack( matched.length > 1 ? jQuery.unique( matched ) : matched );
67 }, 89 },
68   90  
69 // Determine the position of an element within the set 91 // Determine the position of an element within the set
70 index: function( elem ) { 92 index: function( elem ) {
71   93  
72 // No argument, return index in parent 94 // No argument, return index in parent
73 if ( !elem ) { 95 if ( !elem ) {
74 return ( this[ 0 ] && this[ 0 ].parentNode ) ? this.first().prevAll().length : -1; 96 return ( this[ 0 ] && this[ 0 ].parentNode ) ? this.first().prevAll().length : -1;
75 } 97 }
76   98  
77 // Index in selector 99 // Index in selector
78 if ( typeof elem === "string" ) { 100 if ( typeof elem === "string" ) {
79 return indexOf.call( jQuery( elem ), this[ 0 ] ); 101 return indexOf.call( jQuery( elem ), this[ 0 ] );
80 } 102 }
81   103  
82 // Locate the position of the desired element 104 // Locate the position of the desired element
83 return indexOf.call( this, 105 return indexOf.call( this,
84   106  
85 // If it receives a jQuery object, the first element is used 107 // If it receives a jQuery object, the first element is used
86 elem.jquery ? elem[ 0 ] : elem 108 elem.jquery ? elem[ 0 ] : elem
87 ); 109 );
88 }, 110 },
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 );
96 }, 118 },
97   119  
98 addBack: function( selector ) { 120 addBack: function( selector ) {
99 return this.add( selector == null ? 121 return this.add( selector == null ?
100 this.prevObject : this.prevObject.filter( selector ) 122 this.prevObject : this.prevObject.filter(selector)
101 ); 123 );
102 } 124 }
103 } ); 125 });
104   126  
105 function sibling( cur, dir ) { 127 function sibling( cur, dir ) {
106 while ( ( cur = cur[ dir ] ) && cur.nodeType !== 1 ) {} 128 while ( (cur = cur[dir]) && cur.nodeType !== 1 ) {}
107 return cur; 129 return cur;
108 } 130 }
109   131  
110 jQuery.each( { 132 jQuery.each({
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 ) {
149 jQuery.fn[ name ] = function( until, selector ) { 171 jQuery.fn[ name ] = function( until, selector ) {
150 var matched = jQuery.map( this, fn, until ); 172 var matched = jQuery.map( this, fn, until );
151   173  
152 if ( name.slice( -5 ) !== "Until" ) { 174 if ( name.slice( -5 ) !== "Until" ) {
153 selector = until; 175 selector = until;
154 } 176 }
155   177  
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 }
159   181  
160 if ( this.length > 1 ) { 182 if ( this.length > 1 ) {
161   -  
162 // Remove duplicates 183 // Remove duplicates
163 if ( !guaranteedUnique[ name ] ) { 184 if ( !guaranteedUnique[ name ] ) {
164 jQuery.uniqueSort( matched ); 185 jQuery.unique( matched );
165 } 186 }
166   187  
167 // Reverse order for parents* and prev-derivatives 188 // Reverse order for parents* and prev-derivatives
168 if ( rparentsprev.test( name ) ) { 189 if ( rparentsprev.test( name ) ) {
169 matched.reverse(); 190 matched.reverse();
170 } 191 }
171 } 192 }
172   193  
173 return this.pushStack( matched ); 194 return this.pushStack( matched );
174 }; 195 };
175 } ); 196 });
176   197  
177 return jQuery; 198 return jQuery;
178 } ); 199 });
179   200