mirror of
https://github.com/misskey-dev/misskey.git
synced 2026-05-25 16:44:05 +02:00
wip
This commit is contained in:
6
src/web/app/desktop/views/directives/index.ts
Normal file
6
src/web/app/desktop/views/directives/index.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import Vue from 'vue';
|
||||
|
||||
import userPreview from './user-preview';
|
||||
|
||||
Vue.directive('userPreview', userPreview);
|
||||
Vue.directive('user-preview', userPreview);
|
||||
63
src/web/app/desktop/views/directives/user-preview.ts
Normal file
63
src/web/app/desktop/views/directives/user-preview.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import MkUserPreview from '../components/user-preview.vue';
|
||||
|
||||
export default {
|
||||
bind(el, binding, vn) {
|
||||
const self = vn.context._userPreviewDirective_ = {} as any;
|
||||
|
||||
self.user = binding.value;
|
||||
|
||||
let tag = null;
|
||||
self.showTimer = null;
|
||||
self.hideTimer = null;
|
||||
|
||||
self.close = () => {
|
||||
if (tag) {
|
||||
tag.close();
|
||||
tag = null;
|
||||
}
|
||||
};
|
||||
|
||||
const show = () => {
|
||||
if (tag) return;
|
||||
tag = new MkUserPreview({
|
||||
parent: vn.context,
|
||||
propsData: {
|
||||
user: self.user
|
||||
}
|
||||
}).$mount();
|
||||
const preview = tag.$el;
|
||||
const rect = el.getBoundingClientRect();
|
||||
const x = rect.left + el.offsetWidth + window.pageXOffset;
|
||||
const y = rect.top + window.pageYOffset;
|
||||
preview.style.top = y + 'px';
|
||||
preview.style.left = x + 'px';
|
||||
preview.addEventListener('mouseover', () => {
|
||||
clearTimeout(self.hideTimer);
|
||||
});
|
||||
preview.addEventListener('mouseleave', () => {
|
||||
clearTimeout(self.showTimer);
|
||||
self.hideTimer = setTimeout(self.close, 500);
|
||||
});
|
||||
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);
|
||||
});
|
||||
},
|
||||
unbind(el, binding, vn) {
|
||||
const self = vn.context._userPreviewDirective_;
|
||||
console.log('unbound:', self.user);
|
||||
clearTimeout(self.showTimer);
|
||||
clearTimeout(self.hideTimer);
|
||||
self.close();
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user