DMS/static/scripts.js
2025-05-01 00:24:26 +08:00

65 lines
2.5 KiB
JavaScript

// Document Management System JavaScript
document.addEventListener('DOMContentLoaded', function() {
// Auto-dismiss flash messages after 5 seconds
window.setTimeout(function() {
document.querySelectorAll('.alert').forEach(function(alert) {
if (bootstrap && bootstrap.Alert) {
var bsAlert = new bootstrap.Alert(alert);
bsAlert.close();
} else {
alert.style.display = 'none';
}
});
}, 5000);
// Copy link functionality
window.copyLink = function(elementId) {
var copyText = document.getElementById(elementId);
if (copyText) {
copyText.select();
copyText.setSelectionRange(0, 99999);
navigator.clipboard.writeText(copyText.value);
// Show a temporary tooltip
var tooltip = document.createElement("div");
tooltip.innerHTML = "Copied!";
tooltip.style.position = "fixed";
tooltip.style.backgroundColor = "#4CAF50";
tooltip.style.color = "white";
tooltip.style.padding = "5px 10px";
tooltip.style.borderRadius = "5px";
tooltip.style.zIndex = "1000";
tooltip.style.top = (event.clientY - 30) + "px";
tooltip.style.left = event.clientX + "px";
document.body.appendChild(tooltip);
setTimeout(function() {
document.body.removeChild(tooltip);
}, 2000);
}
};
// Email sharing functionality
window.shareViaEmail = function(filename, url) {
var subject = "Shared Document: " + filename;
var body = "I'm sharing a document with you: " + filename + "\n\nYou can access it here: " + url;
window.location.href = "mailto:?subject=" + encodeURIComponent(subject) + "&body=" + encodeURIComponent(body);
};
// WhatsApp sharing functionality
window.shareViaWhatsApp = function(filename, url) {
var text = "I'm sharing a document with you: " + filename + "\n\nYou can access it here: " + url;
window.open("https://wa.me/?text=" + encodeURIComponent(text), "_blank");
};
// Confirm delete
var deleteButtons = document.querySelectorAll('[data-confirm]');
deleteButtons.forEach(function(button) {
button.addEventListener('click', function(e) {
if (!confirm(this.getAttribute('data-confirm'))) {
e.preventDefault();
}
});
});
});