Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. "use strict";
  12. /**
  13. * Load a url into a page
  14. */
  15. jQuery.fn.load = function( url, params, callback ) {
  16. var selector, type, response,
  17. self = this,
  18. off = url.indexOf( " " );
  19. if ( off > -1 ) {
  20. selector = stripAndCollapse( url.slice( off ) );
  21. url = url.slice( 0, off );
  22. }
  23. // If it's a function
  24. if ( isFunction( params ) ) {
  25. // We assume that it's the callback
  26. callback = params;
  27. params = undefined;
  28. // Otherwise, build a param string
  29. } else if ( params && typeof params === "object" ) {
  30. type = "POST";
  31. }
  32. // If we have elements to modify, make the request
  33. if ( self.length > 0 ) {
  34. jQuery.ajax( {
  35. url: url,
  36. // If "type" variable is undefined, then "GET" method will be used.
  37. // Make value of this field explicit since
  38. // user can override it through ajaxSetup method
  39. type: type || "GET",
  40. dataType: "html",
  41. data: params
  42. } ).done( function( responseText ) {
  43. // Save response for use in complete callback
  44. response = arguments;
  45. self.html( selector ?
  46. // If a selector was specified, locate the right elements in a dummy div
  47. // Exclude scripts to avoid IE 'Permission Denied' errors
  48. jQuery( "<div>" ).append( jQuery.parseHTML( responseText ) ).find( selector ) :
  49. // Otherwise use the full result
  50. responseText );
  51. // If the request succeeds, this function gets "data", "status", "jqXHR"
  52. // but they are ignored because response was set above.
  53. // If it fails, this function gets "jqXHR", "status", "error"
  54. } ).always( callback && function( jqXHR, status ) {
  55. self.each( function() {
  56. callback.apply( this, response || [ jqXHR.responseText, status, jqXHR ] );
  57. } );
  58. } );
  59. }
  60. return this;
  61. };
  62. } );