Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/webroot/rsrc/js/phuix/PHUIXButtonView.js
12241 views
1
/**
2
* @provides phuix-button-view
3
* @requires javelin-install
4
* javelin-dom
5
*/
6
JX.install('PHUIXButtonView', {
7
8
statics: {
9
BUTTONTYPE_DEFAULT: 'buttontype.default',
10
BUTTONTYPE_SIMPLE: 'buttontype.simple'
11
},
12
13
members: {
14
_node: null,
15
_textNode: null,
16
_auralNode: null,
17
18
_iconView: null,
19
_color: null,
20
_selected: null,
21
_buttonType: null,
22
23
setIcon: function(icon) {
24
this.getIconView().setIcon(icon);
25
return this;
26
},
27
28
getIconView: function() {
29
if (!this._iconView) {
30
this._iconView = new JX.PHUIXIconView();
31
this._redraw();
32
}
33
return this._iconView;
34
},
35
36
setColor: function(color) {
37
var node = this.getNode();
38
39
if (this._color) {
40
JX.DOM.alterClass(node, 'button-' + this._color, false);
41
}
42
this._color = color;
43
JX.DOM.alterClass(node, 'button-' + this._color, true);
44
45
return this;
46
},
47
48
setSelected: function(selected) {
49
var node = this.getNode();
50
this._selected = selected;
51
JX.DOM.alterClass(node, 'selected', this._selected);
52
return this;
53
},
54
55
setButtonType: function(button_type) {
56
var self = JX.PHUIXButtonView;
57
58
this._buttonType = button_type;
59
var node = this.getNode();
60
61
var is_simple = (this._buttonType == self.BUTTONTYPE_SIMPLE);
62
JX.DOM.alterClass(node, 'phui-button-simple', is_simple);
63
64
return this;
65
},
66
67
setText: function(text) {
68
JX.DOM.setContent(this._getTextNode(), text);
69
this._redraw();
70
return this;
71
},
72
73
setAuralLabel: function(label) {
74
JX.DOM.setContent(this._getAuralNode(), label);
75
this._redraw();
76
return this;
77
},
78
79
getNode: function() {
80
if (!this._node) {
81
var attrs = {
82
className: 'button'
83
};
84
85
this._node = JX.$N('button', attrs);
86
87
this._redraw();
88
}
89
90
return this._node;
91
},
92
93
_getTextNode: function() {
94
if (!this._textNode) {
95
var attrs = {
96
className: 'phui-button-text'
97
};
98
99
this._textNode = JX.$N('div', attrs);
100
}
101
102
return this._textNode;
103
},
104
105
_getAuralNode: function() {
106
if (!this._auralNode) {
107
var attrs = {
108
className: 'aural-only'
109
};
110
111
this._auralNode = JX.$N('span', attrs);
112
}
113
114
return this._auralNode;
115
},
116
117
_redraw: function() {
118
var node = this.getNode();
119
120
var aural = this._auralNode;
121
var icon = this._iconView;
122
var text = this._textNode;
123
124
var content = [];
125
126
if (aural) {
127
content.push(aural);
128
}
129
130
if (icon) {
131
content.push(icon.getNode());
132
}
133
134
if (text) {
135
content.push(text);
136
}
137
138
JX.DOM.alterClass(node, 'has-icon', !!icon);
139
JX.DOM.alterClass(node, 'has-text', !!text);
140
JX.DOM.setContent(node, content);
141
}
142
}
143
144
});
145
146