scratch – Blame information for rev 58

Subversion Repositories:
Rev:
Rev Author Line No. Line
58 office 1 // Initialize a jQuery object
2 define( [
3 "../core",
4 "../var/document",
5 "./var/rsingleTag",
6 "../traversing/findFilter"
7 ], function( jQuery, document, rsingleTag ) {
8  
9 "use strict";
10  
11 // A central reference to the root jQuery(document)
12 var rootjQuery,
13  
14 // A simple way to check for HTML strings
15 // Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
16 // Strict HTML recognition (#11290: must start with <)
17 // Shortcut simple #id case for speed
18 rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]+))$/,
19  
20 <[\w\W]+> init = jQuery.fn.init = function( selector, context, root ) {
21 <[\w\W]+> var match, elem;
22  
23 <[\w\W]+> // HANDLE: $(""), $(null), $(undefined), $(false)
24 <[\w\W]+> if ( !selector ) {
25 <[\w\W]+> return this;
26 <[\w\W]+> }
27  
28 <[\w\W]+> // Method init() accepts an alternate rootjQuery
29 <[\w\W]+> // so migrate can support jQuery.sub (gh-2101)
30 <[\w\W]+> root = root || rootjQuery;
31  
32 <[\w\W]+> // Handle HTML strings
33 <[\w\W]+> if ( typeof selector === "string" ) {
34 <[\w\W]+> if ( selector[ 0 ] === "<" &&
35 <[\w\W]+> selector[ selector.length - 1 ] === ">" &&
36 <[\w\W]+> selector.length >= 3 ) {
37  
38 <[\w\W]+> // Assume that strings that start and end with <> are HTML and skip the regex check
39 <[\w\W]+> match = [ null, selector, null ];
40  
41 <[\w\W]+> } else {
42 <[\w\W]+> match = rquickExpr.exec( selector );
43 <[\w\W]+> }
44  
45 <[\w\W]+> // Match html or make sure no context is specified for #id
46 <[\w\W]+> if ( match && ( match[ 1 ] || !context ) ) {
47  
48 <[\w\W]+> // HANDLE: $(html) -> $(array)
49 <[\w\W]+> if ( match[ 1 ] ) {
50 <[\w\W]+> context = context instanceof jQuery ? context[ 0 ] : context;
51  
52 <[\w\W]+> // Option to run scripts is true for back-compat
53 <[\w\W]+> // Intentionally let the error be thrown if parseHTML is not present
54 <[\w\W]+> jQuery.merge( this, jQuery.parseHTML(
55 <[\w\W]+> match[ 1 ],
56 <[\w\W]+> context && context.nodeType ? context.ownerDocument || context : document,
57 <[\w\W]+> true
58 <[\w\W]+> ) );
59  
60 <[\w\W]+> // HANDLE: $(html, props)
61 <[\w\W]+> if ( rsingleTag.test( match[ 1 ] ) && jQuery.isPlainObject( context ) ) {
62 <[\w\W]+> for ( match in context ) {
63  
64 <[\w\W]+> // Properties of context are called as methods if possible
65 <[\w\W]+> if ( jQuery.isFunction( this[ match ] ) ) {
66 <[\w\W]+> this[ match ]( context[ match ] );
67  
68 <[\w\W]+> // ...and otherwise set as attributes
69 <[\w\W]+> } else {
70 <[\w\W]+> this.attr( match, context[ match ] );
71 <[\w\W]+> }
72 <[\w\W]+> }
73 <[\w\W]+> }
74  
75 <[\w\W]+> return this;
76  
77 <[\w\W]+> // HANDLE: $(#id)
78 <[\w\W]+> } else {
79 <[\w\W]+> elem = document.getElementById( match[ 2 ] );
80  
81 <[\w\W]+> if ( elem ) {
82  
83 <[\w\W]+> // Inject the element directly into the jQuery object
84 <[\w\W]+> this[ 0 ] = elem;
85 <[\w\W]+> this.length = 1;
86 <[\w\W]+> }
87 <[\w\W]+> return this;
88 <[\w\W]+> }
89  
90 <[\w\W]+> // HANDLE: $(expr, $(...))
91 <[\w\W]+> } else if ( !context || context.jquery ) {
92 <[\w\W]+> return ( context || root ).find( selector );
93  
94 <[\w\W]+> // HANDLE: $(expr, context)
95 <[\w\W]+> // (which is just equivalent to: $(context).find(expr)
96 <[\w\W]+> } else {
97 <[\w\W]+> return this.constructor( context ).find( selector );
98 <[\w\W]+> }
99  
100 <[\w\W]+> // HANDLE: $(DOMElement)
101 <[\w\W]+> } else if ( selector.nodeType ) {
102 <[\w\W]+> this[ 0 ] = selector;
103 <[\w\W]+> this.length = 1;
104 <[\w\W]+> return this;
105  
106 <[\w\W]+> // HANDLE: $(function)
107 <[\w\W]+> // Shortcut for document ready
108 <[\w\W]+> } else if ( jQuery.isFunction( selector ) ) {
109 <[\w\W]+> return root.ready !== undefined ?
110 <[\w\W]+> root.ready( selector ) :
111  
112 <[\w\W]+> // Execute immediately if ready is not present
113 <[\w\W]+> selector( jQuery );
114 <[\w\W]+> }
115  
116 <[\w\W]+> return jQuery.makeArray( selector, this );
117 <[\w\W]+> };
118  
119 <[\w\W]+>// Give the init function the jQuery prototype for later instantiation
120 <[\w\W]+>init.prototype = jQuery.fn;
121  
122 <[\w\W]+>// Initialize central reference
123 <[\w\W]+>rootjQuery = jQuery( document );
124  
125 <[\w\W]+>return init;
126  
127 <[\w\W]+>} );