Blame view

bower_components/jquery/src/ajax/load.js 1.63 KB
c5169e0e   Renato De Donato   a new hope
1
  define([
74249687   Luigi Serra   Cross browser con...
2
3
4
5
6
7
  	"../core",
  	"../core/parseHTML",
  	"../ajax",
  	"../traversing",
  	"../manipulation",
  	"../selector",
74249687   Luigi Serra   Cross browser con...
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  	// 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,
c5169e0e   Renato De Donato   a new hope
25
  		off = url.indexOf(" ");
74249687   Luigi Serra   Cross browser con...
26
  
c5169e0e   Renato De Donato   a new hope
27
  	if ( off >= 0 ) {
74249687   Luigi Serra   Cross browser con...
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
  		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 ) {
c5169e0e   Renato De Donato   a new hope
46
  		jQuery.ajax({
74249687   Luigi Serra   Cross browser con...
47
48
  			url: url,
  
c5169e0e   Renato De Donato   a new hope
49
50
  			// if "type" variable is undefined, then "GET" method will be used
  			type: type,
74249687   Luigi Serra   Cross browser con...
51
52
  			dataType: "html",
  			data: params
c5169e0e   Renato De Donato   a new hope
53
  		}).done(function( responseText ) {
74249687   Luigi Serra   Cross browser con...
54
55
56
57
58
59
60
61
  
  			// 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
c5169e0e   Renato De Donato   a new hope
62
  				jQuery("<div>").append( jQuery.parseHTML( responseText ) ).find( selector ) :
74249687   Luigi Serra   Cross browser con...
63
64
65
66
  
  				// Otherwise use the full result
  				responseText );
  
c5169e0e   Renato De Donato   a new hope
67
68
69
  		}).complete( callback && function( jqXHR, status ) {
  			self.each( callback, response || [ jqXHR.responseText, status, jqXHR ] );
  		});
74249687   Luigi Serra   Cross browser con...
70
71
72
73
74
  	}
  
  	return this;
  };
  
c5169e0e   Renato De Donato   a new hope
75
  });