From 7674a62d40b7d4eec82387a1157e48da10c2f312 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 28 Feb 2021 02:22:53 +0900 Subject: chore: improve reaction picker behaviour --- src/client/components/ui/modal.vue | 111 ++++++++++++++++++++----------------- 1 file changed, 59 insertions(+), 52 deletions(-) (limited to 'src/client/components') diff --git a/src/client/components/ui/modal.vue b/src/client/components/ui/modal.vue index 1c8ae63907..03be437071 100644 --- a/src/client/components/ui/modal.vue +++ b/src/client/components/ui/modal.vue @@ -69,71 +69,78 @@ export default defineComponent({ mounted() { this.$watch('src', () => { this.fixed = getFixedContainer(this.src) != null; + this.$nextTick(() => { + this.align(); + }); }, { immediate: true }); this.$nextTick(() => { const popover = this.$refs.content as any; - - // TODO: ResizeObserver無くしたい new ResizeObserver((entries, observer) => { - if (!this.popup) return; - - const rect = this.src.getBoundingClientRect(); - - const width = popover.offsetWidth; - const height = popover.offsetHeight; - - let left; - let top; - - if (this.srcCenter) { - const x = rect.left + (this.fixed ? 0 : window.pageXOffset) + (this.src.offsetWidth / 2); - const y = rect.top + (this.fixed ? 0 : window.pageYOffset) + (this.src.offsetHeight / 2); - left = (x - (width / 2)); - top = (y - (height / 2)); - } else { - const x = rect.left + (this.fixed ? 0 : window.pageXOffset) + (this.src.offsetWidth / 2); - const y = rect.top + (this.fixed ? 0 : window.pageYOffset) + this.src.offsetHeight; - left = (x - (width / 2)); - top = y; - } + this.align(); + }).observe(popover); + }); + }, + methods: { + align() { + if (!this.popup) return; - if (this.fixed) { - if (left + width > window.innerWidth) { - left = window.innerWidth - width; - } - - if (top + height > window.innerHeight) { - top = window.innerHeight - height; - } - } else { - if (left + width - window.pageXOffset > window.innerWidth) { - left = window.innerWidth - width + window.pageXOffset - 1; - } - - if (top + height - window.pageYOffset > window.innerHeight) { - top = window.innerHeight - height + window.pageYOffset - 1; - } - } + const popover = this.$refs.content as any; + + const rect = this.src.getBoundingClientRect(); + + const width = popover.offsetWidth; + const height = popover.offsetHeight; + + let left; + let top; + + if (this.srcCenter) { + const x = rect.left + (this.fixed ? 0 : window.pageXOffset) + (this.src.offsetWidth / 2); + const y = rect.top + (this.fixed ? 0 : window.pageYOffset) + (this.src.offsetHeight / 2); + left = (x - (width / 2)); + top = (y - (height / 2)); + } else { + const x = rect.left + (this.fixed ? 0 : window.pageXOffset) + (this.src.offsetWidth / 2); + const y = rect.top + (this.fixed ? 0 : window.pageYOffset) + this.src.offsetHeight; + left = (x - (width / 2)); + top = y; + } - if (top < 0) { - top = 0; + if (this.fixed) { + if (left + width > window.innerWidth) { + left = window.innerWidth - width; } - if (left < 0) { - left = 0; + if (top + height > window.innerHeight) { + top = window.innerHeight - height; + } + } else { + if (left + width - window.pageXOffset > window.innerWidth) { + left = window.innerWidth - width + window.pageXOffset - 1; } - if (top > rect.top + (this.fixed ? 0 : window.pageYOffset)) { - this.transformOrigin = 'center top'; + if (top + height - window.pageYOffset > window.innerHeight) { + top = window.innerHeight - height + window.pageYOffset - 1; } + } + + if (top < 0) { + top = 0; + } + + if (left < 0) { + left = 0; + } + + if (top > rect.top + (this.fixed ? 0 : window.pageYOffset)) { + this.transformOrigin = 'center top'; + } + + popover.style.left = left + 'px'; + popover.style.top = top + 'px'; + }, - popover.style.left = left + 'px'; - popover.style.top = top + 'px'; - }).observe(popover); - }); - }, - methods: { childRendered() { // モーダルコンテンツにマウスボタンが押され、コンテンツ外でマウスボタンが離されたときにモーダルバックグラウンドクリックと判定させないためにマウスイベントを監視しフラグ管理する const content = this.$refs.content.children[0]; -- cgit v1.2.3-freya