-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
143 lines (133 loc) · 3.65 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
/**
* @file mofron-comp-contextitem.js
* @brief contextmenu item component for mofron
* @license MIT
*/
const Text = require('mofron-comp-text');
const Color = require('mofron-effect-color');
const Hover = require('mofron-event-hover');
const Click = require('mofron-event-click');
const comutl = mofron.util.common;
const ConfArg = mofron.class.ConfArg;
module.exports = class extends mofron.class.Component {
/**
* initialize component
*
* @param (mixed) ratio parameter
* key-value: component option
* @type private
*/
constructor (p1) {
try {
super();
this.modname("ContextItem");
this.shortForm('text');
this.confmng().add('clickEvent', { type:'event', list:true });
/* set config */
if (0 < arguments.length) {
this.config(p1);
}
} catch (e) {
console.error(e.stack);
throw e;
}
}
hoverEvent (p1,p2,p3) {
try {
p3.execEffect((true === p2) ? 2:3);
} catch (e) {
console.error(e.stack);
throw e;
}
}
clickEvent (fnc,prm) {
try {
if (undefined === fnc) {
return this.confmng('clickEvent');
}
this.confmng('clickEvent',[fnc,prm]);
} catch (e) {
console.error(e.stack);
throw e;
}
}
/**
* initialize dom contents
*
* @type private
*/
initDomConts () {
try {
super.initDomConts();
this.style({
'align-items': 'center',
'display': 'flex'
});
this.size('100%','0.3rem');
this.effect([
new Color({ tag:'ContextItem', speed:100, eid:2, type:'base' }),
new Color({ tag:'ContextItem', speed:100, eid:3, type:'base', color:[255,255,255] })
]);
let clk = (c1,c2,c3) => {
try {
let cevt = c1.clickEvent();
for (let cidx in cevt) {
cevt[cidx][0](c1,c2,cevt[cidx][1]);
}
} catch (e) {
console.error(e.stack);
throw e;
}
}
this.event([
new Hover(new ConfArg(this.hoverEvent,this)),
new Hover(new ConfArg(this.hoverEvent,this.text())),
new Click(clk)
]);
this.child(this.text());
} catch (e) {
console.error(e.stack);
throw e;
}
}
text (prm) {
try {
if ('string' === typeof prm) {
this.text().text(prm);
return;
} else if (true === comutl.isinc(prm,'Text')) {
prm.config({
style: { 'margin-left':'0.1rem' },
effect:[
new Color({ tag:'ContextItem', speed:100, eid:2, type:'main' }),
new Color({ tag:'ContextItem', speed:100, eid:3, type:'main' })
],
});
}
return this.innerComp('text', prm, Text);
} catch (e) {
console.error(e.stack);
throw e;
}
}
invert (prm) {
try {
if (true === prm) {
this.text().effect({ modname:'Color', tag:'ContextItem', eid:2 }).color([255,255,255]);
this.text().effect({ modname:'Color', tag:'ContextItem', eid:3 }).color(this.text().mainColor());
}
} catch (e) {
console.error(e.stack);
throw e;
}
}
accentColor (prm, opt) {
try {
return this.effect({ modname:'Color', eid:2 }).color(prm);
} catch (e) {
console.error(e.stack);
throw e;
}
}
}
/* end of file */