电子档案
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.

93 lines
3.4 KiB

  1. /* Licensed under the Apache License, Version 2.0 (the "License");
  2. * you may not use this file except in compliance with the License.
  3. * You may obtain a copy of the License at
  4. *
  5. * http://www.apache.org/licenses/LICENSE-2.0
  6. *
  7. * Unless required by applicable law or agreed to in writing, software
  8. * distributed under the License is distributed on an "AS IS" BASIS,
  9. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. * See the License for the specific language governing permissions and
  11. * limitations under the License.
  12. */
  13. (function(resources){
  14. if (resources) {
  15. // Pause angular bootstrap so we have time to register and override angular services/directives etc
  16. window.name = 'NG_DEFER_BOOTSTRAP!';
  17. function load(res, node, callback, scope) {
  18. var resource;
  19. if (res.tag === 'script') {
  20. resource = document.createElement('script');
  21. resource.type = res.type || 'text/javascript';
  22. resource.src = res.src;
  23. if (callback) {
  24. var done = false;
  25. // Attach handlers for all browsers
  26. resource.onload = resource.onreadystatechange = function()
  27. {
  28. if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete"))
  29. {
  30. done = true;
  31. callback.call(scope ? scope : this, res);
  32. }
  33. };
  34. }
  35. }
  36. else if (res.tag === 'link') {
  37. resource = document.createElement('link');
  38. resource.rel = res.rel || 'stylesheet';
  39. resource.href = res.href;
  40. }
  41. if (node.nextSibling) {
  42. node.parentNode.insertBefore(resource, node.nextSibling);
  43. }
  44. else {
  45. node.parentNode.appendChild(resource);
  46. }
  47. if (res.tag === 'link' && callback) {
  48. callback.call(scope ? scope : this, res);
  49. }
  50. }
  51. function getResourceLoaderElement() {
  52. var scripts = document.getElementsByTagName('script');
  53. for (var i = 0, il = scripts.length; i < il; i++) {
  54. if (scripts[i].src.indexOf('scripts/resource-loader.js') != -1) {
  55. return scripts[i];
  56. }
  57. }
  58. return null;
  59. }
  60. var res = resources['*'];
  61. var resourceLoaderElement = getResourceLoaderElement();
  62. var appName = resourceLoaderElement.getAttribute('app');
  63. if (resources.hasOwnProperty(appName)) {
  64. res = resources[appName];
  65. }
  66. var loadedResources = 0;
  67. for (var i = 0, il = res.length; i < il; i++) {
  68. load(res[i], resourceLoaderElement, function(){
  69. loadedResources++;
  70. if (loadedResources == res.length) {
  71. // Let angular resume bootstrap
  72. var interval = window.setInterval(function(){
  73. if (angular && typeof angular.resumeBootstrap == 'function') {
  74. angular.resumeBootstrap();
  75. window.clearInterval(interval);
  76. }
  77. }, 20);
  78. }
  79. });
  80. }
  81. }
  82. })(FLOWABLE.CONFIG.resources);