1 /** 2 * @fileOverview UIBase.Box 3 * @author yiminghe@gmail.com 4 */ 5 KISSY.add('component/uibase/box', function (S) { 6 7 /** 8 * @name Box 9 * @memberOf Component.UIBase 10 * @class 11 * Box extension class. 12 * Represent a dom element. 13 */ 14 function Box() { 15 } 16 17 Box.ATTRS = 18 /** 19 * @lends Component.UIBase.Box.prototype 20 */ 21 { 22 /** 23 * component's html content. 24 * Note: content and srcNode can not be set both! 25 * @type String|NodeList 26 */ 27 content:{ 28 view:1, 29 sync:false 30 }, 31 /** 32 * component's width 33 * @type Number|String 34 */ 35 width:{ 36 // 没有 _uiSetWidth,所以不需要设置 sync:false 37 view:1, 38 sync:false 39 }, 40 /** 41 * component's height 42 * @type Number|String 43 */ 44 height:{ 45 sync:false, 46 view:1 47 }, 48 /** 49 * css class of component's root element 50 * @type String 51 */ 52 elCls:{ 53 sync:false, 54 view:1 55 }, 56 /** 57 * name-value pair css style of component's root element 58 * @type Object 59 */ 60 elStyle:{ 61 sync:false, 62 view:1 63 }, 64 /** 65 * name-value pair attribute of component's root element 66 * @type Object 67 */ 68 elAttrs:{ 69 sync:false, 70 view:1 71 }, 72 /** 73 * archor element where component insert before 74 * @type NodeList 75 */ 76 elBefore:{ 77 sync:false, 78 view:1 79 }, 80 /** 81 * readonly. root element of current component 82 * @type NodeList 83 */ 84 el:{ 85 view:1 86 }, 87 88 /** 89 * archor element where component append to 90 * @type NodeList 91 */ 92 render:{ 93 view:1 94 }, 95 96 /** 97 * component's visibleMode,use css "display" or "visibility" to show this component 98 * @type String 99 */ 100 visibleMode:{ 101 view:1 102 }, 103 104 /** 105 * whether this component is visible 106 * @type Boolean 107 */ 108 visible:{ 109 view:1 110 }, 111 112 /** 113 * the node to parse for configuration values,passed to component's HTML_PARSER definition 114 * @type NodeList 115 */ 116 srcNode:{ 117 view:1 118 } 119 }; 120 121 122 Box.HTML_PARSER = 123 /** 124 * @private 125 */ 126 { 127 el:function (srcNode) { 128 /** 129 * 如果需要特殊的对现有元素的装饰行为 130 */ 131 var self = this; 132 if (self.decorateInternal) { 133 self.decorateInternal(S.one(srcNode)); 134 } 135 return srcNode; 136 } 137 }; 138 139 Box.prototype = 140 /** 141 * @lends Component.UIBase.Box# 142 */ 143 { 144 /** 145 * @private 146 */ 147 _uiSetVisible:function (isVisible) { 148 this.fire(isVisible ? "show" : "hide"); 149 }, 150 151 /** 152 * show component 153 */ 154 show:function () { 155 var self = this, view; 156 if (!self.get("rendered")) { 157 // 防止初始设置 false,导致触发 hide 事件 158 // show 里面的初始一定是 true,触发 show 事件 159 // 2012-03-28 : 用 set 而不是 __set : 160 // - 如果 show 前调用了 hide 和 create,view 已经根据 false 建立起来了 161 // - 也要设置 view 162 // self.set("visible", true); 163 // 2012-06-07 ,不能 set 164 // 初始监听 visible ,得不到 el 165 166 // 2012-06-12 167 // 复位 undefined,防止之前设置过 168 self.__set("visible", undefined); 169 if (view = self.get("view")) { 170 view.__set("visible", undefined); 171 } 172 self.render(); 173 } 174 self.set("visible", true); 175 return self; 176 }, 177 178 /** 179 * hide component 180 */ 181 hide:function () { 182 var self = this; 183 self.set("visible", false); 184 return self; 185 } 186 }; 187 188 return Box; 189 }); 190