( selector, context, results, seed )
| 1158 | ); |
| 1159 | |
| 1160 | function find( selector, context, results, seed ) { |
| 1161 | var m, i, elem, nid, match, groups, newSelector, |
| 1162 | newContext = context && context.ownerDocument, |
| 1163 | |
| 1164 | // nodeType defaults to 9, since context defaults to document |
| 1165 | nodeType = context ? context.nodeType : 9; |
| 1166 | |
| 1167 | results = results || []; |
| 1168 | |
| 1169 | // Return early from calls with invalid selector or context |
| 1170 | if ( typeof selector !== "string" || !selector || |
| 1171 | nodeType !== 1 && nodeType !== 9 && nodeType !== 11 ) { |
| 1172 | |
| 1173 | return results; |
| 1174 | } |
| 1175 | |
| 1176 | // Try to shortcut find operations (as opposed to filters) in HTML documents |
| 1177 | if ( !seed ) { |
| 1178 | setDocument( context ); |
| 1179 | context = context || document; |
| 1180 | |
| 1181 | if ( documentIsHTML ) { |
| 1182 | |
| 1183 | // If the selector is sufficiently simple, try using a "get*By*" DOM method |
| 1184 | // (excepting DocumentFragment context, where the methods don't exist) |
| 1185 | if ( nodeType !== 11 && ( match = rquickExpr$1.exec( selector ) ) ) { |
| 1186 | |
| 1187 | // ID selector |
| 1188 | if ( ( m = match[ 1 ] ) ) { |
| 1189 | |
| 1190 | // Document context |
| 1191 | if ( nodeType === 9 ) { |
| 1192 | if ( ( elem = context.getElementById( m ) ) ) { |
| 1193 | push.call( results, elem ); |
| 1194 | } |
| 1195 | return results; |
| 1196 | |
| 1197 | // Element context |
| 1198 | } else { |
| 1199 | if ( newContext && ( elem = newContext.getElementById( m ) ) && |
| 1200 | jQuery.contains( context, elem ) ) { |
| 1201 | |
| 1202 | push.call( results, elem ); |
| 1203 | return results; |
| 1204 | } |
| 1205 | } |
| 1206 | |
| 1207 | // Type selector |
| 1208 | } else if ( match[ 2 ] ) { |
| 1209 | push.apply( results, context.getElementsByTagName( selector ) ); |
| 1210 | return results; |
| 1211 | |
| 1212 | // Class selector |
| 1213 | } else if ( ( m = match[ 3 ] ) && context.getElementsByClassName ) { |
| 1214 | push.apply( results, context.getElementsByClassName( m ) ); |
| 1215 | return results; |
| 1216 | } |
| 1217 | } |
no test coverage detected