- {{ p.user.name }}
+ {{ p.user.name }}
bot
@{{ p.user.username }}
diff --git a/src/web/app/desktop/views/components/user-preview.vue b/src/web/app/desktop/views/components/user-preview.vue
index fb6ae2553b..71b17503b3 100644
--- a/src/web/app/desktop/views/components/user-preview.vue
+++ b/src/web/app/desktop/views/components/user-preview.vue
@@ -45,7 +45,9 @@ export default Vue.extend({
mounted() {
if (typeof this.user == 'object') {
this.u = this.user;
- this.open();
+ this.$nextTick(() => {
+ this.open();
+ });
} else {
this.$root.$data.os.api('users/show', {
user_id: this.user[0] == '@' ? undefined : this.user,
diff --git a/src/web/app/desktop/views/directives/index.ts b/src/web/app/desktop/views/directives/index.ts
new file mode 100644
index 0000000000..324e07596d
--- /dev/null
+++ b/src/web/app/desktop/views/directives/index.ts
@@ -0,0 +1,6 @@
+import Vue from 'vue';
+
+import userPreview from './user-preview';
+
+Vue.directive('userPreview', userPreview);
+Vue.directive('user-preview', userPreview);
diff --git a/src/web/app/desktop/views/directives/user-preview.ts b/src/web/app/desktop/views/directives/user-preview.ts
new file mode 100644
index 0000000000..7d69936675
--- /dev/null
+++ b/src/web/app/desktop/views/directives/user-preview.ts
@@ -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();
+ }
+};
diff --git a/src/web/app/mobile/script.ts b/src/web/app/mobile/script.ts
index f7129c5539..f2d617f3a2 100644
--- a/src/web/app/mobile/script.ts
+++ b/src/web/app/mobile/script.ts
@@ -12,6 +12,9 @@ import init from '../init';
* init
*/
init((launch) => {
+ // Register directives
+ require('./views/directives');
+
// http://qiita.com/junya/items/3ff380878f26ca447f85
document.body.setAttribute('ontouchstart', '');
diff --git a/src/web/app/mobile/views/directives/index.ts b/src/web/app/mobile/views/directives/index.ts
new file mode 100644
index 0000000000..324e07596d
--- /dev/null
+++ b/src/web/app/mobile/views/directives/index.ts
@@ -0,0 +1,6 @@
+import Vue from 'vue';
+
+import userPreview from './user-preview';
+
+Vue.directive('userPreview', userPreview);
+Vue.directive('user-preview', userPreview);
diff --git a/src/web/app/mobile/views/directives/user-preview.ts b/src/web/app/mobile/views/directives/user-preview.ts
new file mode 100644
index 0000000000..1a54abc20d
--- /dev/null
+++ b/src/web/app/mobile/views/directives/user-preview.ts
@@ -0,0 +1,2 @@
+// nope
+export default {};