init.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /**
  2. * 动态加载初始资源
  3. */
  4. ;(function() {
  5. var resList = {
  6. icon: window.SITE_CONFIG.cdnUrl + '/static/img/favicon.ico',
  7. css: [
  8. window.SITE_CONFIG.cdnUrl + '/static/css/app.css',
  9. ],
  10. js: [
  11. // 插件, 放置业务之前加载, 以免业务需求依赖插件时, 还未加载出错
  12. // 插件 - echarts
  13. // 'https://cdn.bootcss.com/echarts/4.2.1/echarts.common.min.js',
  14. // 插件 - tinymce
  15. 'https://cdn.bootcss.com/tinymce/4.9.4/tinymce.min.js',
  16. window.SITE_CONFIG.cdnUrl + '/static/plugins/tinymce.4.9.4/zh_CN.js',
  17. // 业务
  18. window.SITE_CONFIG.cdnUrl + '/static/js/manifest.js',
  19. window.SITE_CONFIG.cdnUrl + '/static/js/vendor.js',
  20. window.SITE_CONFIG.cdnUrl + '/static/js/app.js'
  21. ]
  22. };
  23. // 图标
  24. (function () {
  25. var _icon = document.createElement('link');
  26. _icon.setAttribute('rel', 'shortcut icon');
  27. _icon.setAttribute('type', 'image/x-icon');
  28. _icon.setAttribute('href', resList.icon);
  29. document.getElementsByTagName('head')[0].appendChild(_icon);
  30. })();
  31. // 样式
  32. (function () {
  33. document.getElementsByTagName('html')[0].style.opacity = 0;
  34. var i = 0;
  35. var _style = null;
  36. var createStyles = function () {
  37. if (i >= resList.css.length) {
  38. document.getElementsByTagName('html')[0].style.opacity = 1;
  39. return;
  40. }
  41. _style = document.createElement('link');
  42. _style.href = resList.css[i];
  43. _style.setAttribute('rel', 'stylesheet');
  44. _style.onload = function () {
  45. i++;
  46. createStyles();
  47. }
  48. document.getElementsByTagName('head')[0].appendChild(_style);
  49. }
  50. createStyles();
  51. })();
  52. // 脚本
  53. document.onreadystatechange = function () {
  54. if (document.readyState === 'interactive') {
  55. var i = 0;
  56. var _script = null;
  57. var createScripts = function () {
  58. if (i >= resList.js.length) {
  59. return;
  60. }
  61. _script = document.createElement('script');
  62. _script.src = resList.js[i];
  63. _script.onload = function () {
  64. i++;
  65. createScripts();
  66. }
  67. document.getElementsByTagName('body')[0].appendChild(_script);
  68. }
  69. createScripts();
  70. }
  71. };
  72. })();