Continues the Bookshelf history. The three plugins tracked there are consolidated into umbra-bookshelf/ and this repository becomes the canonical home for the plugin and the theme. bd-bookshelf/ -> theme/ separate artifact, name unchanged (root specs) -> umbra-bookshelf/spec/ aligned to Umbra Bookshelf old plugin zips -> archive/pre-umbra-releases/ Adds a repository README and drops the Bookshelf closure notice.
150 lines
4.6 KiB
JavaScript
150 lines
4.6 KiB
JavaScript
// Copyright 2026 Umbra Tools (umbratools.com)
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
/**
|
|
* Social Share JavaScript
|
|
*
|
|
* @package BD_Murphy
|
|
*/
|
|
(function() {
|
|
'use strict';
|
|
|
|
var shareContainer = document.querySelector('.social-share-buttons');
|
|
if (!shareContainer) {
|
|
return;
|
|
}
|
|
|
|
// Copy link button
|
|
var copyBtn = shareContainer.querySelector('.share-copy');
|
|
if (copyBtn) {
|
|
copyBtn.addEventListener('click', function() {
|
|
var url = copyBtn.dataset.url;
|
|
if (navigator.clipboard && navigator.clipboard.writeText) {
|
|
navigator.clipboard.writeText(url).then(function() {
|
|
showToast('Link copied to clipboard!');
|
|
}).catch(function() {
|
|
fallbackCopy(url);
|
|
});
|
|
} else {
|
|
fallbackCopy(url);
|
|
}
|
|
});
|
|
}
|
|
|
|
function fallbackCopy(text) {
|
|
var textArea = document.createElement('textarea');
|
|
textArea.value = text;
|
|
textArea.style.position = 'fixed';
|
|
textArea.style.left = '-9999px';
|
|
textArea.style.top = '-9999px';
|
|
document.body.appendChild(textArea);
|
|
textArea.focus();
|
|
textArea.select();
|
|
|
|
try {
|
|
var successful = document.execCommand('copy');
|
|
if (successful) {
|
|
showToast('Link copied to clipboard!');
|
|
} else {
|
|
showToast('Failed to copy link');
|
|
}
|
|
} catch (err) {
|
|
showToast('Failed to copy link');
|
|
}
|
|
|
|
document.body.removeChild(textArea);
|
|
}
|
|
|
|
function showToast(message) {
|
|
var toast = document.createElement('div');
|
|
toast.className = 'share-toast';
|
|
toast.textContent = message;
|
|
document.body.appendChild(toast);
|
|
|
|
setTimeout(function() {
|
|
toast.classList.add('show');
|
|
}, 10);
|
|
|
|
setTimeout(function() {
|
|
toast.classList.remove('show');
|
|
setTimeout(function() {
|
|
if (toast.parentNode) {
|
|
document.body.removeChild(toast);
|
|
}
|
|
}, 300);
|
|
}, 2000);
|
|
}
|
|
|
|
// Web Share API
|
|
if (navigator.share) {
|
|
var webShareBtn = shareContainer.querySelector('.share-webshare');
|
|
if (webShareBtn) {
|
|
webShareBtn.addEventListener('click', function(e) {
|
|
e.preventDefault();
|
|
var url = webShareBtn.dataset.url || window.location.href;
|
|
var title = webShareBtn.dataset.title || document.title;
|
|
|
|
navigator.share({
|
|
title: title,
|
|
url: url
|
|
}).catch(function(err) {
|
|
if (err.name !== 'AbortError') {
|
|
console.log('Error sharing:', err);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
// Share button on book page
|
|
var shareBtn = document.querySelector('.book-page-info .share-btn');
|
|
if (shareBtn) {
|
|
shareBtn.addEventListener('click', function() {
|
|
var url = shareBtn.dataset.url || window.location.href;
|
|
|
|
if (navigator.clipboard && navigator.clipboard.writeText) {
|
|
navigator.clipboard.writeText(url).then(function() {
|
|
showToast('Link copied to clipboard!');
|
|
}).catch(function() {
|
|
fallbackCopy(url);
|
|
});
|
|
} else {
|
|
fallbackCopy(url);
|
|
}
|
|
});
|
|
}
|
|
|
|
// Format toggle
|
|
var formatBtns = document.querySelectorAll('.format-btn');
|
|
formatBtns.forEach(function(btn) {
|
|
btn.addEventListener('click', function() {
|
|
var format = btn.dataset.format;
|
|
var container = btn.closest('.book-entry, .book-page-content, .book-retailer-links');
|
|
|
|
if (!container) {
|
|
return;
|
|
}
|
|
|
|
// Update active state
|
|
container.querySelectorAll('.format-btn').forEach(function(b) {
|
|
b.classList.remove('active');
|
|
b.setAttribute('aria-selected', 'false');
|
|
});
|
|
btn.classList.add('active');
|
|
btn.setAttribute('aria-selected', 'true');
|
|
|
|
// Filter retailer links
|
|
var retailerLinks = container.querySelectorAll('.book-retailer-links .retailer-link');
|
|
retailerLinks.forEach(function(link) {
|
|
var linkFormat = link.dataset.format;
|
|
if (!linkFormat || linkFormat === format) {
|
|
link.style.display = '';
|
|
} else {
|
|
link.style.display = 'none';
|
|
}
|
|
});
|
|
});
|
|
});
|
|
|
|
})();
|