1
0
mirror of https://github.com/MisskeyIO/misskey synced 2024-12-24 03:28:27 +09:00
MisskeyIO/src/client/app/desktop/views/directives/user-preview.ts

73 lines
1.6 KiB
TypeScript
Raw Normal View History

2018-02-18 22:16:36 +09:00
/**
*
*/
2018-02-17 02:24:10 +09:00
import MkUserPreview from '../components/user-preview.vue';
export default {
bind(el, binding, vn) {
2018-02-19 14:29:42 +09:00
const self = el._userPreviewDirective_ = {} as any;
2018-02-17 02:24:10 +09:00
self.user = binding.value;
2018-02-19 14:29:42 +09:00
self.tag = null;
2018-02-17 02:24:10 +09:00
self.showTimer = null;
self.hideTimer = null;
self.close = () => {
2018-02-19 14:29:42 +09:00
if (self.tag) {
self.tag.close();
self.tag = null;
2018-02-17 02:24:10 +09:00
}
};
const show = () => {
2018-02-19 14:29:42 +09:00
if (self.tag) return;
2018-02-18 22:16:36 +09:00
2018-02-19 14:29:42 +09:00
self.tag = new MkUserPreview({
2018-02-17 02:24:10 +09:00
parent: vn.context,
propsData: {
user: self.user
}
}).$mount();
2018-02-18 22:16:36 +09:00
2018-02-19 14:29:42 +09:00
const preview = self.tag.$el;
2018-02-17 02:24:10 +09:00
const rect = el.getBoundingClientRect();
const x = rect.left + el.offsetWidth + window.pageXOffset;
const y = rect.top + window.pageYOffset;
2018-02-18 22:16:36 +09:00
2018-02-17 02:24:10 +09:00
preview.style.top = y + 'px';
preview.style.left = x + 'px';
2018-02-18 22:16:36 +09:00
2018-02-17 02:24:10 +09:00
preview.addEventListener('mouseover', () => {
clearTimeout(self.hideTimer);
});
2018-02-18 22:16:36 +09:00
2018-02-17 02:24:10 +09:00
preview.addEventListener('mouseleave', () => {
clearTimeout(self.showTimer);
self.hideTimer = setTimeout(self.close, 500);
});
2018-02-18 22:16:36 +09:00
2018-02-17 02:24:10 +09:00
document.body.appendChild(preview);
};
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 22:16:36 +09:00
2018-02-17 02:24:10 +09:00
unbind(el, binding, vn) {
2018-02-19 14:29:42 +09:00
const self = el._userPreviewDirective_;
2018-02-17 02:24:10 +09:00
clearTimeout(self.showTimer);
clearTimeout(self.hideTimer);
self.close();
}
};