1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/dashboard-ui/bower_components/jquery/src/ajax/load.js

77 lines
1.8 KiB
JavaScript
Raw Normal View History

2016-01-09 13:36:35 -05:00
define( [
2015-06-26 11:53:49 -04:00
"../core",
2016-09-23 02:57:24 -04:00
"../core/stripAndCollapse",
2015-06-26 11:53:49 -04:00
"../core/parseHTML",
"../ajax",
"../traversing",
"../manipulation",
2016-06-11 11:55:39 -04:00
"../selector"
2016-09-23 02:57:24 -04:00
], function( jQuery, stripAndCollapse ) {
2015-06-26 11:53:49 -04:00
2016-06-11 11:55:39 -04:00
"use strict";
2015-06-26 11:53:49 -04:00
/**
* Load a url into a page
*/
jQuery.fn.load = function( url, params, callback ) {
var selector, type, response,
self = this,
2016-01-09 13:36:35 -05:00
off = url.indexOf( " " );
2015-06-26 11:53:49 -04:00
2016-01-09 13:36:35 -05:00
if ( off > -1 ) {
2016-09-23 02:57:24 -04:00
selector = stripAndCollapse( url.slice( off ) );
2015-06-26 11:53:49 -04:00
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 ) {
2016-01-09 13:36:35 -05:00
jQuery.ajax( {
2015-06-26 11:53:49 -04:00
url: url,
2016-01-09 13:36:35 -05:00
// 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",
2015-06-26 11:53:49 -04:00
dataType: "html",
data: params
2016-01-09 13:36:35 -05:00
} ).done( function( responseText ) {
2015-06-26 11:53:49 -04:00
// 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
2016-01-09 13:36:35 -05:00
jQuery( "<div>" ).append( jQuery.parseHTML( responseText ) ).find( selector ) :
2015-06-26 11:53:49 -04:00
// Otherwise use the full result
responseText );
2016-01-09 13:36:35 -05:00
// 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() {
2016-04-06 13:34:36 -04:00
callback.apply( this, response || [ jqXHR.responseText, status, jqXHR ] );
2016-01-09 13:36:35 -05:00
} );
} );
2015-06-26 11:53:49 -04:00
}
return this;
};
2016-01-09 13:36:35 -05:00
} );