You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
4.4 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-Loader'>/**
  19. </span> * @class Ext.Loader
  20. * @singleton
  21. * Simple class to help load JavaScript files on demand
  22. */
  23. Ext.Loader = Ext.apply({}, {
  24. <span id='Ext-Loader-method-load'> /**
  25. </span> * Loads a given set of .js files. Calls the callback function when all files have been loaded
  26. * Set preserveOrder to true to ensure non-parallel loading of files if load order is important
  27. * @param {Array} fileList Array of all files to load
  28. * @param {Function} callback Callback to call after all files have been loaded
  29. * @param {Object} scope The scope to call the callback in
  30. * @param {Boolean} preserveOrder True to make files load in serial, one after the other (defaults to false)
  31. */
  32. load: function(fileList, callback, scope, preserveOrder) {
  33. var scope = scope || this,
  34. head = document.getElementsByTagName(&quot;head&quot;)[0],
  35. fragment = document.createDocumentFragment(),
  36. numFiles = fileList.length,
  37. loadedFiles = 0,
  38. me = this;
  39. <span id='Ext-Loader-method-loadFileIndex'> /**
  40. </span> * Loads a particular file from the fileList by index. This is used when preserving order
  41. */
  42. var loadFileIndex = function(index) {
  43. head.appendChild(
  44. me.buildScriptTag(fileList[index], onFileLoaded)
  45. );
  46. };
  47. <span id='Ext-Loader-method-onFileLoaded'> /**
  48. </span> * Callback function which is called after each file has been loaded. This calls the callback
  49. * passed to load once the final file in the fileList has been loaded
  50. */
  51. var onFileLoaded = function() {
  52. loadedFiles ++;
  53. //if this was the last file, call the callback, otherwise load the next file
  54. if (numFiles == loadedFiles &amp;&amp; typeof callback == 'function') {
  55. callback.call(scope);
  56. } else {
  57. if (preserveOrder === true) {
  58. loadFileIndex(loadedFiles);
  59. }
  60. }
  61. };
  62. if (preserveOrder === true) {
  63. loadFileIndex.call(this, 0);
  64. } else {
  65. //load each file (most browsers will do this in parallel)
  66. Ext.each(fileList, function(file, index) {
  67. fragment.appendChild(
  68. this.buildScriptTag(file, onFileLoaded)
  69. );
  70. }, this);
  71. head.appendChild(fragment);
  72. }
  73. },
  74. <span id='Ext-Loader-method-buildScriptTag'> /**
  75. </span> * @private
  76. * Creates and returns a script tag, but does not place it into the document. If a callback function
  77. * is passed, this is called when the script has been loaded
  78. * @param {String} filename The name of the file to create a script tag for
  79. * @param {Function} callback Optional callback, which is called when the script has been loaded
  80. * @return {Element} The new script ta
  81. */
  82. buildScriptTag: function(filename, callback) {
  83. var script = document.createElement('script');
  84. script.type = &quot;text/javascript&quot;;
  85. script.src = filename;
  86. //IE has a different way of handling &amp;lt;script&amp;gt; loads, so we need to check for it here
  87. if (script.readyState) {
  88. script.onreadystatechange = function() {
  89. if (script.readyState == &quot;loaded&quot; || script.readyState == &quot;complete&quot;) {
  90. script.onreadystatechange = null;
  91. callback();
  92. }
  93. };
  94. } else {
  95. script.onload = callback;
  96. }
  97. return script;
  98. }
  99. });
  100. </pre>
  101. </body>
  102. </html>