| 1 | define( [
|
| 2 | "../core",
|
| 3 | "../core/stripAndCollapse",
|
| 4 | "../var/isFunction",
|
| 5 | "../core/parseHTML",
|
| 6 | "../ajax",
|
| 7 | "../traversing",
|
| 8 | "../manipulation",
|
| 9 | "../selector"
|
| 10 | ], function( jQuery, stripAndCollapse, isFunction ) {
|
| 11 |
|
| 12 | "use strict";
|
| 13 |
|
| 14 | |
| 15 | |
| 16 |
|
| 17 | jQuery.fn.load = function( url, params, callback ) {
|
| 18 | var selector, type, response,
|
| 19 | self = this,
|
| 20 | off = url.indexOf( " " );
|
| 21 |
|
| 22 | if ( off > -1 ) {
|
| 23 | selector = stripAndCollapse( url.slice( off ) );
|
| 24 | url = url.slice( 0, off );
|
| 25 | }
|
| 26 |
|
| 27 |
|
| 28 | if ( isFunction( params ) ) {
|
| 29 |
|
| 30 |
|
| 31 | callback = params;
|
| 32 | params = undefined;
|
| 33 |
|
| 34 |
|
| 35 | } else if ( params && typeof params === "object" ) {
|
| 36 | type = "POST";
|
| 37 | }
|
| 38 |
|
| 39 |
|
| 40 | if ( self.length > 0 ) {
|
| 41 | jQuery.ajax( {
|
| 42 | url: url,
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 | type: type || "GET",
|
| 48 | dataType: "html",
|
| 49 | data: params
|
| 50 | } ).done( function( responseText ) {
|
| 51 |
|
| 52 |
|
| 53 | response = arguments;
|
| 54 |
|
| 55 | self.html( selector ?
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 | jQuery( "<div>" ).append( jQuery.parseHTML( responseText ) ).find( selector ) :
|
| 60 |
|
| 61 |
|
| 62 | responseText );
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 | } ).always( callback && function( jqXHR, status ) {
|
| 68 | self.each( function() {
|
| 69 | callback.apply( this, response || [ jqXHR.responseText, status, jqXHR ] );
|
| 70 | } );
|
| 71 | } );
|
| 72 | }
|
| 73 |
|
| 74 | return this;
|
| 75 | };
|
| 76 |
|
| 77 | } );
|