1 |
|
2 | define([
|
3 | "../core",
|
4 | "./var/rsingleTag",
|
5 | "../traversing/findFilter"
|
6 | ], function( jQuery, rsingleTag ) {
|
7 |
|
8 |
|
9 | var rootjQuery,
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,
|
15 |
|
16 | init = jQuery.fn.init = function( selector, context ) {
|
17 | var match, elem;
|
18 |
|
19 |
|
20 | if ( !selector ) {
|
21 | return this;
|
22 | }
|
23 |
|
24 |
|
25 | if ( typeof selector === "string" ) {
|
26 | if ( selector[0] === "<" && selector[ selector.length - 1 ] === ">" && selector.length >= 3 ) {
|
27 |
|
28 | match = [ null, selector, null ];
|
29 |
|
30 | } else {
|
31 | match = rquickExpr.exec( selector );
|
32 | }
|
33 |
|
34 |
|
35 | if ( match && (match[1] || !context) ) {
|
36 |
|
37 |
|
38 | if ( match[1] ) {
|
39 | context = context instanceof jQuery ? context[0] : context;
|
40 |
|
41 |
|
42 |
|
43 | jQuery.merge( this, jQuery.parseHTML(
|
44 | match[1],
|
45 | context && context.nodeType ? context.ownerDocument || context : document,
|
46 | true
|
47 | ) );
|
48 |
|
49 |
|
50 | if ( rsingleTag.test( match[1] ) && jQuery.isPlainObject( context ) ) {
|
51 | for ( match in context ) {
|
52 |
|
53 | if ( jQuery.isFunction( this[ match ] ) ) {
|
54 | this[ match ]( context[ match ] );
|
55 |
|
56 |
|
57 | } else {
|
58 | this.attr( match, context[ match ] );
|
59 | }
|
60 | }
|
61 | }
|
62 |
|
63 | return this;
|
64 |
|
65 |
|
66 | } else {
|
67 | elem = document.getElementById( match[2] );
|
68 |
|
69 |
|
70 |
|
71 | if ( elem && elem.parentNode ) {
|
72 |
|
73 | this.length = 1;
|
74 | this[0] = elem;
|
75 | }
|
76 |
|
77 | this.context = document;
|
78 | this.selector = selector;
|
79 | return this;
|
80 | }
|
81 |
|
82 |
|
83 | } else if ( !context || context.jquery ) {
|
84 | return ( context || rootjQuery ).find( selector );
|
85 |
|
86 |
|
87 |
|
88 | } else {
|
89 | return this.constructor( context ).find( selector );
|
90 | }
|
91 |
|
92 |
|
93 | } else if ( selector.nodeType ) {
|
94 | this.context = this[0] = selector;
|
95 | this.length = 1;
|
96 | return this;
|
97 |
|
98 |
|
99 |
|
100 | } else if ( jQuery.isFunction( selector ) ) {
|
101 | return typeof rootjQuery.ready !== "undefined" ?
|
102 | rootjQuery.ready( selector ) :
|
103 |
|
104 | selector( jQuery );
|
105 | }
|
106 |
|
107 | if ( selector.selector !== undefined ) {
|
108 | this.selector = selector.selector;
|
109 | this.context = selector.context;
|
110 | }
|
111 |
|
112 | return jQuery.makeArray( selector, this );
|
113 | };
|
114 |
|
115 |
|
116 | init.prototype = jQuery.fn;
|
117 |
|
118 |
|
119 | rootjQuery = jQuery( document );
|
120 |
|
121 | return init;
|
122 |
|
123 | });
|