|
| 1 | +var selector_hasDuplicate, |
| 2 | + matches = docElem.matchesSelector || |
| 3 | + docElem.mozMatchesSelector || |
| 4 | + docElem.webkitMatchesSelector || |
| 5 | + docElem.oMatchesSelector || |
| 6 | + docElem.msMatchesSelector, |
| 7 | + selector_sortOrder = function( a, b ) { |
| 8 | + // Flag for duplicate removal |
| 9 | + if ( a === b ) { |
| 10 | + selector_hasDuplicate = true; |
| 11 | + return 0; |
| 12 | + } |
| 13 | + |
| 14 | + var compare = b.compareDocumentPosition && a.compareDocumentPosition && a.compareDocumentPosition( b ); |
| 15 | + |
| 16 | + if ( compare ) { |
| 17 | + // Disconnected nodes |
| 18 | + if ( compare & 1 ) { |
| 19 | + |
| 20 | + // Choose the first element that is related to our document |
| 21 | + if ( a === document || jQuery.contains(document, a) ) { |
| 22 | + return -1; |
| 23 | + } |
| 24 | + if ( b === document || jQuery.contains(document, b) ) { |
| 25 | + return 1; |
| 26 | + } |
| 27 | + |
| 28 | + // Maintain original order |
| 29 | + return 0; |
| 30 | + } |
| 31 | + |
| 32 | + return compare & 4 ? -1 : 1; |
| 33 | + } |
| 34 | + |
| 35 | + // Not directly comparable, sort on existence of method |
| 36 | + return a.compareDocumentPosition ? -1 : 1; |
| 37 | + }; |
| 38 | + |
| 39 | +jQuery.extend({ |
| 40 | + find: function( selector, context, results, seed ) { |
| 41 | + var elem, |
| 42 | + i = 0; |
| 43 | + |
| 44 | + results = results || []; |
| 45 | + context = context || document; |
| 46 | + |
| 47 | + if ( seed ) { |
| 48 | + while ( (elem = seed[i++]) ) { |
| 49 | + if ( jQuery.find.matchesSelector(elem, selector) ) { |
| 50 | + results.push( elem ); |
| 51 | + } |
| 52 | + } |
| 53 | + } else { |
| 54 | + jQuery.merge( results, context.querySelectorAll(selector) ); |
| 55 | + } |
| 56 | + |
| 57 | + return results; |
| 58 | + }, |
| 59 | + unique: function( results ) { |
| 60 | + var elem, |
| 61 | + duplicates = [], |
| 62 | + i = 0, |
| 63 | + j = 0; |
| 64 | + |
| 65 | + selector_hasDuplicate = false; |
| 66 | + results.sort( selector_sortOrder ); |
| 67 | + |
| 68 | + if ( selector_hasDuplicate ) { |
| 69 | + while ( (elem = results[i++]) ) { |
| 70 | + if ( elem === results[ i ] ) { |
| 71 | + j = duplicates.push( i ); |
| 72 | + } |
| 73 | + } |
| 74 | + while ( j-- ) { |
| 75 | + results.splice( duplicates[ j ], 1 ); |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + return results; |
| 80 | + }, |
| 81 | + text: function( elem ) { |
| 82 | + var node, |
| 83 | + ret = "", |
| 84 | + i = 0, |
| 85 | + nodeType = elem.nodeType; |
| 86 | + |
| 87 | + if ( !nodeType ) { |
| 88 | + // If no nodeType, this is expected to be an array |
| 89 | + while ( (node = elem[i++]) ) { |
| 90 | + // Do not traverse comment nodes |
| 91 | + ret += jQuery.text( node ); |
| 92 | + } |
| 93 | + } else if ( nodeType === 1 || nodeType === 9 || nodeType === 11 ) { |
| 94 | + // Use textContent for elements |
| 95 | + return elem.textContent; |
| 96 | + } else if ( nodeType === 3 || nodeType === 4 ) { |
| 97 | + return elem.nodeValue; |
| 98 | + } |
| 99 | + // Do not include comment or processing instruction nodes |
| 100 | + |
| 101 | + return ret; |
| 102 | + }, |
| 103 | + contains: function( a, b ) { |
| 104 | + var adown = a.nodeType === 9 ? a.documentElement : a, |
| 105 | + bup = b && b.parentNode; |
| 106 | + return a === bup || !!( bup && bup.nodeType === 1 && adown.contains(bup) ); |
| 107 | + }, |
| 108 | + isXMLDoc: function( elem ) { |
| 109 | + return (elem.ownerDocument || elem).documentElement.nodeName !== "HTML"; |
| 110 | + }, |
| 111 | + expr: { |
| 112 | + match: { |
| 113 | + needsContext: /^[\x20\t\r\n\f]*[>+~]/ |
| 114 | + } |
| 115 | + } |
| 116 | +}); |
| 117 | + |
| 118 | +jQuery.extend( jQuery.find, { |
| 119 | + matches: function( expr, elements ) { |
| 120 | + return jQuery.find( expr, null, null, elements ); |
| 121 | + }, |
| 122 | + matchesSelector: function( elem, expr ) { |
| 123 | + return matches.call( elem, expr ); |
| 124 | + } |
| 125 | +}); |
0 commit comments