2018-02-16 19:24:10 +02:00
|
|
|
import MkUserPreview from '../components/user-preview.vue';
|
|
|
|
|
|
|
|
export default {
|
2020-01-29 21:37:25 +02:00
|
|
|
bind(el: HTMLElement, binding, vn) {
|
|
|
|
const self = (el as any)._userPreviewDirective_ = {} as any;
|
2018-02-16 19:24:10 +02:00
|
|
|
|
|
|
|
self.user = binding.value;
|
2018-02-19 07:29:42 +02:00
|
|
|
self.tag = null;
|
2018-02-16 19:24:10 +02:00
|
|
|
self.showTimer = null;
|
|
|
|
self.hideTimer = null;
|
|
|
|
|
|
|
|
self.close = () => {
|
2018-02-19 07:29:42 +02:00
|
|
|
if (self.tag) {
|
|
|
|
self.tag.close();
|
|
|
|
self.tag = null;
|
2018-02-16 19:24:10 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const show = () => {
|
2018-02-19 07:29:42 +02:00
|
|
|
if (self.tag) return;
|
2018-02-18 15:16:36 +02:00
|
|
|
|
2018-02-19 07:29:42 +02:00
|
|
|
self.tag = new MkUserPreview({
|
2018-02-16 19:24:10 +02:00
|
|
|
parent: vn.context,
|
|
|
|
propsData: {
|
2020-01-29 21:37:25 +02:00
|
|
|
user: self.user,
|
|
|
|
source: el
|
2018-02-16 19:24:10 +02:00
|
|
|
}
|
|
|
|
}).$mount();
|
2018-02-18 15:16:36 +02:00
|
|
|
|
2020-01-29 21:37:25 +02:00
|
|
|
self.tag.$on('mouseover', () => {
|
2018-02-16 19:24:10 +02:00
|
|
|
clearTimeout(self.hideTimer);
|
|
|
|
});
|
2018-02-18 15:16:36 +02:00
|
|
|
|
2020-01-29 21:37:25 +02:00
|
|
|
self.tag.$on('mouseleave', () => {
|
2018-02-16 19:24:10 +02:00
|
|
|
clearTimeout(self.showTimer);
|
|
|
|
self.hideTimer = setTimeout(self.close, 500);
|
|
|
|
});
|
2018-02-18 15:16:36 +02:00
|
|
|
|
2020-01-29 21:37:25 +02:00
|
|
|
document.body.appendChild(self.tag.$el);
|
2018-02-16 19:24:10 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
el.addEventListener('mouseover', () => {
|
|
|
|
clearTimeout(self.showTimer);
|
|
|
|
clearTimeout(self.hideTimer);
|
|
|
|
self.showTimer = setTimeout(show, 500);
|
|
|
|
});
|
|
|
|
|
|
|
|
el.addEventListener('mouseleave', () => {
|
|
|
|
clearTimeout(self.showTimer);
|
|
|
|
clearTimeout(self.hideTimer);
|
|
|
|
self.hideTimer = setTimeout(self.close, 500);
|
|
|
|
});
|
|
|
|
},
|
2018-02-18 15:16:36 +02:00
|
|
|
|
2018-02-16 19:24:10 +02:00
|
|
|
unbind(el, binding, vn) {
|
2018-02-19 07:29:42 +02:00
|
|
|
const self = el._userPreviewDirective_;
|
2018-02-16 19:24:10 +02:00
|
|
|
clearTimeout(self.showTimer);
|
|
|
|
clearTimeout(self.hideTimer);
|
|
|
|
self.close();
|
|
|
|
}
|
|
|
|
};
|