1 /** 2 * @fileOverview decorate function for children render from markup 3 * @author yiminghe@gmail.com 4 */ 5 KISSY.add("component/decorateChildren", function (S, Manager) { 6 7 8 function DecorateChildren() { 9 10 } 11 12 S.augment(DecorateChildren, { 13 decorateInternal:function (el) { 14 var self = this; 15 // 不用 __set , 通知 view 更新 16 self.set("el", el); 17 self.decorateChildren(el); 18 }, 19 20 /** 21 * Get component's constructor from KISSY Node. 22 * @protected 23 * @param {NodeList} childNode Child component's root node. 24 */ 25 findUIConstructorByNode:function (childNode) { 26 var self = this, 27 cls = childNode.attr("class") || "", 28 prefixCls = self.get("prefixCls"); 29 // 过滤掉特定前缀 30 cls = cls.replace(new RegExp("\\b" + prefixCls, "ig"), ""); 31 var UI = Manager.getConstructorByXClass(cls); 32 if (!UI) { 33 S.log(childNode); 34 S.log("can not find ui " + cls + " from this markup"); 35 } 36 return UI; 37 }, 38 39 // 生成一个组件 40 decorateChildrenInternal:function (UI, c) { 41 var self=this; 42 self.addChild(new UI({ 43 srcNode:c, 44 prefixCls:self.get("prefixCls") 45 })); 46 }, 47 48 // container 需要在装饰时对儿子特殊处理,递归装饰 49 decorateChildren:function (el) { 50 var self = this, 51 children = el.children(); 52 children.each(function (c) { 53 var UI = self.findUIConstructorByNode(c); 54 self.decorateChildrenInternal(UI, c); 55 }); 56 } 57 }); 58 59 return DecorateChildren; 60 61 }, { 62 requires:['./manager'] 63 });