script.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. define( [
  2. "../core",
  3. "../var/document",
  4. "../ajax"
  5. ], function( jQuery, document ) {
  6. // Install script dataType
  7. jQuery.ajaxSetup( {
  8. accepts: {
  9. script: "text/javascript, application/javascript, " +
  10. "application/ecmascript, application/x-ecmascript"
  11. },
  12. contents: {
  13. script: /\b(?:java|ecma)script\b/
  14. },
  15. converters: {
  16. "text script": function( text ) {
  17. jQuery.globalEval( text );
  18. return text;
  19. }
  20. }
  21. } );
  22. // Handle cache's special case and crossDomain
  23. jQuery.ajaxPrefilter( "script", function( s ) {
  24. if ( s.cache === undefined ) {
  25. s.cache = false;
  26. }
  27. if ( s.crossDomain ) {
  28. s.type = "GET";
  29. }
  30. } );
  31. // Bind script tag hack transport
  32. jQuery.ajaxTransport( "script", function( s ) {
  33. // This transport only deals with cross domain requests
  34. if ( s.crossDomain ) {
  35. var script, callback;
  36. return {
  37. send: function( _, complete ) {
  38. script = jQuery( "<script>" ).prop( {
  39. charset: s.scriptCharset,
  40. src: s.url
  41. } ).on(
  42. "load error",
  43. callback = function( evt ) {
  44. script.remove();
  45. callback = null;
  46. if ( evt ) {
  47. complete( evt.type === "error" ? 404 : 200, evt.type );
  48. }
  49. }
  50. );
  51. // Use native DOM manipulation to avoid our domManip AJAX trickery
  52. document.head.appendChild( script[ 0 ] );
  53. },
  54. abort: function() {
  55. if ( callback ) {
  56. callback();
  57. }
  58. }
  59. };
  60. }
  61. } );
  62. } );