script.js 1.2 KB

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