$(function() { // 클립보드 활성화 new ClipboardJS('.clipboard'); }); function copyToClipboard() { if (typeof sns_post === 'undefined') { sns_post = window.location.href; } navigator.clipboard.writeText(sns_post).then(r => alert(share_msg)); } function shareSocial(type) { // 소셜 공유 링크 클릭 팝업 switch (type) { case 'kakao': Kakao.Share.sendDefault({ objectType: 'feed', content: { title: share_title, description: share_comment, imageUrl: sns_img, imageWidth: 420, imageHeight: 420, link: { mobileWebUrl: link, webUrl: link, }, }, installTalk: true, buttons: [ { title: share_button, link: { mobileWebUrl: link, webUrl: link, }, }, ], }); break; case 'twitter': if (typeof sns_post === 'undefined') { sns_post = window.location.href; } result = window.open('https://twitter.com/intent/tweet?url='+encodeURIComponent(sns_post)+'&text='+encodeURIComponent(sns_name)); if (!result) { alert(popup_msg); } break; case 'facebook': if (typeof sns_post === 'undefined') { sns_post = window.location.href; } result = window.open('https://www.facebook.com/sharer.php?u='+encodeURIComponent(sns_post)+'&t='+encodeURIComponent(share_title)); if (!result) { alert(popup_msg); } break; case 'instagram': (async () => { const response = await fetch(sns_img); const blob = await response.blob(); const filesArray = [ new File([blob], sns_img, { type: 'image/png', lastModified: new Date().getTime(), }), ]; const shareData = { title: share_title, files: filesArray, }; if (navigator.canShare && navigator.canShare(shareData)) { await navigator.share(shareData); } })().then(r => console.log(r)); break; default: copyToClipboard(); break; } }