-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
165 lines (151 loc) · 3.68 KB
/
index.js
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
/**
* @file mofron-comp-{@comp-name}/index.js
* @brief component module template for developper
* @license MIT
*/
const Input = require("mofron-comp-input");
const Button = require("mofron-comp-button");
const comutl = mofron.util.common;
module.exports = class extends mofron.class.Component {
/**
* initialize component
*
* @param (mixed)
* key-value: component config
* @short
* @type private
*/
constructor (p1) {
try {
super();
this.modname("Search");
this.shortForm("text");
this.confmng().add("searchEvent", { type: "event", list: true });
/* init config */
if (0 < arguments.length) {
this.config(p1);
}
} catch (e) {
console.error(e.stack);
throw e;
}
}
/**
* initialize dom contents
*
* @type private
*/
initDomConts () {
try {
super.initDomConts();
this.style({ "display" : "flex" });
this.button().config({ text:"Search" });
this.child([this.input(), this.button()]);
} catch (e) {
console.error(e.stack);
throw e;
}
}
input (prm) {
try {
if (true === comutl.isinc(prm, "Input")) {
prm.config({
type: "search", height: "0.31rem", accentColor: [180,180,180]
});
}
return this.innerComp("input", prm, Input);
} catch (e) {
console.error(e.stack);
throw e;
}
}
text (ph, btn) {
try {
this.placeholder(ph);
this.buttonText(btn);
} catch (e) {
console.error(e.stack);
throw e;
}
}
placeholder (prm) {
try {
let inp = this.child()[0];
return inp.childDom().attrs(
(undefined === prm) ? prm : { "placeholder" : prm }
);
} catch (e) {
console.error(e.stack);
throw e;
}
}
button (prm) {
try {
if ("string" === typeof prm) {
this.button().text(prm);
return;
} else if (true === comutl.isinc(prm, "Button")) {
prm.style({ "position": "relative", "left": "-0.01rem" });
prm.clickEvent((p1,p2,p3) => {
let evt = p3.searchEvent();
for (let eidx in evt) {
evt[eidx][0](
p3,
p3.input().value(),
evt[eidx][1]);
}
}, this);
}
return this.innerComp("button", prm, Button);
} catch (e) {
console.error(e.stack);
throw e;
}
}
buttonText (prm) {
try {
let btn = this.child()[1];
return btn.text(prm);
} catch (e) {
console.error(e.stack);
throw e;
}
}
fontFamily (prm) {
try {
this.child()[0].style({ "font-family" : "'" + prm + "'" });
} catch (e) {
console.error(e.stack);
throw e;
}
}
width (prm) {
try {
this.child()[0].width(prm);
} catch (e) {
console.error(e.stack);
throw e;
}
}
height (prm) {
try {
this.child()[0].height(prm);
return this.child()[1].height(comutl.sizediff(prm,"0.06rem"));
} catch (e) {
console.error(e.stack);
throw e;
}
}
searchEvent (fnc,prm) {
try {
return this.confmng(
"searchEvent",
(undefined === fnc) ? undefined : [fnc,prm]
);
} catch (e) {
console.error(e.stack);
throw e;
}
}
}
/* end of file */