Skip to content

Commit

Permalink
add func downloadVCard
Browse files Browse the repository at this point in the history
  • Loading branch information
ledangtrung committed Dec 9, 2024
1 parent 3bcc9f4 commit 8259a40
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion js/rt-html-abs.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ function openLocation(element) {
App.callActionButton(json);
}

function shareContent(element) {
function (element) {
const actionData = {
actionID: 9004,
orderNumber: 1,
Expand Down Expand Up @@ -276,6 +276,34 @@ function openChat(element) {
App.callActionButton(json);
}

function downloadVCard() {
// Get VCard content and ensure proper line endings
const vCardContent = document.getElementById('vcardTemplate').textContent;

// Extract FN field for filename
const fnMatch = vCardContent.match(/FN;CHARSET=utf-8:(.*)/);
const filename = fnMatch ? fnMatch[1].trim() : 'contact';

// Create blob with proper encoding
const blob = new Blob([vCardContent], {
type: 'text/vcard;charset=utf-8'
});

// Create download link
const downloadUrl = URL.createObjectURL(blob);
const downloadLink = document.createElement('a');
downloadLink.href = downloadUrl;
downloadLink.download = `${filename}.vcf`;

// Trigger download
document.body.appendChild(downloadLink);
downloadLink.click();
document.body.removeChild(downloadLink);

// Cleanup
URL.revokeObjectURL(downloadUrl);
}

document.addEventListener('DOMContentLoaded', () => {
const buttons = document.querySelectorAll('.btn');
buttons.forEach(button => {
Expand Down

0 comments on commit 8259a40

Please sign in to comment.