Blame view

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