-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
177 lines (165 loc) · 4.84 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
/**
* @file mofron-comp-dropboard/index.js
* @author simpart
*/
let mf = require('mofron');
let Drag = require('mofron-event-drag');
let Drgeff = require('mofron-effect-draggable');
/**
* @class mofron.comp.DropBoard
* @brief DropBoard component for mofron
*/
mf.comp.DropBoard = class extends mf.Component {
constructor (po) {
try {
super();
this.name('DropBoard');
this.m_tempkey = new Drgeff().getTempKey();
this.prmOpt(po);
} catch (e) {
console.error(e.stack);
throw e;
}
}
/**
* initialize vdom
*
* @param prm :
*/
initDomConts (prm) {
try {
super.initDomConts (prm);
/* set drag event */
let drg_core = (tgt, tp, drp_cmp) => {
try {
let chk_drp_cmp = mf.func.getTemp(tgt.m_tempkey);
if ( ('dragenter' === tp) &&
(null !== chk_drp_cmp) ) {
/* notify drag-enter event */
tgt.dragEnter(chk_drp_cmp);
} else if ('dragleave' === tp) {
if (null === drp_cmp) {
console.warn('drag-component is null');
return;
}
if (null === mf.func.getTemp(tgt.m_tempkey)) {
//tgt.isDropped(true);
tgt.dropped(drp_cmp);
} else {
tgt.dragLeave(drp_cmp);
}
}
} catch (e) {
console.error(e.stack);
throw e;
}
}
let drg_evt = new Drag({
addType : ['dragenter', 'dragleave', 'dragover'],
handler : (tgt, tp) => {
try {
setTimeout(
drg_core,
100,
tgt,
tp,
mf.func.getTemp(this.m_tempkey)
);
} catch (e) {
console.error(e.stack);
throw e;
}
}
});
this.addEvent(drg_evt);
} catch (e) {
console.error(e.stack);
throw e;
}
}
size (wid, hei) {
try {
if (undefined === wid) {
/* getter */
return [
mf.func.getLength(this.style('width')),
mf.func.getLength(this.style('height'))
];
}
/* setter */
this.style({
width : ('number' === typeof wid) ? wid + 'px' : wid,
height : ('number' === typeof hei) ? hei + 'px' : hei
});
} catch (e) {
console.error(e.stack);
throw e;
}
}
/**
* enable effect when component was entered in dragg.
*/
dragEnter (cmp) {
try {
/* dragenter event */
let eff = this.effect();
for (let eff_idx in eff) {
eff[eff_idx][0].execute(true);
}
} catch (e) {
console.error(e.stack);
throw e;
}
}
/**
* disable effect when component was leaved in drag.
*/
dragLeave (cmp) {
try {
/* dragleave event */
let eff = this.effect();
for (let eff_idx in eff) {
eff[eff_idx][0].execute(false);
}
} catch (e) {
console.error(e.stack);
throw e;
}
}
dropped (cmp) {
try {
/* dragend event on this component */
let devt = this.dropEvent();
for (let d_idx in devt) {
devt[d_idx][0](cmp, devt[d_idx][1]);
}
} catch (e) {
console.error(e.stack);
throw e;
}
}
addDropEvent (evt, prm) {
try {
if ('function' !== typeof evt) {
throw new Error('invalid parameter');
}
if (undefined === this.m_dropevt) {
this.m_dropevt = new Array();
}
this.m_dropevt.push([evt, prm]);
} catch (e) {
console.error(e.stack);
throw e;
}
}
dropEvent () {
try {
return (undefined === this.m_dropevt) ? null : this.m_dropevt;
} catch (e) {
console.error(e.stack);
throw e;
}
}
}
mofron.comp.dropboard = {};
module.exports = mofron.comp.DropBoard;