Copybara bot | be50d49 | 2023-11-30 00:16:42 +0100 | [diff] [blame] | 1 | define( [ |
| 2 | "./core", |
| 3 | "./var/document", |
| 4 | "./var/documentElement", |
| 5 | "./var/hasOwn", |
| 6 | "./var/indexOf" |
| 7 | ], function( jQuery, document, documentElement, hasOwn, indexOf ) { |
| 8 | |
| 9 | "use strict"; |
| 10 | |
| 11 | /* |
| 12 | * Optional (non-Sizzle) selector module for custom builds. |
| 13 | * |
| 14 | * Note that this DOES NOT SUPPORT many documented jQuery |
| 15 | * features in exchange for its smaller size: |
| 16 | * |
| 17 | * Attribute not equal selector |
| 18 | * Positional selectors (:first; :eq(n); :odd; etc.) |
| 19 | * Type selectors (:input; :checkbox; :button; etc.) |
| 20 | * State-based selectors (:animated; :visible; :hidden; etc.) |
| 21 | * :has(selector) |
| 22 | * :not(complex selector) |
| 23 | * custom selectors via Sizzle extensions |
| 24 | * Leading combinators (e.g., $collection.find("> *")) |
| 25 | * Reliable functionality on XML fragments |
| 26 | * Requiring all parts of a selector to match elements under context |
| 27 | * (e.g., $div.find("div > *") now matches children of $div) |
| 28 | * Matching against non-elements |
| 29 | * Reliable sorting of disconnected nodes |
| 30 | * querySelectorAll bug fixes (e.g., unreliable :focus on WebKit) |
| 31 | * |
| 32 | * If any of these are unacceptable tradeoffs, either use Sizzle or |
| 33 | * customize this stub for the project's specific needs. |
| 34 | */ |
| 35 | |
| 36 | var hasDuplicate, sortInput, |
Renovate bot | f591dcf | 2023-12-30 14:13:54 +0000 | [diff] [blame] | 37 | rhtmlSuffix = /HTML$/i, |
Copybara bot | be50d49 | 2023-11-30 00:16:42 +0100 | [diff] [blame] | 38 | sortStable = jQuery.expando.split( "" ).sort( sortOrder ).join( "" ) === jQuery.expando, |
| 39 | matches = documentElement.matches || |
| 40 | documentElement.webkitMatchesSelector || |
| 41 | documentElement.mozMatchesSelector || |
| 42 | documentElement.oMatchesSelector || |
| 43 | documentElement.msMatchesSelector, |
| 44 | |
| 45 | // CSS string/identifier serialization |
| 46 | // https://drafts.csswg.org/cssom/#common-serializing-idioms |
| 47 | rcssescape = /([\0-\x1f\x7f]|^-?\d)|^-$|[^\x80-\uFFFF\w-]/g, |
| 48 | fcssescape = function( ch, asCodePoint ) { |
| 49 | if ( asCodePoint ) { |
| 50 | |
| 51 | // U+0000 NULL becomes U+FFFD REPLACEMENT CHARACTER |
| 52 | if ( ch === "\0" ) { |
| 53 | return "\uFFFD"; |
| 54 | } |
| 55 | |
| 56 | // Control characters and (dependent upon position) numbers get escaped as code points |
| 57 | return ch.slice( 0, -1 ) + "\\" + ch.charCodeAt( ch.length - 1 ).toString( 16 ) + " "; |
| 58 | } |
| 59 | |
| 60 | // Other potentially-special ASCII characters get backslash-escaped |
| 61 | return "\\" + ch; |
| 62 | }; |
| 63 | |
| 64 | function sortOrder( a, b ) { |
| 65 | |
| 66 | // Flag for duplicate removal |
| 67 | if ( a === b ) { |
| 68 | hasDuplicate = true; |
| 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | // Sort on method existence if only one input has compareDocumentPosition |
| 73 | var compare = !a.compareDocumentPosition - !b.compareDocumentPosition; |
| 74 | if ( compare ) { |
| 75 | return compare; |
| 76 | } |
| 77 | |
| 78 | // Calculate position if both inputs belong to the same document |
| 79 | compare = ( a.ownerDocument || a ) === ( b.ownerDocument || b ) ? |
| 80 | a.compareDocumentPosition( b ) : |
| 81 | |
| 82 | // Otherwise we know they are disconnected |
| 83 | 1; |
| 84 | |
| 85 | // Disconnected nodes |
| 86 | if ( compare & 1 ) { |
| 87 | |
| 88 | // Choose the first element that is related to our preferred document |
| 89 | if ( a === document || a.ownerDocument === document && |
| 90 | jQuery.contains( document, a ) ) { |
| 91 | return -1; |
| 92 | } |
| 93 | if ( b === document || b.ownerDocument === document && |
| 94 | jQuery.contains( document, b ) ) { |
| 95 | return 1; |
| 96 | } |
| 97 | |
| 98 | // Maintain original order |
| 99 | return sortInput ? |
| 100 | ( indexOf.call( sortInput, a ) - indexOf.call( sortInput, b ) ) : |
| 101 | 0; |
| 102 | } |
| 103 | |
| 104 | return compare & 4 ? -1 : 1; |
| 105 | } |
| 106 | |
| 107 | function uniqueSort( results ) { |
| 108 | var elem, |
| 109 | duplicates = [], |
| 110 | j = 0, |
| 111 | i = 0; |
| 112 | |
| 113 | hasDuplicate = false; |
| 114 | sortInput = !sortStable && results.slice( 0 ); |
| 115 | results.sort( sortOrder ); |
| 116 | |
| 117 | if ( hasDuplicate ) { |
| 118 | while ( ( elem = results[ i++ ] ) ) { |
| 119 | if ( elem === results[ i ] ) { |
| 120 | j = duplicates.push( i ); |
| 121 | } |
| 122 | } |
| 123 | while ( j-- ) { |
| 124 | results.splice( duplicates[ j ], 1 ); |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | // Clear input after sorting to release objects |
| 129 | // See https://github.com/jquery/sizzle/pull/225 |
| 130 | sortInput = null; |
| 131 | |
| 132 | return results; |
| 133 | } |
| 134 | |
| 135 | function escape( sel ) { |
| 136 | return ( sel + "" ).replace( rcssescape, fcssescape ); |
| 137 | } |
| 138 | |
| 139 | jQuery.extend( { |
| 140 | uniqueSort: uniqueSort, |
| 141 | unique: uniqueSort, |
| 142 | escapeSelector: escape, |
| 143 | find: function( selector, context, results, seed ) { |
| 144 | var elem, nodeType, |
| 145 | i = 0; |
| 146 | |
| 147 | results = results || []; |
| 148 | context = context || document; |
| 149 | |
| 150 | // Same basic safeguard as Sizzle |
| 151 | if ( !selector || typeof selector !== "string" ) { |
| 152 | return results; |
| 153 | } |
| 154 | |
| 155 | // Early return if context is not an element or document |
| 156 | if ( ( nodeType = context.nodeType ) !== 1 && nodeType !== 9 ) { |
| 157 | return []; |
| 158 | } |
| 159 | |
| 160 | if ( seed ) { |
| 161 | while ( ( elem = seed[ i++ ] ) ) { |
| 162 | if ( jQuery.find.matchesSelector( elem, selector ) ) { |
| 163 | results.push( elem ); |
| 164 | } |
| 165 | } |
| 166 | } else { |
| 167 | jQuery.merge( results, context.querySelectorAll( selector ) ); |
| 168 | } |
| 169 | |
| 170 | return results; |
| 171 | }, |
| 172 | text: function( elem ) { |
| 173 | var node, |
| 174 | ret = "", |
| 175 | i = 0, |
| 176 | nodeType = elem.nodeType; |
| 177 | |
| 178 | if ( !nodeType ) { |
| 179 | |
| 180 | // If no nodeType, this is expected to be an array |
| 181 | while ( ( node = elem[ i++ ] ) ) { |
| 182 | |
| 183 | // Do not traverse comment nodes |
| 184 | ret += jQuery.text( node ); |
| 185 | } |
| 186 | } else if ( nodeType === 1 || nodeType === 9 || nodeType === 11 ) { |
| 187 | |
| 188 | // Use textContent for elements |
| 189 | return elem.textContent; |
| 190 | } else if ( nodeType === 3 || nodeType === 4 ) { |
| 191 | return elem.nodeValue; |
| 192 | } |
| 193 | |
| 194 | // Do not include comment or processing instruction nodes |
| 195 | |
| 196 | return ret; |
| 197 | }, |
| 198 | contains: function( a, b ) { |
| 199 | var adown = a.nodeType === 9 ? a.documentElement : a, |
| 200 | bup = b && b.parentNode; |
| 201 | return a === bup || !!( bup && bup.nodeType === 1 && adown.contains( bup ) ); |
| 202 | }, |
| 203 | isXMLDoc: function( elem ) { |
Renovate bot | f591dcf | 2023-12-30 14:13:54 +0000 | [diff] [blame] | 204 | var namespace = elem.namespaceURI, |
| 205 | documentElement = ( elem.ownerDocument || elem ).documentElement; |
Copybara bot | be50d49 | 2023-11-30 00:16:42 +0100 | [diff] [blame] | 206 | |
Renovate bot | f591dcf | 2023-12-30 14:13:54 +0000 | [diff] [blame] | 207 | // Assume HTML when documentElement doesn't yet exist, such as inside |
| 208 | // document fragments. |
| 209 | return !rhtmlSuffix.test( namespace || |
| 210 | documentElement && documentElement.nodeName || |
| 211 | "HTML" ); |
Copybara bot | be50d49 | 2023-11-30 00:16:42 +0100 | [diff] [blame] | 212 | }, |
| 213 | expr: { |
| 214 | attrHandle: {}, |
| 215 | match: { |
| 216 | bool: new RegExp( "^(?:checked|selected|async|autofocus|autoplay|controls|defer" + |
| 217 | "|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped)$", "i" ), |
| 218 | needsContext: /^[\x20\t\r\n\f]*[>+~]/ |
| 219 | } |
| 220 | } |
| 221 | } ); |
| 222 | |
| 223 | jQuery.extend( jQuery.find, { |
| 224 | matches: function( expr, elements ) { |
| 225 | return jQuery.find( expr, null, null, elements ); |
| 226 | }, |
| 227 | matchesSelector: function( elem, expr ) { |
| 228 | return matches.call( elem, expr ); |
| 229 | }, |
| 230 | attr: function( elem, name ) { |
| 231 | var fn = jQuery.expr.attrHandle[ name.toLowerCase() ], |
| 232 | |
| 233 | // Don't get fooled by Object.prototype properties (jQuery #13807) |
| 234 | value = fn && hasOwn.call( jQuery.expr.attrHandle, name.toLowerCase() ) ? |
| 235 | fn( elem, name, jQuery.isXMLDoc( elem ) ) : |
| 236 | undefined; |
| 237 | return value !== undefined ? value : elem.getAttribute( name ); |
| 238 | } |
| 239 | } ); |
| 240 | |
| 241 | } ); |