2016-09-26 09:28:47 +00:00
|
|
|
|
|
|
|
module.exports = new Class
|
2015-03-27 19:10:49 +00:00
|
|
|
({
|
|
|
|
Extends: Htk.Field
|
|
|
|
,Tag: 'htk-button'
|
|
|
|
,Properties:
|
|
|
|
{
|
|
|
|
image:
|
|
|
|
{
|
|
|
|
type: String
|
|
|
|
,set: function (x)
|
|
|
|
{
|
|
|
|
this.img.src = x;
|
|
|
|
}
|
2016-09-19 06:40:18 +00:00
|
|
|
},
|
2016-09-26 09:28:47 +00:00
|
|
|
icon:
|
2016-09-19 06:40:18 +00:00
|
|
|
{
|
|
|
|
type: String
|
|
|
|
,set: function (x)
|
|
|
|
{
|
|
|
|
this.img.src = 'image/icon/light/'+ x +'.svg';
|
|
|
|
}
|
2015-03-27 19:10:49 +00:00
|
|
|
},
|
2016-09-26 09:28:47 +00:00
|
|
|
tip:
|
2015-03-27 19:10:49 +00:00
|
|
|
{
|
|
|
|
type: String
|
|
|
|
,set: function (x)
|
|
|
|
{
|
|
|
|
if (x)
|
|
|
|
{
|
|
|
|
this.node.title = _(x);
|
|
|
|
this.img.title = _(x);
|
|
|
|
}
|
2015-09-16 16:11:15 +00:00
|
|
|
|
2016-10-16 14:16:08 +00:00
|
|
|
this.renderContent ();
|
2015-09-16 16:11:15 +00:00
|
|
|
}
|
|
|
|
,get: function ()
|
|
|
|
{
|
|
|
|
return this.node.title;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
showText:
|
|
|
|
{
|
|
|
|
type: Boolean
|
|
|
|
,set: function (x)
|
|
|
|
{
|
|
|
|
this._showText = x;
|
2016-10-16 14:16:08 +00:00
|
|
|
this.renderContent ();
|
2015-09-16 16:11:15 +00:00
|
|
|
}
|
|
|
|
,get: function ()
|
|
|
|
{
|
|
|
|
return this._showText;
|
2015-03-27 19:10:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-16 16:11:15 +00:00
|
|
|
,_showText: false
|
|
|
|
|
2016-10-16 14:16:08 +00:00
|
|
|
,render: function ()
|
2015-03-27 19:10:49 +00:00
|
|
|
{
|
2016-10-16 14:16:08 +00:00
|
|
|
var node = this.createRoot ('button');
|
|
|
|
node.className = 'htk-button';
|
2016-12-23 08:57:49 +00:00
|
|
|
node.addEventListener ('click', this._onClick.bind (this));
|
2015-11-09 08:14:33 +00:00
|
|
|
|
2016-10-16 14:16:08 +00:00
|
|
|
this.img = this.createElement ('img');
|
|
|
|
node.appendChild (this.img);
|
2015-03-27 19:10:49 +00:00
|
|
|
}
|
2015-09-16 16:11:15 +00:00
|
|
|
|
2016-10-16 14:16:08 +00:00
|
|
|
,renderContent: function ()
|
2015-09-16 16:11:15 +00:00
|
|
|
{
|
|
|
|
if (this._textNode)
|
|
|
|
Vn.Node.remove (this._textNode);
|
|
|
|
|
|
|
|
if (this._showText && this.node.title)
|
|
|
|
{
|
2016-10-16 14:16:08 +00:00
|
|
|
this._textNode = this.createElement ('span');
|
|
|
|
this._textNode.appendChild (this.createTextNode (this.node.title));
|
2015-09-16 16:11:15 +00:00
|
|
|
this.node.appendChild (this._textNode);
|
|
|
|
}
|
|
|
|
}
|
2015-03-27 19:10:49 +00:00
|
|
|
|
2016-12-23 08:57:49 +00:00
|
|
|
,_onClick: function (event)
|
2015-03-27 19:10:49 +00:00
|
|
|
{
|
2016-12-23 08:57:49 +00:00
|
|
|
event.preventDefault ();
|
2017-04-19 06:16:37 +00:00
|
|
|
this.emit ('click', this._form, event);
|
2015-03-27 19:10:49 +00:00
|
|
|
}
|
|
|
|
});
|