11define ( [
22 "./core" ,
33 "./var/document" ,
4- "./var/documentElement"
5- ] , function ( jQuery , document , documentElement ) {
4+ "./var/documentElement" ,
5+ "./var/hasOwn" ,
6+ "./var/indexOf"
7+ ] , function ( jQuery , document , documentElement , hasOwn , indexOf ) {
68
79/*
810 * Optional (non-Sizzle) selector module for custom builds.
@@ -29,69 +31,84 @@ define( [
2931 * customize this stub for the project's specific needs.
3032 */
3133
32- var hasDuplicate ,
34+ var hasDuplicate , sortInput ,
35+ sortStable = jQuery . expando . split ( "" ) . sort ( sortOrder ) . join ( "" ) === jQuery . expando ,
3336 matches = documentElement . matches ||
3437 documentElement . webkitMatchesSelector ||
3538 documentElement . mozMatchesSelector ||
3639 documentElement . oMatchesSelector ||
37- documentElement . msMatchesSelector ,
38- sortOrder = function ( a , b ) {
40+ documentElement . msMatchesSelector ;
3941
40- // Flag for duplicate removal
41- if ( a === b ) {
42- hasDuplicate = true ;
43- return 0 ;
44- }
42+ function sortOrder ( a , b ) {
4543
46- var compare = b . compareDocumentPosition &&
47- a . compareDocumentPosition &&
48- a . compareDocumentPosition ( b ) ;
44+ // Flag for duplicate removal
45+ if ( a === b ) {
46+ hasDuplicate = true ;
47+ return 0 ;
48+ }
4949
50- if ( compare ) {
50+ // Sort on method existence if only one input has compareDocumentPosition
51+ var compare = ! a . compareDocumentPosition - ! b . compareDocumentPosition ;
52+ if ( compare ) {
53+ return compare ;
54+ }
5155
52- // Disconnected nodes
53- if ( compare & 1 ) {
56+ // Calculate position if both inputs belong to the same document
57+ compare = ( a . ownerDocument || a ) === ( b . ownerDocument || b ) ?
58+ a . compareDocumentPosition ( b ) :
5459
55- // Choose the first element that is related to our document
56- if ( a === document || jQuery . contains ( document , a ) ) {
57- return - 1 ;
58- }
59- if ( b === document || jQuery . contains ( document , b ) ) {
60- return 1 ;
61- }
60+ // Otherwise we know they are disconnected
61+ 1 ;
6262
63- // Maintain original order
64- return 0 ;
65- }
63+ // Disconnected nodes
64+ if ( compare & 1 ) {
6665
67- return compare & 4 ? - 1 : 1 ;
66+ // Choose the first element that is related to our preferred document
67+ if ( a === document || a . ownerDocument === document &&
68+ jQuery . contains ( document , a ) ) {
69+ return - 1 ;
70+ }
71+ if ( b === document || b . ownerDocument === document &&
72+ jQuery . contains ( document , b ) ) {
73+ return 1 ;
6874 }
6975
70- // Not directly comparable, sort on existence of method
71- return a . compareDocumentPosition ? - 1 : 1 ;
72- } ,
73- uniqueSort = function ( results ) {
74- var elem ,
75- duplicates = [ ] ,
76- i = 0 ,
77- j = 0 ;
76+ // Maintain original order
77+ return sortInput ?
78+ ( indexOf . call ( sortInput , a ) - indexOf . call ( sortInput , b ) ) :
79+ 0 ;
80+ }
7881
79- hasDuplicate = false ;
80- results . sort ( sortOrder ) ;
82+ return compare & 4 ? - 1 : 1 ;
83+ }
8184
82- if ( hasDuplicate ) {
83- while ( ( elem = results [ i ++ ] ) ) {
84- if ( elem === results [ i ] ) {
85- j = duplicates . push ( i ) ;
86- }
87- }
88- while ( j -- ) {
89- results . splice ( duplicates [ j ] , 1 ) ;
85+ function uniqueSort ( results ) {
86+ var elem ,
87+ duplicates = [ ] ,
88+ j = 0 ,
89+ i = 0 ;
90+
91+ hasDuplicate = false ;
92+ sortInput = ! sortStable && results . slice ( 0 ) ;
93+ results . sort ( sortOrder ) ;
94+
95+ if ( hasDuplicate ) {
96+ while ( ( elem = results [ i ++ ] ) ) {
97+ if ( elem === results [ i ] ) {
98+ j = duplicates . push ( i ) ;
9099 }
91100 }
101+ while ( j -- ) {
102+ results . splice ( duplicates [ j ] , 1 ) ;
103+ }
104+ }
92105
93- return results ;
94- } ;
106+ // Clear input after sorting to release objects
107+ // See https://github.com/jquery/sizzle/pull/225
108+ sortInput = null ;
109+
110+ return results ;
111+ }
95112
96113jQuery . extend ( {
97114 find : function ( selector , context , results , seed ) {
@@ -157,7 +174,11 @@ jQuery.extend( {
157174 return a === bup || ! ! ( bup && bup . nodeType === 1 && adown . contains ( bup ) ) ;
158175 } ,
159176 isXMLDoc : function ( elem ) {
160- return ( elem . ownerDocument || elem ) . documentElement . nodeName !== "HTML" ;
177+
178+ // documentElement is verified for cases where it doesn't yet exist
179+ // (such as loading iframes in IE - #4833)
180+ var documentElement = elem && ( elem . ownerDocument || elem ) . documentElement ;
181+ return documentElement ? documentElement . nodeName !== "HTML" : false ;
161182 } ,
162183 expr : {
163184 attrHandle : { } ,
@@ -177,7 +198,13 @@ jQuery.extend( jQuery.find, {
177198 return matches . call ( elem , expr ) ;
178199 } ,
179200 attr : function ( elem , name ) {
180- return elem . getAttribute ( name ) ;
201+ var fn = jQuery . expr . attrHandle [ name . toLowerCase ( ) ] ,
202+
203+ // Don't get fooled by Object.prototype properties (jQuery #13807)
204+ value = fn && hasOwn . call ( jQuery . expr . attrHandle , name . toLowerCase ( ) ) ?
205+ fn ( elem , name , jQuery . isXMLDoc ( elem ) ) :
206+ undefined ;
207+ return value !== undefined ? value : elem . getAttribute ( name ) ;
181208 }
182209} ) ;
183210
0 commit comments