|

楼主 |
发表于 2016-12-2 11:22:28
|
显示全部楼层
define(function(require) {
var $ = require("jquery");
var Util = require("$UI/system/components/justep/common/designer/common");
var xuiService = require("$UI/system/components/designerCommon/js/xuiService");
var xuiDoc = xuiService.getXuiDoc();
var Button = require("../Myb");
require('css!./css/button').load();
var _Button = Button.extend({
init : function(value, bindingContext) {
var $domNode = $(this.domNode);
this.callParent(value, bindingContext);
var cfg = Util.attr2js($domNode, [ 'label', 'icon', 'image' ]);
if (cfg)
this.set(cfg);
var onclick = xuiDoc.get(this,'onClick');
if (onclick && 0 < onclick.indexOf('operation')) {
// 操作感知
this.on('onClick', onclick);
}
$domNode.removeAttr('onclick').off('click');
this._d_inited_ = true;
this._getLabelNode().attr('d_selectable', false).attr("d_canRemove", false).attr("d_canAddChild", false);
this._getIconNode().attr('d_selectable', false).attr("d_canRemove", false).attr("d_canAddChild", false);
this._getImgNode().attr('d_selectable', false).attr("d_canRemove", false).attr("d_canAddChild", false);
},
bindOperation : function(data) {
if (data && data.eventName)
this.on(data.eventName, data.value);
},
_getImgUrl : function(icon) {// "icon-refresh"/"img:xxx.png|xxx.png"
if (typeof (icon) === 'string' && 0 === icon.indexOf('img:')) {
var ipos = icon.indexOf('|');
if(!this.disabled || ipos < 0){
if (ipos < 0)
ipos = icon.length;
return icon.slice(4, ipos);
}else return icon.slice(ipos);
}
},
propertyChangedHandler : function(key, oldVal, value) {
var $img,$icon,url,newImg;
switch (key) {
case "label":
this.callParent(key, oldVal, value);
if (this._d_inited_)
xuiDoc.updateText(this._getLabelNode());
break;
case "disabled":
if (this.$domNode) {
if (this.isImgIcon) {
$img = this._getImgNode();
$icon = this._getIconNode();
$icon.removeAttr('class');
xuiDoc.updateProperties($icon, [ 'class' ]);
newImg = false;
if ($img.size() <= 0){
newImg = true;
this._getLabelNode().before('<img d_selectable="false" d_canRemove="false"/>');
}
$img = this._getImgNode();
//这个逻辑是为了同步设计时模型,同步后在刷新设计器显示,特殊处理
url = this._getImgUrl(value);
$img.attr('src', url?url:'');
if(newImg) xuiDoc.updateNodes($img);
else xuiDoc.updateProperties($img, ['src']);
//这是为了在设计器正常显示
$img.attr('src', this.imgIcon[this.disabled ? 1 : 0]);
}
}
break;
case "icon":
if (oldVal != value) {
this._setIcon(this.icon || this.opIcon);
if (this.$domNode) {
if (!this.isImgIcon) {
$icon = this._getIconNode();
if (oldVal)
$icon.removeClass(oldVal);
if (this.opIcon)
$icon.removeClass(this.opIcon);
if (value)
$icon.addClass(this.icon || this.opIcon);
xuiDoc.updateProperties($icon, [ 'class' ]);
$img = this._getImgNode();
if ($img.size() > 0) {
xuiDoc.deleteComponent([ $img.attr('d_id') ]);
$img.remove();
}
} else {
$img = this._getImgNode();
if (value) {
$icon = this._getIconNode();
$icon.removeAttr('class');
xuiDoc.updateProperties($icon, [ 'class' ]);
newImg = false;
if ($img.size() <= 0){
newImg = true;
this._getLabelNode().before('<img d_selectable="false" d_canRemove="false"/>');
}
$img = this._getImgNode();
//这个逻辑是为了同步设计时模型,同步后在刷新设计器显示,特殊处理
url = this._getImgUrl(value);
$img.attr('src', url?url:'');
if(newImg) xuiDoc.updateNodes($img);
else xuiDoc.updateProperties($img, ['src']);
//这是为了在设计器正常显示
$img.attr('src', this.imgIcon[this.disabled ? 1 : 0]);
}
}
}
}
break;
default:
this.callParent(key, oldVal, value);
}
}
});
return {
'$UI/system/components/justep/Myb/Myb' : _Button,
};
});
以上是mybtn.js里面的代码
init属性是新建时触发
propertyChangedHandler 这个就是控件的属性被修改的时候,比如说,你把空间的xid修改了,就会触发这个事件
最后的返回值一定要注意按这个标准写。
|
|