v12 (#5712)
Co-authored-by: MeiMei <30769358+mei23@users.noreply.github.com> Co-authored-by: Satsuki Yanagi <17376330+u1-liquid@users.noreply.github.com>
This commit is contained in:
61
src/client/directives/user-preview.ts
Normal file
61
src/client/directives/user-preview.ts
Normal file
@ -0,0 +1,61 @@
|
||||
import MkUserPreview from '../components/user-preview.vue';
|
||||
|
||||
export default {
|
||||
bind(el: HTMLElement, binding, vn) {
|
||||
const self = (el as any)._userPreviewDirective_ = {} as any;
|
||||
|
||||
self.user = binding.value;
|
||||
self.tag = null;
|
||||
self.showTimer = null;
|
||||
self.hideTimer = null;
|
||||
|
||||
self.close = () => {
|
||||
if (self.tag) {
|
||||
self.tag.close();
|
||||
self.tag = null;
|
||||
}
|
||||
};
|
||||
|
||||
const show = () => {
|
||||
if (self.tag) return;
|
||||
|
||||
self.tag = new MkUserPreview({
|
||||
parent: vn.context,
|
||||
propsData: {
|
||||
user: self.user,
|
||||
source: el
|
||||
}
|
||||
}).$mount();
|
||||
|
||||
self.tag.$on('mouseover', () => {
|
||||
clearTimeout(self.hideTimer);
|
||||
});
|
||||
|
||||
self.tag.$on('mouseleave', () => {
|
||||
clearTimeout(self.showTimer);
|
||||
self.hideTimer = setTimeout(self.close, 500);
|
||||
});
|
||||
|
||||
document.body.appendChild(self.tag.$el);
|
||||
};
|
||||
|
||||
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);
|
||||
});
|
||||
},
|
||||
|
||||
unbind(el, binding, vn) {
|
||||
const self = el._userPreviewDirective_;
|
||||
clearTimeout(self.showTimer);
|
||||
clearTimeout(self.hideTimer);
|
||||
self.close();
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user