1 /** 2 * @fileOverview setup data structure for kissy loader 3 * @author yiminghe@gmail.com,lifesinger@gmail.com 4 */ 5 (function (S) { 6 if (typeof require !== 'undefined') { 7 return; 8 } 9 10 /** 11 * @class KISSY Loader constructor 12 * This class should not be instantiated manually. 13 * @memberOf KISSY 14 */ 15 function Loader(SS) { 16 this.SS = SS; 17 /** 18 * @name KISSY.Loader#afterModAttached 19 * @description fired after a module is attached 20 * @event 21 * @param e 22 * @param {KISSY.Loader.Module} e.mod current module object 23 */ 24 } 25 26 KISSY.Loader = Loader; 27 28 /** 29 * @name Package 30 * @class KISSY Package constructor 31 * This class should not be instantiated manually. 32 * @memberOf KISSY.Loader 33 */ 34 function Package(cfg) { 35 S.mix(this, cfg); 36 } 37 38 S.augment(Package, 39 /** 40 * @lends KISSY.Loader.Package# 41 */ 42 { 43 /** 44 * Tag for package. 45 * @return {String} 46 */ 47 getTag:function () { 48 return this.tag || this.SS.Config.tag; 49 }, 50 51 /** 52 * Get package name. 53 * @return {String} 54 */ 55 getName:function () { 56 return this.name; 57 }, 58 59 /** 60 * Get package base. 61 * @return {String} 62 */ 63 getBase:function () { 64 return this.base || this.SS.Config.base; 65 }, 66 67 /** 68 * Whether is debug for this package. 69 * @return {Boolean} 70 */ 71 isDebug:function () { 72 var debug = this.debug; 73 return debug === undefined ? this.SS.Config.debug : debug; 74 }, 75 76 /** 77 * Get charset for package. 78 * @return {String} 79 */ 80 getCharset:function () { 81 return this.charset || this.SS.Config.charset; 82 }, 83 84 /** 85 * Whether modules are combined for this package. 86 * @return {Boolean} 87 */ 88 isCombine:function () { 89 var combine = this.combine; 90 return combine === undefined ? this.SS.Config.combine : combine; 91 } 92 }); 93 94 Loader.Package = Package; 95 96 97 /** 98 * @class KISSY Module constructor 99 * This class should not be instantiated manually. 100 * @memberOf KISSY.Loader 101 */ 102 function Module(cfg) { 103 S.mix(this, cfg); 104 } 105 106 S.augment(Module, 107 /** 108 * @lends KISSY.Loader.Module# 109 */ 110 { 111 /** 112 * Set the value of current module 113 * @param v value to be set 114 */ 115 setValue:function (v) { 116 this.value = v; 117 }, 118 119 /** 120 * Get the fullpath of current module if load dynamically 121 */ 122 getFullPath:function () { 123 var self = this, t; 124 return self.fullpath || (self.fullpath = 125 Loader.Utils.getMappedPath(self.SS, 126 self.packageInfo.getBase() + 127 self.path + 128 ((t = self.getTag()) ? ("?t=" + encodeURIComponent(t)) : ""))); 129 }, 130 131 /** 132 * Get the value of current module 133 */ 134 getValue:function () { 135 return this.value; 136 }, 137 138 /** 139 * Get the name of current module 140 * @returns {String} 141 */ 142 getName:function () { 143 return this.name; 144 }, 145 146 /** 147 * Get the packageInfo of current module 148 * @return {Object} 149 */ 150 getPackageInfo:function () { 151 return this.packageInfo; 152 }, 153 154 /** 155 * Get the tag of current module 156 * @return {String} 157 */ 158 getTag:function () { 159 return (this.tag || this.packageInfo.getTag()); 160 }, 161 162 /** 163 * Get the charset of current module 164 * @return {String} 165 */ 166 getCharset:function () { 167 return this.charset || this.packageInfo.getCharset(); 168 } 169 }); 170 171 Loader.Module = Module; 172 173 // 模块(mod)状态 174 Loader.STATUS = { 175 INIT:0, 176 LOADING:1, 177 LOADED:2, 178 ERROR:3, 179 ATTACHED:4 180 }; 181 })(KISSY);