- Changed from gray-700 to blue-600 (matches site theme) - Added shadow-sm for better definition - Buttons now clearly visible on white card background
76 lines
2.4 KiB
JavaScript
76 lines
2.4 KiB
JavaScript
/**
|
|
* Share CTA functionality
|
|
* Professional, quiet sharing mechanism
|
|
* CSP-compliant (no inline handlers)
|
|
*/
|
|
|
|
(function() {
|
|
'use strict';
|
|
|
|
// Wait for DOM to be ready
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', initShare);
|
|
} else {
|
|
initShare();
|
|
}
|
|
|
|
function initShare() {
|
|
// Copy link to clipboard
|
|
const copyButtons = document.querySelectorAll('[data-action="copy-link"]');
|
|
copyButtons.forEach(button => {
|
|
button.addEventListener('click', async () => {
|
|
const url = window.location.href;
|
|
|
|
try {
|
|
await navigator.clipboard.writeText(url);
|
|
|
|
// Visual feedback
|
|
const originalText = button.textContent;
|
|
const originalClasses = button.className;
|
|
|
|
button.textContent = 'Link Copied';
|
|
button.className = 'bg-green-600 hover:bg-green-700 text-white px-6 py-2.5 rounded-lg font-medium transition-colors shadow-sm';
|
|
|
|
setTimeout(() => {
|
|
button.textContent = originalText;
|
|
button.className = originalClasses;
|
|
}, 2000);
|
|
} catch (err) {
|
|
console.error('Failed to copy link:', err);
|
|
// Fallback: show alert with URL
|
|
alert('Copy this link: ' + url);
|
|
}
|
|
});
|
|
});
|
|
|
|
// Email share
|
|
const emailButtons = document.querySelectorAll('[data-action="email-share"]');
|
|
emailButtons.forEach(button => {
|
|
button.addEventListener('click', () => {
|
|
const url = window.location.href;
|
|
const subject = encodeURIComponent('Thought you might find this useful');
|
|
const body = encodeURIComponent(
|
|
'I thought this might be relevant to your work:\n\n' +
|
|
'Tractatus - AI Safety Framework\n' +
|
|
url + '\n\n' +
|
|
'It addresses structural AI governance through architectural constraints.'
|
|
);
|
|
|
|
window.location.href = `mailto:?subject=${subject}&body=${body}`;
|
|
});
|
|
});
|
|
|
|
// LinkedIn share
|
|
const linkedinButtons = document.querySelectorAll('[data-action="linkedin-share"]');
|
|
linkedinButtons.forEach(button => {
|
|
button.addEventListener('click', () => {
|
|
const url = encodeURIComponent(window.location.href);
|
|
window.open(
|
|
`https://www.linkedin.com/sharing/share-offsite/?url=${url}`,
|
|
'_blank',
|
|
'width=600,height=600'
|
|
);
|
|
});
|
|
});
|
|
}
|
|
})();
|