「MediaWiki:Forum.js」の版間の差分
編集の要約なし |
編集の要約なし |
||
| 587行目: | 587行目: | ||
const showPopup = (anchorEl, postId) => { | const showPopup = (anchorEl, postId) => { | ||
const target = document.querySelector(`#post-${postId}`); | |||
if (!target) return; | |||
// 対象投稿をクローンしてポップアップに表示 | |||
const clone = target.cloneNode(true); | |||
clone.querySelectorAll('a[href*="fedit"], span[style*="#d33"]').forEach(el => el.remove()); | |||
popup.innerHTML = ''; | |||
popup.appendChild(clone); | |||
// ポップアップの位置をリンクの近くに配置(モバイル対応) | |||
const rect = anchorEl.getBoundingClientRect(); | |||
const viewportWidth = window.innerWidth; | |||
const viewportHeight = window.innerHeight; | |||
// ポップアップの最大幅を画面幅の90%に制限 | |||
const maxWidth = Math.min(480, viewportWidth * 0.9); | |||
popup.style.maxWidth = maxWidth + 'px'; | |||
// 一度表示して実際の高さを取得 | |||
popup.style.display = 'block'; | |||
popup.style.visibility = 'hidden'; | |||
const popupHeight = popup.offsetHeight; | |||
popup.style.visibility = 'visible'; | |||
// 縦位置:下に余裕があれば下、なければ上 | |||
const spaceBelow = viewportHeight - rect.bottom; | |||
const top = spaceBelow > popupHeight + 10 | |||
? rect.bottom + 4 | |||
: Math.max(4, rect.top - popupHeight - 4); | |||
// 横位置:画面からはみ出ないように調整 | |||
let left = rect.left; | |||
if (left + maxWidth > viewportWidth - 10) { | |||
left = viewportWidth - maxWidth - 10; | |||
} | |||
if (left < 10) { | |||
left = 10; | |||
} | |||
popup.style.left = left + 'px'; | |||
popup.style.top = top + 'px'; | |||
}; | |||
const hidePopup = () => { | const hidePopup = () => { | ||