-
Notifications
You must be signed in to change notification settings - Fork 0
/
ResetX.js
55 lines (47 loc) · 1.12 KB
/
ResetX.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
let component = null;
export const ResetX = {
/**
* Called by Vue when the directive is created
* @param {*} el DOM element this directive is attached to
*/
inserted(el, _binding, vnode) {
el.onfocus = () => {
vnode.elm.parentElement.style.position = "relative";
if (el.value) {
component.$el.classList.add("v-reset-input-active");
}
};
el.onblur = () => {
setTimeout(() => {
component.$el.classList.remove("v-reset-input-active");
}, 150);
};
let onClick = () => {
el.value = "";
el.dispatchEvent(new Event("input"));
el.focus();
};
let resetComponent = Vue.extend({
render(h) {
return h("span", {
domProps: { innerHTML: "✖" },
class: { "v-reset-input": true },
style: { position: "absolute", cursor: "default" },
on: {
click: onClick
}
});
}
});
let span = document.createElement("span");
el.after(span);
component = new resetComponent().$mount(span);
},
update(el) {
if (!el.value) {
component.$el.classList.remove("v-reset-input-active");
} else {
component.$el.classList.add("v-reset-input-active");
}
}
};