2017-05-30 23:47:50 +02:00
|
|
|
/**
|
|
|
|
* @provides phuix-button-view
|
|
|
|
* @requires javelin-install
|
|
|
|
* javelin-dom
|
|
|
|
*/
|
|
|
|
JX.install('PHUIXButtonView', {
|
|
|
|
|
|
|
|
statics: {
|
|
|
|
BUTTONTYPE_DEFAULT: 'buttontype.default',
|
|
|
|
BUTTONTYPE_SIMPLE: 'buttontype.simple'
|
|
|
|
},
|
|
|
|
|
|
|
|
members: {
|
|
|
|
_node: null,
|
|
|
|
_textNode: null,
|
2018-08-17 19:53:28 +02:00
|
|
|
_auralNode: null,
|
2017-05-30 23:47:50 +02:00
|
|
|
|
|
|
|
_iconView: null,
|
|
|
|
_color: null,
|
2017-08-30 19:00:23 +02:00
|
|
|
_selected: null,
|
2017-05-30 23:47:50 +02:00
|
|
|
_buttonType: null,
|
|
|
|
|
|
|
|
setIcon: function(icon) {
|
|
|
|
this.getIconView().setIcon(icon);
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
getIconView: function() {
|
|
|
|
if (!this._iconView) {
|
|
|
|
this._iconView = new JX.PHUIXIconView();
|
|
|
|
this._redraw();
|
|
|
|
}
|
|
|
|
return this._iconView;
|
|
|
|
},
|
|
|
|
|
|
|
|
setColor: function(color) {
|
|
|
|
var node = this.getNode();
|
|
|
|
|
|
|
|
if (this._color) {
|
2017-06-05 22:14:34 +02:00
|
|
|
JX.DOM.alterClass(node, 'button-' + this._color, false);
|
2017-05-30 23:47:50 +02:00
|
|
|
}
|
|
|
|
this._color = color;
|
2017-06-05 22:14:34 +02:00
|
|
|
JX.DOM.alterClass(node, 'button-' + this._color, true);
|
2017-05-30 23:47:50 +02:00
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2017-08-30 19:00:23 +02:00
|
|
|
setSelected: function(selected) {
|
|
|
|
var node = this.getNode();
|
|
|
|
this._selected = selected;
|
|
|
|
JX.DOM.alterClass(node, 'selected', this._selected);
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2017-05-30 23:47:50 +02:00
|
|
|
setButtonType: function(button_type) {
|
|
|
|
var self = JX.PHUIXButtonView;
|
|
|
|
|
|
|
|
this._buttonType = button_type;
|
|
|
|
var node = this.getNode();
|
|
|
|
|
|
|
|
var is_simple = (this._buttonType == self.BUTTONTYPE_SIMPLE);
|
2017-06-05 22:14:34 +02:00
|
|
|
JX.DOM.alterClass(node, 'phui-button-simple', is_simple);
|
2017-05-30 23:47:50 +02:00
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
setText: function(text) {
|
|
|
|
JX.DOM.setContent(this._getTextNode(), text);
|
2017-06-03 15:21:45 +02:00
|
|
|
this._redraw();
|
2017-05-30 23:47:50 +02:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-08-17 19:53:28 +02:00
|
|
|
setAuralLabel: function(label) {
|
|
|
|
JX.DOM.setContent(this._getAuralNode(), label);
|
|
|
|
this._redraw();
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2017-05-30 23:47:50 +02:00
|
|
|
getNode: function() {
|
|
|
|
if (!this._node) {
|
|
|
|
var attrs = {
|
|
|
|
className: 'button'
|
|
|
|
};
|
|
|
|
|
|
|
|
this._node = JX.$N('button', attrs);
|
|
|
|
|
|
|
|
this._redraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
return this._node;
|
|
|
|
},
|
|
|
|
|
|
|
|
_getTextNode: function() {
|
|
|
|
if (!this._textNode) {
|
|
|
|
var attrs = {
|
|
|
|
className: 'phui-button-text'
|
|
|
|
};
|
|
|
|
|
|
|
|
this._textNode = JX.$N('div', attrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this._textNode;
|
|
|
|
},
|
|
|
|
|
2018-08-17 19:53:28 +02:00
|
|
|
_getAuralNode: function() {
|
|
|
|
if (!this._auralNode) {
|
|
|
|
var attrs = {
|
|
|
|
className: 'aural-only'
|
|
|
|
};
|
|
|
|
|
|
|
|
this._auralNode = JX.$N('span', attrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this._auralNode;
|
|
|
|
},
|
|
|
|
|
2017-05-30 23:47:50 +02:00
|
|
|
_redraw: function() {
|
|
|
|
var node = this.getNode();
|
|
|
|
|
2018-08-17 19:53:28 +02:00
|
|
|
var aural = this._auralNode;
|
2017-05-30 23:47:50 +02:00
|
|
|
var icon = this._iconView;
|
|
|
|
var text = this._textNode;
|
|
|
|
|
|
|
|
var content = [];
|
2018-08-17 19:53:28 +02:00
|
|
|
|
|
|
|
if (aural) {
|
|
|
|
content.push(aural);
|
|
|
|
}
|
|
|
|
|
2017-05-30 23:47:50 +02:00
|
|
|
if (icon) {
|
|
|
|
content.push(icon.getNode());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (text) {
|
|
|
|
content.push(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
JX.DOM.alterClass(node, 'has-icon', !!icon);
|
2017-05-31 22:11:15 +02:00
|
|
|
JX.DOM.alterClass(node, 'has-text', !!text);
|
2017-05-30 23:47:50 +02:00
|
|
|
JX.DOM.setContent(node, content);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|