// Share Overlay Functions
function openShareOverlay() {
const overlay = document.getElementById('btpShareOverlay');
if (overlay) {
overlay.classList.add('active');
document.body.style.overflow = 'hidden';
}
}
function closeShareOverlay() {
const overlay = document.getElementById('btpShareOverlay');
if (overlay) {
overlay.classList.remove('active');
document.body.style.overflow = '';
}
}
// Copy Link to Clipboard
function copyLinkToClipboard() {
const url = window.location.href;
// Modern clipboard API
if (navigator.clipboard) {
navigator.clipboard.writeText(url).then(function() {
showCopyNotification();
closeShareOverlay();
}, function(err) {
fallbackCopyTextToClipboard(url);
});
} else {
fallbackCopyTextToClipboard(url);
}
}
// Fallback for older browsers
function fallbackCopyTextToClipboard(text) {
const textArea = document.createElement("textarea");
textArea.value = text;
textArea.style.position = "fixed";
textArea.style.top = "0";
textArea.style.left = "0";
textArea.style.width = "2em";
textArea.style.height = "2em";
textArea.style.padding = "0";
textArea.style.border = "none";
textArea.style.outline = "none";
textArea.style.boxShadow = "none";
textArea.style.background = "transparent";
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
try {
const successful = document.execCommand('copy');
if (successful) {
showCopyNotification();
closeShareOverlay();
}
} catch (err) {
console.error('Fallback: Oops, unable to copy', err);
}
document.body.removeChild(textArea);
}
// Show notification after copying
function showCopyNotification() {
const notification = document.createElement('div');
notification.className = 'btp-copy-notification';
notification.textContent = 'Link berhasil disalin!';
notification.style.cssText = `
position: fixed;
bottom: 20px;
left: 50%;
transform: translateX(-50%);
background: #212121;
color: #fff;
padding: 12px 24px;
border-radius: 8px;
font-family: 'Manrope', sans-serif;
font-size: 14px;
font-weight: 600;
z-index: 10000;
animation: slideUp 0.3s ease;
`;
document.body.appendChild(notification);
setTimeout(function() {
notification.style.animation = 'slideDown 0.3s ease';
setTimeout(function() {
document.body.removeChild(notification);
}, 300);
}, 2000);
}
// Add animation styles
const style = document.createElement('style');
style.textContent = `
@keyframes slideUp {
from {
opacity: 0;
transform: translateX(-50%) translateY(20px);
}
to {
opacity: 1;
transform: translateX(-50%) translateY(0);
}
}
@keyframes slideDown {
from {
opacity: 1;
transform: translateX(-50%) translateY(0);
}
to {
opacity: 0;
transform: translateX(-50%) translateY(20px);
}
}
`;
document.head.appendChild(style);
// Close overlay when clicking outside
document.addEventListener('click', function(e) {
const overlay = document.getElementById('btpShareOverlay');
if (overlay && overlay.classList.contains('active')) {
if (e.target === overlay) {
closeShareOverlay();
}
}
});
// Close overlay with Escape key
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape') {
closeShareOverlay();
}
});