You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

212 line
5.5KB

  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. * Optional (non-Sizzle) selector module for custom builds.
  10. *
  11. * Note that this DOES NOT SUPPORT many documented jQuery
  12. * features in exchange for its smaller size:
  13. *
  14. * Attribute not equal selector
  15. * Positional selectors (:first; :eq(n); :odd; etc.)
  16. * Type selectors (:input; :checkbox; :button; etc.)
  17. * State-based selectors (:animated; :visible; :hidden; etc.)
  18. * :has(selector)
  19. * :not(complex selector)
  20. * custom selectors via Sizzle extensions
  21. * Leading combinators (e.g., $collection.find("> *"))
  22. * Reliable functionality on XML fragments
  23. * Requiring all parts of a selector to match elements under context
  24. * (e.g., $div.find("div > *") now matches children of $div)
  25. * Matching against non-elements
  26. * Reliable sorting of disconnected nodes
  27. * querySelectorAll bug fixes (e.g., unreliable :focus on WebKit)
  28. *
  29. * If any of these are unacceptable tradeoffs, either use Sizzle or
  30. * customize this stub for the project's specific needs.
  31. */
  32. var hasDuplicate, sortInput,
  33. sortStable = jQuery.expando.split( "" ).sort( sortOrder ).join( "" ) === jQuery.expando,
  34. matches = documentElement.matches ||
  35. documentElement.webkitMatchesSelector ||
  36. documentElement.mozMatchesSelector ||
  37. documentElement.oMatchesSelector ||
  38. documentElement.msMatchesSelector;
  39. function sortOrder( a, b ) {
  40. // Flag for duplicate removal
  41. if ( a === b ) {
  42. hasDuplicate = true;
  43. return 0;
  44. }
  45. // Sort on method existence if only one input has compareDocumentPosition
  46. var compare = !a.compareDocumentPosition - !b.compareDocumentPosition;
  47. if ( compare ) {
  48. return compare;
  49. }
  50. // Calculate position if both inputs belong to the same document
  51. compare = ( a.ownerDocument || a ) === ( b.ownerDocument || b ) ?
  52. a.compareDocumentPosition( b ) :
  53. // Otherwise we know they are disconnected
  54. 1;
  55. // Disconnected nodes
  56. if ( compare & 1 ) {
  57. // Choose the first element that is related to our preferred document
  58. if ( a === document || a.ownerDocument === document &&
  59. jQuery.contains( document, a ) ) {
  60. return -1;
  61. }
  62. if ( b === document || b.ownerDocument === document &&
  63. jQuery.contains( document, b ) ) {
  64. return 1;
  65. }
  66. // Maintain original order
  67. return sortInput ?
  68. ( indexOf.call( sortInput, a ) - indexOf.call( sortInput, b ) ) :
  69. 0;
  70. }
  71. return compare & 4 ? -1 : 1;
  72. }
  73. function uniqueSort( results ) {
  74. var elem,
  75. duplicates = [],
  76. j = 0,
  77. i = 0;
  78. hasDuplicate = false;
  79. sortInput = !sortStable && results.slice( 0 );
  80. results.sort( sortOrder );
  81. if ( hasDuplicate ) {
  82. while ( ( elem = results[ i++ ] ) ) {
  83. if ( elem === results[ i ] ) {
  84. j = duplicates.push( i );
  85. }
  86. }
  87. while ( j-- ) {
  88. results.splice( duplicates[ j ], 1 );
  89. }
  90. }
  91. // Clear input after sorting to release objects
  92. // See https://github.com/jquery/sizzle/pull/225
  93. sortInput = null;
  94. return results;
  95. }
  96. jQuery.extend( {
  97. find: function( selector, context, results, seed ) {
  98. var elem, nodeType,
  99. i = 0;
  100. results = results || [];
  101. context = context || document;
  102. // Same basic safeguard as Sizzle
  103. if ( !selector || typeof selector !== "string" ) {
  104. return results;
  105. }
  106. // Early return if context is not an element or document
  107. if ( ( nodeType = context.nodeType ) !== 1 && nodeType !== 9 ) {
  108. return [];
  109. }
  110. if ( seed ) {
  111. while ( ( elem = seed[ i++ ] ) ) {
  112. if ( jQuery.find.matchesSelector( elem, selector ) ) {
  113. results.push( elem );
  114. }
  115. }
  116. } else {
  117. jQuery.merge( results, context.querySelectorAll( selector ) );
  118. }
  119. return results;
  120. },
  121. uniqueSort: uniqueSort,
  122. unique: uniqueSort,
  123. text: function( elem ) {
  124. var node,
  125. ret = "",
  126. i = 0,
  127. nodeType = elem.nodeType;
  128. if ( !nodeType ) {
  129. // If no nodeType, this is expected to be an array
  130. while ( ( node = elem[ i++ ] ) ) {
  131. // Do not traverse comment nodes
  132. ret += jQuery.text( node );
  133. }
  134. } else if ( nodeType === 1 || nodeType === 9 || nodeType === 11 ) {
  135. // Use textContent for elements
  136. return elem.textContent;
  137. } else if ( nodeType === 3 || nodeType === 4 ) {
  138. return elem.nodeValue;
  139. }
  140. // Do not include comment or processing instruction nodes
  141. return ret;
  142. },
  143. contains: function( a, b ) {
  144. var adown = a.nodeType === 9 ? a.documentElement : a,
  145. bup = b && b.parentNode;
  146. return a === bup || !!( bup && bup.nodeType === 1 && adown.contains( bup ) );
  147. },
  148. isXMLDoc: function( elem ) {
  149. // documentElement is verified for cases where it doesn't yet exist
  150. // (such as loading iframes in IE - #4833)
  151. var documentElement = elem && ( elem.ownerDocument || elem ).documentElement;
  152. return documentElement ? documentElement.nodeName !== "HTML" : false;
  153. },
  154. expr: {
  155. attrHandle: {},
  156. match: {
  157. bool: new RegExp( "^(?:checked|selected|async|autofocus|autoplay|controls|defer" +
  158. "|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped)$", "i" ),
  159. needsContext: /^[\x20\t\r\n\f]*[>+~]/
  160. }
  161. }
  162. } );
  163. jQuery.extend( jQuery.find, {
  164. matches: function( expr, elements ) {
  165. return jQuery.find( expr, null, null, elements );
  166. },
  167. matchesSelector: function( elem, expr ) {
  168. return matches.call( elem, expr );
  169. },
  170. attr: function( elem, name ) {
  171. var fn = jQuery.expr.attrHandle[ name.toLowerCase() ],
  172. // Don't get fooled by Object.prototype properties (jQuery #13807)
  173. value = fn && hasOwn.call( jQuery.expr.attrHandle, name.toLowerCase() ) ?
  174. fn( elem, name, jQuery.isXMLDoc( elem ) ) :
  175. undefined;
  176. return value !== undefined ? value : elem.getAttribute( name );
  177. }
  178. } );
  179. } );