Policy 1707 commit to LF
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / libs / bower_components / jquery / src / ajax / load.js
1 define([
2         "../core",
3         "../core/parseHTML",
4         "../ajax",
5         "../traversing",
6         "../manipulation",
7         "../selector",
8         // Optional event/alias dependency
9         "../event/alias"
10 ], function( jQuery ) {
11
12 // Keep a copy of the old load method
13 var _load = jQuery.fn.load;
14
15 /**
16  * Load a url into a page
17  */
18 jQuery.fn.load = function( url, params, callback ) {
19         if ( typeof url !== "string" && _load ) {
20                 return _load.apply( this, arguments );
21         }
22
23         var selector, type, response,
24                 self = this,
25                 off = url.indexOf(" ");
26
27         if ( off >= 0 ) {
28                 selector = jQuery.trim( url.slice( off ) );
29                 url = url.slice( 0, off );
30         }
31
32         // If it's a function
33         if ( jQuery.isFunction( params ) ) {
34
35                 // We assume that it's the callback
36                 callback = params;
37                 params = undefined;
38
39         // Otherwise, build a param string
40         } else if ( params && typeof params === "object" ) {
41                 type = "POST";
42         }
43
44         // If we have elements to modify, make the request
45         if ( self.length > 0 ) {
46                 jQuery.ajax({
47                         url: url,
48
49                         // if "type" variable is undefined, then "GET" method will be used
50                         type: type,
51                         dataType: "html",
52                         data: params
53                 }).done(function( responseText ) {
54
55                         // Save response for use in complete callback
56                         response = arguments;
57
58                         self.html( selector ?
59
60                                 // If a selector was specified, locate the right elements in a dummy div
61                                 // Exclude scripts to avoid IE 'Permission Denied' errors
62                                 jQuery("<div>").append( jQuery.parseHTML( responseText ) ).find( selector ) :
63
64                                 // Otherwise use the full result
65                                 responseText );
66
67                 }).complete( callback && function( jqXHR, status ) {
68                         self.each( callback, response || [ jqXHR.responseText, status, jqXHR ] );
69                 });
70         }
71
72         return this;
73 };
74
75 });