Blame view

app/bower_components/jquery/src/traversing.js 4.07 KB
87c93a029   Dang YoungWorld   add modal
1
  define( [
f986e111b   TRUONG   add libs
2
  	"./core",
87c93a029   Dang YoungWorld   add modal
3
4
5
  	"./var/indexOf",
  	"./traversing/var/dir",
  	"./traversing/var/siblings",
f986e111b   TRUONG   add libs
6
7
8
9
  	"./traversing/var/rneedsContext",
  	"./core/init",
  	"./traversing/findFilter",
  	"./selector"
87c93a029   Dang YoungWorld   add modal
10
11
12
  ], function( jQuery, indexOf, dir, siblings, rneedsContext ) {
  
  "use strict";
f986e111b   TRUONG   add libs
13
14
  
  var rparentsprev = /^(?:parents|prev(?:Until|All))/,
87c93a029   Dang YoungWorld   add modal
15
16
  
  	// Methods guaranteed to produce a unique set when starting from a unique set
f986e111b   TRUONG   add libs
17
18
19
20
21
22
  	guaranteedUnique = {
  		children: true,
  		contents: true,
  		next: true,
  		prev: true
  	};
87c93a029   Dang YoungWorld   add modal
23
  jQuery.fn.extend( {
f986e111b   TRUONG   add libs
24
  	has: function( target ) {
87c93a029   Dang YoungWorld   add modal
25
26
  		var targets = jQuery( target, this ),
  			l = targets.length;
f986e111b   TRUONG   add libs
27

87c93a029   Dang YoungWorld   add modal
28
29
30
31
  		return this.filter( function() {
  			var i = 0;
  			for ( ; i < l; i++ ) {
  				if ( jQuery.contains( this, targets[ i ] ) ) {
f986e111b   TRUONG   add libs
32
33
34
  					return true;
  				}
  			}
87c93a029   Dang YoungWorld   add modal
35
  		} );
f986e111b   TRUONG   add libs
36
37
38
39
40
41
42
  	},
  
  	closest: function( selectors, context ) {
  		var cur,
  			i = 0,
  			l = this.length,
  			matched = [],
87c93a029   Dang YoungWorld   add modal
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
  			targets = typeof selectors !== "string" && jQuery( selectors );
  
  		// Positional selectors never match, since there's no _selection_ context
  		if ( !rneedsContext.test( selectors ) ) {
  			for ( ; i < l; i++ ) {
  				for ( cur = this[ i ]; cur && cur !== context; cur = cur.parentNode ) {
  
  					// Always skip document fragments
  					if ( cur.nodeType < 11 && ( targets ?
  						targets.index( cur ) > -1 :
  
  						// Don't pass non-elements to Sizzle
  						cur.nodeType === 1 &&
  							jQuery.find.matchesSelector( cur, selectors ) ) ) {
  
  						matched.push( cur );
  						break;
  					}
f986e111b   TRUONG   add libs
61
62
63
  				}
  			}
  		}
87c93a029   Dang YoungWorld   add modal
64
  		return this.pushStack( matched.length > 1 ? jQuery.uniqueSort( matched ) : matched );
f986e111b   TRUONG   add libs
65
  	},
87c93a029   Dang YoungWorld   add modal
66
  	// Determine the position of an element within the set
f986e111b   TRUONG   add libs
67
68
69
70
  	index: function( elem ) {
  
  		// No argument, return index in parent
  		if ( !elem ) {
87c93a029   Dang YoungWorld   add modal
71
  			return ( this[ 0 ] && this[ 0 ].parentNode ) ? this.first().prevAll().length : -1;
f986e111b   TRUONG   add libs
72
  		}
87c93a029   Dang YoungWorld   add modal
73
  		// Index in selector
f986e111b   TRUONG   add libs
74
  		if ( typeof elem === "string" ) {
87c93a029   Dang YoungWorld   add modal
75
  			return indexOf.call( jQuery( elem ), this[ 0 ] );
f986e111b   TRUONG   add libs
76
77
78
  		}
  
  		// Locate the position of the desired element
87c93a029   Dang YoungWorld   add modal
79
  		return indexOf.call( this,
f986e111b   TRUONG   add libs
80
  			// If it receives a jQuery object, the first element is used
87c93a029   Dang YoungWorld   add modal
81
82
  			elem.jquery ? elem[ 0 ] : elem
  		);
f986e111b   TRUONG   add libs
83
84
85
86
  	},
  
  	add: function( selector, context ) {
  		return this.pushStack(
87c93a029   Dang YoungWorld   add modal
87
  			jQuery.uniqueSort(
f986e111b   TRUONG   add libs
88
89
90
91
92
93
94
  				jQuery.merge( this.get(), jQuery( selector, context ) )
  			)
  		);
  	},
  
  	addBack: function( selector ) {
  		return this.add( selector == null ?
87c93a029   Dang YoungWorld   add modal
95
  			this.prevObject : this.prevObject.filter( selector )
f986e111b   TRUONG   add libs
96
97
  		);
  	}
87c93a029   Dang YoungWorld   add modal
98
  } );
f986e111b   TRUONG   add libs
99
100
  
  function sibling( cur, dir ) {
87c93a029   Dang YoungWorld   add modal
101
  	while ( ( cur = cur[ dir ] ) && cur.nodeType !== 1 ) {}
f986e111b   TRUONG   add libs
102
103
  	return cur;
  }
87c93a029   Dang YoungWorld   add modal
104
  jQuery.each( {
f986e111b   TRUONG   add libs
105
106
107
108
109
  	parent: function( elem ) {
  		var parent = elem.parentNode;
  		return parent && parent.nodeType !== 11 ? parent : null;
  	},
  	parents: function( elem ) {
87c93a029   Dang YoungWorld   add modal
110
  		return dir( elem, "parentNode" );
f986e111b   TRUONG   add libs
111
112
  	},
  	parentsUntil: function( elem, i, until ) {
87c93a029   Dang YoungWorld   add modal
113
  		return dir( elem, "parentNode", until );
f986e111b   TRUONG   add libs
114
115
116
117
118
119
120
121
  	},
  	next: function( elem ) {
  		return sibling( elem, "nextSibling" );
  	},
  	prev: function( elem ) {
  		return sibling( elem, "previousSibling" );
  	},
  	nextAll: function( elem ) {
87c93a029   Dang YoungWorld   add modal
122
  		return dir( elem, "nextSibling" );
f986e111b   TRUONG   add libs
123
124
  	},
  	prevAll: function( elem ) {
87c93a029   Dang YoungWorld   add modal
125
  		return dir( elem, "previousSibling" );
f986e111b   TRUONG   add libs
126
127
  	},
  	nextUntil: function( elem, i, until ) {
87c93a029   Dang YoungWorld   add modal
128
  		return dir( elem, "nextSibling", until );
f986e111b   TRUONG   add libs
129
130
  	},
  	prevUntil: function( elem, i, until ) {
87c93a029   Dang YoungWorld   add modal
131
  		return dir( elem, "previousSibling", until );
f986e111b   TRUONG   add libs
132
133
  	},
  	siblings: function( elem ) {
87c93a029   Dang YoungWorld   add modal
134
  		return siblings( ( elem.parentNode || {} ).firstChild, elem );
f986e111b   TRUONG   add libs
135
136
  	},
  	children: function( elem ) {
87c93a029   Dang YoungWorld   add modal
137
  		return siblings( elem.firstChild );
f986e111b   TRUONG   add libs
138
139
  	},
  	contents: function( elem ) {
87c93a029   Dang YoungWorld   add modal
140
  		return elem.contentDocument || jQuery.merge( [], elem.childNodes );
f986e111b   TRUONG   add libs
141
142
143
  	}
  }, function( name, fn ) {
  	jQuery.fn[ name ] = function( until, selector ) {
87c93a029   Dang YoungWorld   add modal
144
  		var matched = jQuery.map( this, fn, until );
f986e111b   TRUONG   add libs
145
146
147
148
149
150
  
  		if ( name.slice( -5 ) !== "Until" ) {
  			selector = until;
  		}
  
  		if ( selector && typeof selector === "string" ) {
87c93a029   Dang YoungWorld   add modal
151
  			matched = jQuery.filter( selector, matched );
f986e111b   TRUONG   add libs
152
153
154
  		}
  
  		if ( this.length > 1 ) {
87c93a029   Dang YoungWorld   add modal
155

f986e111b   TRUONG   add libs
156
157
  			// Remove duplicates
  			if ( !guaranteedUnique[ name ] ) {
87c93a029   Dang YoungWorld   add modal
158
  				jQuery.uniqueSort( matched );
f986e111b   TRUONG   add libs
159
160
161
162
  			}
  
  			// Reverse order for parents* and prev-derivatives
  			if ( rparentsprev.test( name ) ) {
87c93a029   Dang YoungWorld   add modal
163
  				matched.reverse();
f986e111b   TRUONG   add libs
164
165
  			}
  		}
87c93a029   Dang YoungWorld   add modal
166
  		return this.pushStack( matched );
f986e111b   TRUONG   add libs
167
  	};
87c93a029   Dang YoungWorld   add modal
168
  } );
f986e111b   TRUONG   add libs
169
170
  
  return jQuery;
87c93a029   Dang YoungWorld   add modal
171
  } );