Merge "Add qtip job to pod zte-virtual6"
[releng.git] / utils / test / testapi / 3rd_party / static / testapi-ui / assets / lib / jquery / src / ajax / load.js
1 define( [
2         "../core",
3         "../core/stripAndCollapse",
4         "../core/parseHTML",
5         "../ajax",
6         "../traversing",
7         "../manipulation",
8         "../selector"
9 ], function( jQuery, stripAndCollapse ) {
10
11 "use strict";
12
13 /**
14  * Load a url into a page
15  */
16 jQuery.fn.load = function( url, params, callback ) {
17         var selector, type, response,
18                 self = this,
19                 off = url.indexOf( " " );
20
21         if ( off > -1 ) {
22                 selector = stripAndCollapse( url.slice( off ) );
23                 url = url.slice( 0, off );
24         }
25
26         // If it's a function
27         if ( jQuery.isFunction( params ) ) {
28
29                 // We assume that it's the callback
30                 callback = params;
31                 params = undefined;
32
33         // Otherwise, build a param string
34         } else if ( params && typeof params === "object" ) {
35                 type = "POST";
36         }
37
38         // If we have elements to modify, make the request
39         if ( self.length > 0 ) {
40                 jQuery.ajax( {
41                         url: url,
42
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
46                         type: type || "GET",
47                         dataType: "html",
48                         data: params
49                 } ).done( function( responseText ) {
50
51                         // Save response for use in complete callback
52                         response = arguments;
53
54                         self.html( selector ?
55
56                                 // If a selector was specified, locate the right elements in a dummy div
57                                 // Exclude scripts to avoid IE 'Permission Denied' errors
58                                 jQuery( "<div>" ).append( jQuery.parseHTML( responseText ) ).find( selector ) :
59
60                                 // Otherwise use the full result
61                                 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                 } ).always( callback && function( jqXHR, status ) {
67                         self.each( function() {
68                                 callback.apply( this, response || [ jqXHR.responseText, status, jqXHR ] );
69                         } );
70                 } );
71         }
72
73         return this;
74 };
75
76 } );