-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
228 lines (215 loc) · 6.2 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
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
/**
* @file mofron-comp-appheader/index.js
* @brief app header component for mofron
* @license MIT
*/
const Image = require('mofron-comp-image');
const Header = require('mofron-comp-txtheader');
const Text = require('mofron-comp-text');
const Link = require('mofron-event-link');
const Synhei = require('mofron-effect-synchei');
const Hrzpos = require('mofron-effect-hrzpos');
const Horiz = require('mofron-layout-horizon');
const comutl = mofron.util.common;
const ConfArg = mofron.class.ConfArg;
module.exports = class extends Header {
/**
* initialize component
*
* @param (mixed) mixed: title config parameter
* dict: component config list
* @param (mixed) image config parameter
* @param (component) navi config parameter
* @short title,image,navi
* @type private
*/
constructor (p1, p2, p3) {
try {
super();
this.modname('AppHeader');
this.shortForm('title', 'image', 'navi');
if (0 < arguments.length) {
this.config(p1, p2, p3);
}
} catch (e) {
console.error(e.stack);
throw e;
}
}
/**
* init dom contents
*
* @type private
*/
initDomConts() {
try {
super.initDomConts();
this.child(this.image(), 0);
this.image().event(new Link(location.href));
this.text().event(new Link(location.href));
let conts = new mofron.class.Component({ layout: new Horiz() });
this.child([ conts, this.naviWrap() ]);
this.styleDom(this.styleDom());
this.childDom(conts.childDom());
} catch (e) {
console.error(e.stack);
throw e;
}
}
/**
* header title
*
* @param (mixed) string: header title
* mofron-comp-text: replace title component of header
* @param (key-value) text config
* @return (mofron-comp-text) text contents
* @type parameter
*/
text (txt, cnf) {
try {
let ret = super.text(txt, cnf);
if (undefined !== txt) {
this.text().style({ "margin-left" : "0.2rem" }, { passive: true});
}
return ret;
} catch (e) {
console.error(e.stack);
throw e;
}
}
/**
* header title, same as text
*
* @param (mixed) string: header title
* mofron-comp-text: replace title component of header
* @param (key-value) text config
* @return (mofron-comp-text) text contents
* @type parameter
*/
title (txt, cnf) {
try {
return this.text(txt,cnf);
} catch (e) {
console.error(e.stack);
throw e;
}
}
/**
* setter/getter logo image
* insert logo image to left side of title
*
* @param (mixed) string: path to logo image
* mofron-comp-image: replace image component
* @param (key-value) image config
* @return (mofron-comp-image) logo image
* @type parameter
*/
image (prm, cnf) {
try {
if (undefined !== cnf) {
let add_cnf = (true === comutl.isinc(prm, 'Image')) ? prm : this.image();
add_cnf.config(cnf);
}
if ('string' === typeof prm) {
this.image().config({ path : prm });
return;
} else if (true === comutl.isinc(prm, 'Image')) {
prm.config({ effect : new Synhei(this,'-0.1rem') });
prm.style({ "margin-left" : "0.1rem" }, { passive: true});
}
return this.innerComp('image', prm, Image);
} catch (e) {
console.error(e.stack);
throw e;
}
}
/**
* setter/getter navigate area
*
* @param (component) navigate component
* @param (key-value) navigate component config
* @return (array) navigate component list
* @type parameter
*/
navi (prm, cnf) {
try {
if (undefined !== cnf) {
this.naviWrap().config(cnf);
}
return this.naviWrap().child(prm);
} catch (e) {
console.error(e.stack);
throw e;
}
}
/**
* logo image position and size offset
*
* @param (string (size)) left offset position
* @param (string (size)) height offset position
*
*/
imgpos (lft, hei) {
try {
this.image().style({ "margin-left" : lft });
let syn = this.image().effect({ name: "SyncHei" });
if (true === comutl.isinc(syn, "SyncHei") ) {
syn.offset(hei);
}
} catch (e) {
console.error(e.stack);
throw e;
}
}
/**
* setter/getter url jump target
* it jump to this url when user clicks logo or title
* set null if you don't want jump
*
* @param (mixed) string: jump url
* null: not jump
* @return (string) jump url
* @type parameter
*/
url (prm) {
try {
let txt_link = this.text().event({ modname: "Link" });
let img_link = this.image().event({ modname: "Link" });
if (undefined === prm) {
return ("" === txt_link.url()) ? null : txt_link.url();
}
if (null === prm) {
txt_link.config({ url:"", suspend: true });
img_link.config({ url:"", suspend: true });
} else {
txt_link.url(prm);
img_link.url(prm);
}
} catch (e) {
console.error(e.stack);
throw e;
}
}
/**
* setter/getter navigate wrapper
*
* @param (component) wrap component
* @return (component) wrap component
* @type private
*/
naviWrap (prm) {
try {
if (true === comutl.isinc(prm, 'Component')) {
prm.config({
layout : new Horiz(),
effect : new Hrzpos("right", "0.2rem")
});
}
return this.innerComp('naviWrap', prm, mofron.class.Component);
} catch (e) {
console.error(e.stack);
throw e;
}
}
}
/* end of file */