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