This repository was archived by the owner on Mar 17, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpop.js
More file actions
71 lines (57 loc) · 1.53 KB
/
pop.js
File metadata and controls
71 lines (57 loc) · 1.53 KB
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
import { create, on, off } from 'uc-dom';
let activePop;
export default {
addPop: function(opts) {
this.pop = opts.pop;
this.pop.onChange = value => this.onPopChange(value);
this.elPop = create(`div.input-pop.input-pop-${opts.popDirection || 'down'}`);
this.elPop.appendChild(opts.pop.el);
this.el.appendChild(this.elPop);
this.events.popFocus = on(this.input, 'focus', () => this.show());
this.events.popDocumentClick = on(document, 'click', () => this.hide());
},
removePop: function() {
off(this.input, 'focus', this.events.popFocus);
off(document, 'click', this.events.popDocumentClick);
this.pop.remove();
delete this.pop;
delete this.elPop;
},
show: function() {
if (this.popActive) {
return;
}
activePop && activePop.hide();
activePop = this.addClass('input-pop-active');
this.popActive = true;
return this;
},
hide: function() {
if (!this.popActive) {
return;
}
this.popActive = false;
this.removeClass('input-pop-active');
activePop = undefined;
},
toggle: function() {
this[this.popActive ? 'hide' : 'show']();
},
onChange: function(str) {
const currentValue = this.pop.toString();
if (str === currentValue) {
return;
}
try {
this.pop.value(str);
} catch (e) {
this.error(e);
}
},
onPopChange: function() {
this.setValue(this.pop.toString());
this.toggleClass('input-value', !!this.getValue());
this.onKeyUp();
this.onValueChange(this.pop.value());
}
}