Implement share functionality and UI updates: Add share button to various pages, create share popup with URL input, and enhance CSS styles for better layout and responsiveness. Update JavaScript for clipboard functionality and navigator share API support.
This commit is contained in:
@@ -1567,3 +1567,57 @@ function btnTabMenu(tabBtnNumber) {
|
||||
$(".tab-menu .btn-select").text($tabBtnText);
|
||||
}
|
||||
}
|
||||
|
||||
// 공유하기 팝업 열릴 때 URL 설정
|
||||
function openSharePopup() {
|
||||
var currentUrl = window.location.href;
|
||||
currentUrl = currentUrl.split("?")[0];
|
||||
currentUrl = currentUrl.split("#")[0];
|
||||
document.getElementById("shareUrl").value = currentUrl;
|
||||
|
||||
// 모바일이고 navigator.share API가 지원되는 경우
|
||||
if (navigator.share) {
|
||||
const shareData = {
|
||||
title: document.title,
|
||||
url: currentUrl,
|
||||
};
|
||||
|
||||
const btn = document.querySelector(".btn-share");
|
||||
|
||||
// Share must be triggered by "user activation"
|
||||
btn.addEventListener("click", async () => {
|
||||
try {
|
||||
await navigator.share(shareData);
|
||||
console.log("MDN shared successfully");
|
||||
} catch (err) {
|
||||
console.log(`Error: ${err}`);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.log("navigator.share is not supported");
|
||||
open_layer_popup("sharePopup");
|
||||
}
|
||||
}
|
||||
|
||||
// 링크 복사 함수
|
||||
function copyShareLink() {
|
||||
var urlInput = document.getElementById("shareUrl");
|
||||
urlInput.select();
|
||||
urlInput.setSelectionRange(0, 99999); // 모바일 지원
|
||||
|
||||
try {
|
||||
document.execCommand("copy");
|
||||
alert("링크가 복사되었습니다.");
|
||||
close_layer_popup("sharePopup");
|
||||
} catch (err) {
|
||||
// execCommand가 실패한 경우 (최신 브라우저)
|
||||
if (navigator.clipboard && navigator.clipboard.writeText) {
|
||||
navigator.clipboard.writeText(urlInput.value).then(function () {
|
||||
alert("링크가 복사되었습니다.");
|
||||
close_layer_popup("sharePopup");
|
||||
});
|
||||
} else {
|
||||
alert("링크 복사에 실패했습니다. 수동으로 복사해주세요.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user