(selector, context, results, seed)
| 810 | } |
| 811 | |
| 812 | function find(selector, context, results, seed) { |
| 813 | var m, |
| 814 | i, |
| 815 | elem, |
| 816 | nid, |
| 817 | match, |
| 818 | groups, |
| 819 | newSelector, |
| 820 | newContext = context && context.ownerDocument, |
| 821 | // nodeType defaults to 9, since context defaults to document |
| 822 | nodeType = context ? context.nodeType : 9; |
| 823 | |
| 824 | results = results || []; |
| 825 | |
| 826 | // Return early from calls with invalid selector or context |
| 827 | if ( |
| 828 | typeof selector !== 'string' || |
| 829 | !selector || |
| 830 | (nodeType !== 1 && nodeType !== 9 && nodeType !== 11) |
| 831 | ) { |
| 832 | return results; |
| 833 | } |
| 834 | |
| 835 | // Try to shortcut find operations (as opposed to filters) in HTML documents |
| 836 | if (!seed) { |
| 837 | setDocument(context); |
| 838 | context = context || document; |
| 839 | |
| 840 | if (documentIsHTML) { |
| 841 | // If the selector is sufficiently simple, try using a "get*By*" DOM method |
| 842 | // (excepting DocumentFragment context, where the methods don't exist) |
| 843 | if (nodeType !== 11 && (match = rquickExpr.exec(selector))) { |
| 844 | // ID selector |
| 845 | if ((m = match[1])) { |
| 846 | // Document context |
| 847 | if (nodeType === 9) { |
| 848 | if ((elem = context.getElementById(m))) { |
| 849 | // Support: IE 9 only |
| 850 | // getElementById can match elements by name instead of ID |
| 851 | if (elem.id === m) { |
| 852 | push.call(results, elem); |
| 853 | return results; |
| 854 | } |
| 855 | } else { |
| 856 | return results; |
| 857 | } |
| 858 | |
| 859 | // Element context |
| 860 | } else { |
| 861 | // Support: IE 9 only |
| 862 | // getElementById can match elements by name instead of ID |
| 863 | if ( |
| 864 | newContext && |
| 865 | (elem = newContext.getElementById(m)) && |
| 866 | find.contains(context, elem) && |
| 867 | elem.id === m |
| 868 | ) { |
| 869 | push.call(results, elem); |
no test coverage detected