script.js 1.5 KB

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