scratch – Blame information for rev 125

Subversion Repositories:
Rev:
Rev Author Line No. Line
125 office 1 define([
58 office 2 "./core",
3 "./var/indexOf",
4 "./traversing/var/rneedsContext",
5 "./core/init",
6 "./traversing/findFilter",
7 "./selector"
125 office 8 ], function( jQuery, indexOf, rneedsContext ) {
58 office 9  
10 var rparentsprev = /^(?:parents|prev(?:Until|All))/,
11 // Methods guaranteed to produce a unique set when starting from a unique set
12 guaranteedUnique = {
13 children: true,
14 contents: true,
15 next: true,
16 prev: true
17 };
18  
125 office 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 });
47  
48 jQuery.fn.extend({
58 office 49 has: function( target ) {
50 var targets = jQuery( target, this ),
51 l = targets.length;
52  
125 office 53 return this.filter(function() {
58 office 54 var i = 0;
55 for ( ; i < l; i++ ) {
125 office 56 if ( jQuery.contains( this, targets[i] ) ) {
58 office 57 return true;
58 }
59 }
125 office 60 });
58 office 61 },
62  
63 closest: function( selectors, context ) {
64 var cur,
65 i = 0,
66 l = this.length,
67 matched = [],
125 office 68 pos = rneedsContext.test( selectors ) || typeof selectors !== "string" ?
69 jQuery( selectors, context || this.context ) :
70 0;
58 office 71  
125 office 72 for ( ; i < l; i++ ) {
73 for ( cur = this[i]; cur && cur !== context; cur = cur.parentNode ) {
74 // Always skip document fragments
75 if ( cur.nodeType < 11 && (pos ?
76 pos.index(cur) > -1 :
58 office 77  
125 office 78 // Don't pass non-elements to Sizzle
79 cur.nodeType === 1 &&
80 jQuery.find.matchesSelector(cur, selectors)) ) {
58 office 81  
125 office 82 matched.push( cur );
83 break;
58 office 84 }
85 }
86 }
87  
125 office 88 return this.pushStack( matched.length > 1 ? jQuery.unique( matched ) : matched );
58 office 89 },
90  
91 // Determine the position of an element within the set
92 index: function( elem ) {
93  
94 // No argument, return index in parent
95 if ( !elem ) {
96 return ( this[ 0 ] && this[ 0 ].parentNode ) ? this.first().prevAll().length : -1;
97 }
98  
99 // Index in selector
100 if ( typeof elem === "string" ) {
101 return indexOf.call( jQuery( elem ), this[ 0 ] );
102 }
103  
104 // Locate the position of the desired element
105 return indexOf.call( this,
106  
107 // If it receives a jQuery object, the first element is used
108 elem.jquery ? elem[ 0 ] : elem
109 );
110 },
111  
112 add: function( selector, context ) {
113 return this.pushStack(
125 office 114 jQuery.unique(
58 office 115 jQuery.merge( this.get(), jQuery( selector, context ) )
116 )
117 );
118 },
119  
120 addBack: function( selector ) {
121 return this.add( selector == null ?
125 office 122 this.prevObject : this.prevObject.filter(selector)
58 office 123 );
124 }
125 office 125 });
58 office 126  
127 function sibling( cur, dir ) {
125 office 128 while ( (cur = cur[dir]) && cur.nodeType !== 1 ) {}
58 office 129 return cur;
130 }
131  
125 office 132 jQuery.each({
58 office 133 parent: function( elem ) {
134 var parent = elem.parentNode;
135 return parent && parent.nodeType !== 11 ? parent : null;
136 },
137 parents: function( elem ) {
125 office 138 return jQuery.dir( elem, "parentNode" );
58 office 139 },
140 parentsUntil: function( elem, i, until ) {
125 office 141 return jQuery.dir( elem, "parentNode", until );
58 office 142 },
143 next: function( elem ) {
144 return sibling( elem, "nextSibling" );
145 },
146 prev: function( elem ) {
147 return sibling( elem, "previousSibling" );
148 },
149 nextAll: function( elem ) {
125 office 150 return jQuery.dir( elem, "nextSibling" );
58 office 151 },
152 prevAll: function( elem ) {
125 office 153 return jQuery.dir( elem, "previousSibling" );
58 office 154 },
155 nextUntil: function( elem, i, until ) {
125 office 156 return jQuery.dir( elem, "nextSibling", until );
58 office 157 },
158 prevUntil: function( elem, i, until ) {
125 office 159 return jQuery.dir( elem, "previousSibling", until );
58 office 160 },
161 siblings: function( elem ) {
125 office 162 return jQuery.sibling( ( elem.parentNode || {} ).firstChild, elem );
58 office 163 },
164 children: function( elem ) {
125 office 165 return jQuery.sibling( elem.firstChild );
58 office 166 },
167 contents: function( elem ) {
168 return elem.contentDocument || jQuery.merge( [], elem.childNodes );
169 }
170 }, function( name, fn ) {
171 jQuery.fn[ name ] = function( until, selector ) {
172 var matched = jQuery.map( this, fn, until );
173  
174 if ( name.slice( -5 ) !== "Until" ) {
175 selector = until;
176 }
177  
178 if ( selector && typeof selector === "string" ) {
179 matched = jQuery.filter( selector, matched );
180 }
181  
182 if ( this.length > 1 ) {
183 // Remove duplicates
184 if ( !guaranteedUnique[ name ] ) {
125 office 185 jQuery.unique( matched );
58 office 186 }
187  
188 // Reverse order for parents* and prev-derivatives
189 if ( rparentsprev.test( name ) ) {
190 matched.reverse();
191 }
192 }
193  
194 return this.pushStack( matched );
195 };
125 office 196 });
58 office 197  
198 return jQuery;
125 office 199 });