-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhtmlselect.mata
250 lines (159 loc) · 7.42 KB
/
htmlselect.mata
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
// Switch to Mata interpreter/compiler
mata:
// Drops class object if it already exists
// mata drop stselect()
// Definition of HTML Tag stselect Mata Class
// Defines a drop-down list// Information retrieved from http://www.w3schools.com/tags/tag_select.asp
class stselect extends htmlglobal {
// Define private member variables
private:
// Static/final variables
static string scalar opens, opene, close
// String scalar attributes
string scalar htmlautofocus, htmldisabled, htmlform, htmlmultiple, htmlname, htmlrequired, htmlsize
// Make class args non-static to prevent assignment of class args to all instances of class
string scalar classargs
// Define public members/methods
public:
// Class constructor method
void new()
// Setter methods
class stselect scalar setClassArgs(), setAutofocus(), setDisabled(), setForm(), setMultiple(), setName(), setRequired(), setSize()
// Getter methods
string scalar getOpens(), getOpene(), getClose(), print(), getClassArgs(), getAutofocus(), getDisabled(), getForm(), getMultiple(), getName(), getRequired(), getSize()
} // End of class declaration
// Class constructor method declaration
void stselect::new() {
// Defines the start of the opening tag for the class
this.opens = "<select"
// Defines the end of the opening tag for the class
this.opene = ">"
// Defines the closing tag for the class
this.close = "</select>"
} // End of class constructor method definition
// Setter method for class arguments (appear between HTML tags)
class stselect scalar stselect::setClassArgs(| string scalar classarguments) {
// Defines arguments that appear between HTML tags
this.classargs = classarguments
// Return a copy of the object
return(this)
} // End of setter method for class arguments
// Specifies that the drop-down list should automatically get focus when the page loads
class stselect scalar stselect::setAutofocus(| string scalar methodarg) {
// Set the attribute autofocus for this class
this.htmlautofocus = `" autofocus=""' + methodarg + `"""'
// Return a copy of the object
return(this)
} // End of Method autofocus declaration for class stselect
// Specifies that a drop-down list should be disabled
class stselect scalar stselect::setDisabled(| string scalar methodarg) {
// Set the attribute disabled for this class
this.htmldisabled = `" disabled=""' + methodarg + `"""'
// Return a copy of the object
return(this)
} // End of Method disabled declaration for class stselect
// Defines one or more forms the select field belongs to
class stselect scalar stselect::setForm(| string scalar methodarg) {
// Set the attribute form for this class
this.htmlform = `" form=""' + methodarg + `"""'
// Return a copy of the object
return(this)
} // End of Method form declaration for class stselect
// Specifies that multiple options can be selected at once
class stselect scalar stselect::setMultiple(| string scalar methodarg) {
// Set the attribute multiple for this class
this.htmlmultiple = `" multiple=""' + methodarg + `"""'
// Return a copy of the object
return(this)
} // End of Method multiple declaration for class stselect
// Defines a name for the drop-down list
class stselect scalar stselect::setName(| string scalar methodarg) {
// Set the attribute name for this class
this.htmlname = `" name=""' + methodarg + `"""'
// Return a copy of the object
return(this)
} // End of Method name declaration for class stselect
// Specifies that the user is required to select a value before submitting the form
class stselect scalar stselect::setRequired(| string scalar methodarg) {
// Set the attribute required for this class
this.htmlrequired = `" required=""' + methodarg + `"""'
// Return a copy of the object
return(this)
} // End of Method required declaration for class stselect
// Defines the number of visible options in a drop-down list
class stselect scalar stselect::setSize(| string scalar methodarg) {
// Set the attribute size for this class
this.htmlsize = `" size=""' + methodarg + `"""'
// Return a copy of the object
return(this)
} // End of Method size declaration for class stselect
// Getter method for opening bracket
string scalar stselect::getOpens() {
// Returns the opening bracket/tag w/o > character to allow attributes
return(this.opens)
} // End of getter method for opens member of class stselect
// Getter method for opening bracket closing character
string scalar stselect::getOpene() {
// Returns the closing character for the opening bracket
return(this.opene)
} // End of getter method for opene member of class stselect
// Getter method for closing bracket
string scalar stselect::getClose() {
// Returns the closing bracket/tag
return(this.close)
} // End of getter method for close member of class stselect
// Getter method for class arguments
string scalar stselect::getClassArgs() {
// Returns the class arguments that appear between the HTML tags
return(this.classargs)
} // End of getter method for class arguments member of class stselect
// Getter method for autofocus member variable
string scalar stselect::getAutofocus() {
// Returns the autofocus variable
return(this.htmlautofocus)
} // End of getter method for autofocus member of class stselect
// Getter method for disabled member variable
string scalar stselect::getDisabled() {
// Returns the disabled variable
return(this.htmldisabled)
} // End of getter method for disabled member of class stselect
// Getter method for form member variable
string scalar stselect::getForm() {
// Returns the form variable
return(this.htmlform)
} // End of getter method for form member of class stselect
// Getter method for multiple member variable
string scalar stselect::getMultiple() {
// Returns the multiple variable
return(this.htmlmultiple)
} // End of getter method for multiple member of class stselect
// Getter method for name member variable
string scalar stselect::getName() {
// Returns the name variable
return(this.htmlname)
} // End of getter method for name member of class stselect
// Getter method for required member variable
string scalar stselect::getRequired() {
// Returns the required variable
return(this.htmlrequired)
} // End of getter method for required member of class stselect
// Getter method for size member variable
string scalar stselect::getSize() {
// Returns the size variable
return(this.htmlsize)
} // End of getter method for size member of class stselect
// Get the HTML tag w/attributes and arguments
string scalar stselect::print() {
// Create local variables to piece together return string
string scalar open, args, close
// Create opening string
open = getOpens() + getAutofocus() + getDisabled() + getForm() + getMultiple() + getName() + getRequired() + getSize() + globalAttrs() + getOpene()
// Get class arguments
args = getClassArgs()
// Get closing tag
close = getClose()
// Return the complete HTML string
return(char((10)) + subinstr(open, " >", ">") + args + close + char((10)))
} // End of print method for class stselect
// End of Mata session
end