diff options
author | Michał Gołębiowski-Owczarek <m.goleb@gmail.com> | 2019-07-29 21:14:46 +0200 |
---|---|---|
committer | Michał Gołębiowski-Owczarek <m.goleb@gmail.com> | 2019-07-29 21:19:21 +0200 |
commit | 47835965bd100a3661d8299d8b769ceeb8b6ce48 (patch) | |
tree | 5ef322bc48cd27d5a5f004e6e3fcf955c67fc9eb /src/selector-native.js | |
parent | 79b74e043a4ee737d44a95094ff1184e40bd5b16 (diff) | |
download | jquery-47835965bd100a3661d8299d8b769ceeb8b6ce48.tar.gz jquery-47835965bd100a3661d8299d8b769ceeb8b6ce48.zip |
Selector: Inline Sizzle into the selector module
This commit removes Sizzle from jQuery, inlining its code & removing obsolete
workarounds where applicable.
The selector-native module has been removed. Further work on the selector
module may decrease the size enough that it will no longer be necessary. If
it turns out it's still useful, we'll reinstate it but the code will look
different anyway as we'll want to share as much code as possible with
the existing selector module.
The Sizzle AUTHORS.txt file has been merged with the jQuery one - people are
sorted by their first contributions to either of the two repositories.
The commit reduces the gzipped jQuery size by 1460 bytes compared to master.
Closes gh-4395
Diffstat (limited to 'src/selector-native.js')
-rw-r--r-- | src/selector-native.js | 240 |
1 files changed, 0 insertions, 240 deletions
diff --git a/src/selector-native.js b/src/selector-native.js deleted file mode 100644 index 511d85d03..000000000 --- a/src/selector-native.js +++ /dev/null @@ -1,240 +0,0 @@ -define( [ - "./core", - "./var/document", - "./var/documentElement", - "./var/hasOwn", - "./var/indexOf" -], function( jQuery, document, documentElement, hasOwn, indexOf ) { - -"use strict"; - -/* - * Optional (non-Sizzle) selector module for custom builds. - * - * Note that this DOES NOT SUPPORT many documented jQuery - * features in exchange for its smaller size: - * - * Attribute not equal selector - * Positional selectors (:first; :eq(n); :odd; etc.) - * Type selectors (:input; :checkbox; :button; etc.) - * State-based selectors (:animated; :visible; :hidden; etc.) - * :has(selector) - * :not(complex selector) - * custom selectors via Sizzle extensions - * Leading combinators (e.g., $collection.find("> *")) - * Reliable functionality on XML fragments - * Requiring all parts of a selector to match elements under context - * (e.g., $div.find("div > *") now matches children of $div) - * Matching against non-elements - * Reliable sorting of disconnected nodes - * querySelectorAll bug fixes (e.g., unreliable :focus on WebKit) - * - * If any of these are unacceptable tradeoffs, either use Sizzle or - * customize this stub for the project's specific needs. - */ - -var hasDuplicate, sortInput, - rhtmlSuffix = /HTML$/i, - sortStable = jQuery.expando.split( "" ).sort( sortOrder ).join( "" ) === jQuery.expando, - - // Support: IE 9 - 11+ - // IE requires a prefix. - matches = documentElement.matches || documentElement.msMatchesSelector, - - // CSS string/identifier serialization - // https://drafts.csswg.org/cssom/#common-serializing-idioms - rcssescape = /([\0-\x1f\x7f]|^-?\d)|^-$|[^\x80-\uFFFF\w-]/g, - fcssescape = function( ch, asCodePoint ) { - if ( asCodePoint ) { - - // U+0000 NULL becomes U+FFFD REPLACEMENT CHARACTER - if ( ch === "\0" ) { - return "\uFFFD"; - } - - // Control characters and (dependent upon position) numbers get escaped as code points - return ch.slice( 0, -1 ) + "\\" + ch.charCodeAt( ch.length - 1 ).toString( 16 ) + " "; - } - - // Other potentially-special ASCII characters get backslash-escaped - return "\\" + ch; - }; - -function sortOrder( a, b ) { - - // Flag for duplicate removal - if ( a === b ) { - hasDuplicate = true; - return 0; - } - - // Sort on method existence if only one input has compareDocumentPosition - var compare = !a.compareDocumentPosition - !b.compareDocumentPosition; - if ( compare ) { - return compare; - } - - // Calculate position if both inputs belong to the same document - compare = ( a.ownerDocument || a ) === ( b.ownerDocument || b ) ? - a.compareDocumentPosition( b ) : - - // Otherwise we know they are disconnected - 1; - - // Disconnected nodes - if ( compare & 1 ) { - - // Choose the first element that is related to our preferred document - if ( a === document || a.ownerDocument === document && - jQuery.contains( document, a ) ) { - return -1; - } - if ( b === document || b.ownerDocument === document && - jQuery.contains( document, b ) ) { - return 1; - } - - // Maintain original order - return sortInput ? - ( indexOf.call( sortInput, a ) - indexOf.call( sortInput, b ) ) : - 0; - } - - return compare & 4 ? -1 : 1; -} - -function uniqueSort( results ) { - var elem, - duplicates = [], - j = 0, - i = 0; - - hasDuplicate = false; - sortInput = !sortStable && results.slice( 0 ); - results.sort( sortOrder ); - - if ( hasDuplicate ) { - while ( ( elem = results[ i++ ] ) ) { - if ( elem === results[ i ] ) { - j = duplicates.push( i ); - } - } - while ( j-- ) { - results.splice( duplicates[ j ], 1 ); - } - } - - // Clear input after sorting to release objects - // See https://github.com/jquery/sizzle/pull/225 - sortInput = null; - - return results; -} - -function escape( sel ) { - return ( sel + "" ).replace( rcssescape, fcssescape ); -} - -jQuery.extend( { - uniqueSort: uniqueSort, - unique: uniqueSort, - escapeSelector: escape, - find: function( selector, context, results, seed ) { - var elem, nodeType, - i = 0; - - results = results || []; - context = context || document; - - // Same basic safeguard as Sizzle - if ( !selector || typeof selector !== "string" ) { - return results; - } - - // Early return if context is not an element or document - if ( ( nodeType = context.nodeType ) !== 1 && nodeType !== 9 ) { - return []; - } - - if ( seed ) { - while ( ( elem = seed[ i++ ] ) ) { - if ( jQuery.find.matchesSelector( elem, selector ) ) { - results.push( elem ); - } - } - } else { - jQuery.merge( results, context.querySelectorAll( selector ) ); - } - - return results; - }, - text: function( elem ) { - var node, - ret = "", - i = 0, - nodeType = elem.nodeType; - - if ( !nodeType ) { - - // If no nodeType, this is expected to be an array - while ( ( node = elem[ i++ ] ) ) { - - // Do not traverse comment nodes - ret += jQuery.text( node ); - } - } else if ( nodeType === 1 || nodeType === 9 || nodeType === 11 ) { - - // Use textContent for elements - return elem.textContent; - } else if ( nodeType === 3 || nodeType === 4 ) { - return elem.nodeValue; - } - - // Do not include comment or processing instruction nodes - - return ret; - }, - contains: function( a, b ) { - var adown = a.nodeType === 9 ? a.documentElement : a, - bup = b && b.parentNode; - return a === bup || !!( bup && bup.nodeType === 1 && adown.contains( bup ) ); - }, - isXMLDoc: function( elem ) { - var namespace = elem.namespaceURI, - documentElement = ( elem.ownerDocument || elem ).documentElement; - - // Assume HTML when documentElement doesn't yet exist, such as inside - // document fragments. - return !rhtmlSuffix.test( namespace || - documentElement && documentElement.nodeName || - "HTML" ); - }, - expr: { - attrHandle: {}, - match: { - bool: new RegExp( "^(?:checked|selected|async|autofocus|autoplay|controls|defer" + - "|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped)$", "i" ), - needsContext: /^[\x20\t\r\n\f]*[>+~]/ - } - } -} ); - -jQuery.extend( jQuery.find, { - matches: function( expr, elements ) { - return jQuery.find( expr, null, null, elements ); - }, - matchesSelector: function( elem, expr ) { - return matches.call( elem, expr ); - }, - attr: function( elem, name ) { - var fn = jQuery.expr.attrHandle[ name.toLowerCase() ], - - // Don't get fooled by Object.prototype properties (jQuery #13807) - value = fn && hasOwn.call( jQuery.expr.attrHandle, name.toLowerCase() ) ? - fn( elem, name, jQuery.isXMLDoc( elem ) ) : - undefined; - return value !== undefined ? value : elem.getAttribute( name ); - } -} ); - -} ); |