22 * @Date : 2021-01-07 23:18:20
33 * @Author : MemoryShadow
44 * @LastEditors : MemoryShadow
5- * @LastEditTime : 2021-01-08 00:32:33
5+ * @LastEditTime : 2021-01-08 01:19:04
66 * @Description : 用于处理依赖的Depend类
77 */
88
99/**
1010 * 将指定资源添加至加载队列中并加载,用于处理依赖
11- * @param {String } ResourcesURL 指定资源URL
11+ * @param {String } ResourcesURL 指定资源URL
1212 */
1313function Depend ( ResourcesURL ) {
1414 // 此资源的URL
@@ -17,6 +17,8 @@ function Depend(ResourcesURL) {
1717 this . ResourcesType ;
1818 // 此对象在公共队列中的位置
1919 this . thisObjectIndex ;
20+ // 节点对象
21+ this . NodeObj = undefined ;
2022
2123 /**
2224 * 解析当前URL的类型
@@ -27,25 +29,55 @@ function Depend(ResourcesURL) {
2729 return this . ResourcesType ;
2830 }
2931
32+ /**
33+ * 注册当前资源
34+ * @returns {HTMLElement } 已经成功注册的HTMLElement对象
35+ */
36+ this . RegisteredNode = function ( e ) {
37+ switch ( this . ResourcesType ) {
38+ case 'js' :
39+ let script = document . createElement ( "script" ) ;
40+ script . src = this . ResourcesURL ;
41+ this . NodeObj = document . head . appendChild ( script ) ;
42+ break ;
43+ case 'css' :
44+ let link = document . createElement ( "link" ) ;
45+ link . href = this . ResourcesURL ;
46+ link . type = "text/css" ;
47+ link . rel = "stylesheet" ;
48+ this . NodeObj = document . head . appendChild ( link ) ;
49+ break ;
50+
51+ default :
52+ console . error ( "暂不支持这个类型的资源" ) ;
53+ return undefined ;
54+ }
55+ // 记录当前的控制组件
56+ return this . NodeObj ;
57+ }
58+
3059 /**
3160 * 构造器
32- * @param {String } ResourcesURL 指定资源URL
61+ * @param {String } ResourcesURL 指定资源URL
3362 */
3463 this . constructor = function ( ResourcesURL ) {
64+ // 储存URL
3565 this . ResourcesURL = ResourcesURL ;
66+ // 自动推导资源类型
3667 this . ResourcesType = this . AnalysisResourcesType ( ) ;
68+ // 记录当前索引位置
3769 this . thisObjectIndex = Depend . ObjectList . length ;
3870 // 将自身添加至对象列
3971 Depend . ObjectList . push ( this ) ;
4072 }
4173
42- this . constructor ( ResourcesURL , ResourcesType ) ;
74+ this . constructor ( ResourcesURL ) ;
4375}
4476
4577/**
4678 * 索引
4779 * @param {int,String } Key 要用于索引的Key
48- * @return {ControlNode } 指定的控制对象
80+ * @return {Depend } 指定的控制对象
4981 */
5082Depend . indexOf = function ( Key ) {
5183 // 判断是数字还是字符串
@@ -69,16 +101,16 @@ Depend.indexOf = function (Key) {
69101/**
70102 * 获取指定节点的控制对象
71103 * @param {string } MainNodeID 指定要作为主节点的ID
72- * @return {ControlNode } 指定的控制对象
104+ * @return {Depend } 指定的控制对象
73105 */
74106Depend . valueOf = function ( index ) {
75107 // 检查是否存在重复的对象,如果有,就直接返回,没有的情况下才创建新对象
76- if ( ControlNode . indexOf ( index ) == undefined ) {
108+ if ( Depend . indexOf ( index ) == undefined ) {
77109 // 如果没有,就New新的值
78- return new ControlNode ( index ) ;
110+ return new Depend ( index ) ;
79111 } else {
80112 // 如果不为空,就返回指定的内容
81- return ControlNode . indexOf ( index ) ;
113+ return Depend . indexOf ( index ) ;
82114 }
83115}
84116
0 commit comments