scratch – Diff between revs 58 and 125

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 58 Rev 125
1 define( [ 1 define([
2 "../core", 2 "../core",
3 "../core/stripAndCollapse", -  
4 "../core/parseHTML", 3 "../core/parseHTML",
5 "../ajax", 4 "../ajax",
6 "../traversing", 5 "../traversing",
7 "../manipulation", 6 "../manipulation",
8 "../selector" 7 "../selector",
-   8 // Optional event/alias dependency
-   9 "../event/alias"
9 ], function( jQuery, stripAndCollapse ) { 10 ], function( jQuery ) {
-   11  
10   12 // Keep a copy of the old load method
11 "use strict"; 13 var _load = jQuery.fn.load;
12   14  
13 /** 15 /**
14 * Load a url into a page 16 * Load a url into a page
15 */ 17 */
16 jQuery.fn.load = function( url, params, callback ) { 18 jQuery.fn.load = function( url, params, callback ) {
-   19 if ( typeof url !== "string" && _load ) {
-   20 return _load.apply( this, arguments );
-   21 }
-   22  
17 var selector, type, response, 23 var selector, type, response,
18 self = this, 24 self = this,
19 off = url.indexOf( " " ); 25 off = url.indexOf(" ");
20   26  
21 if ( off > -1 ) { 27 if ( off >= 0 ) {
22 selector = stripAndCollapse( url.slice( off ) ); 28 selector = jQuery.trim( url.slice( off ) );
23 url = url.slice( 0, off ); 29 url = url.slice( 0, off );
24 } 30 }
25   31  
26 // If it's a function 32 // If it's a function
27 if ( jQuery.isFunction( params ) ) { 33 if ( jQuery.isFunction( params ) ) {
28   34  
29 // We assume that it's the callback 35 // We assume that it's the callback
30 callback = params; 36 callback = params;
31 params = undefined; 37 params = undefined;
32   38  
33 // Otherwise, build a param string 39 // Otherwise, build a param string
34 } else if ( params && typeof params === "object" ) { 40 } else if ( params && typeof params === "object" ) {
35 type = "POST"; 41 type = "POST";
36 } 42 }
37   43  
38 // If we have elements to modify, make the request 44 // If we have elements to modify, make the request
39 if ( self.length > 0 ) { 45 if ( self.length > 0 ) {
40 jQuery.ajax( { 46 jQuery.ajax({
41 url: url, 47 url: url,
42   48  
43 // If "type" variable is undefined, then "GET" method will be used. -  
44 // Make value of this field explicit since -  
45 // user can override it through ajaxSetup method 49 // if "type" variable is undefined, then "GET" method will be used
46 type: type || "GET", 50 type: type,
47 dataType: "html", 51 dataType: "html",
48 data: params 52 data: params
49 } ).done( function( responseText ) { 53 }).done(function( responseText ) {
50   54  
51 // Save response for use in complete callback 55 // Save response for use in complete callback
52 response = arguments; 56 response = arguments;
53   57  
54 self.html( selector ? 58 self.html( selector ?
55   59  
56 // If a selector was specified, locate the right elements in a dummy div 60 // If a selector was specified, locate the right elements in a dummy div
57 // Exclude scripts to avoid IE 'Permission Denied' errors 61 // Exclude scripts to avoid IE 'Permission Denied' errors
58 jQuery( "<div>" ).append( jQuery.parseHTML( responseText ) ).find( selector ) : 62 jQuery("<div>").append( jQuery.parseHTML( responseText ) ).find( selector ) :
59   63  
60 // Otherwise use the full result 64 // Otherwise use the full result
61 responseText ); 65 responseText );
62   -  
63 // If the request succeeds, this function gets "data", "status", "jqXHR" -  
64 // but they are ignored because response was set above. -  
65 // If it fails, this function gets "jqXHR", "status", "error" 66  
66 } ).always( callback && function( jqXHR, status ) { -  
67 self.each( function() { 67 }).complete( callback && function( jqXHR, status ) {
68 callback.apply( this, response || [ jqXHR.responseText, status, jqXHR ] ); -  
69 } ); 68 self.each( callback, response || [ jqXHR.responseText, status, jqXHR ] );
70 } ); 69 });
71 } 70 }
72   71  
73 return this; 72 return this;
74 }; 73 };
75   74  
76 } ); 75 });
77   76