-
Notifications
You must be signed in to change notification settings - Fork 0
/
card.html
421 lines (374 loc) · 14 KB
/
card.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#000000">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="apple-mobile-web-app-capable" content="yes">
<title>eCard</title>
<link rel="apple-touch-icon" sizes="180x180" href="/favicons/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicons/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicons/favicon-16x16.png">
<link rel="manifest" href="/site.webmanifest">
<style>
* {
box-sizing: border-box;
}
html {
height: 100vh;
width: 100vw;
margin:0;
padding:0;
background-color: black;
color:black;
-ms-overflow-style: none; /* Internet Explorer, Edge */
scrollbar-width: none; /* Firefox */
overflow-x: hidden;
overscroll-behavior: contain;
}
::-webkit-scrollbar {
display: none; /* Chrome, Safari, Opera */
}
body {
/* background-color: black; */
color:white;
width: 100%;
height:100vh;
margin:0;
padding:4px;
font-family: Helvetica, Arial, sans-serif;
font-size: 12pt;
/* display:flex;
flex-direction: column;
align-content: center;
justify-content: center; */
overflow-x: hidden;
overflow-y: scroll;
}
@media (orientation: landscape) {
body {
max-width: 3.5in;
margin: auto;
}
}
#card {
border-radius:8px;
margin:0;
background-color:#222;
width:100%;
/* aspect-ratio: 3.5/2; */
min-height: max-content;
}
#card #banner {
background-image: url('cardAssets/banner.jpg');
background-position: center; /* Center the image */
background-repeat: no-repeat; /* Do not repeat the image */
background-size: cover;
position:relative;
width:100%;
height:50%;
border:1px solid gray;
border-radius:8px;
background-color: #444;
aspect-ratio: 3.5/1;
}
#card #banner #picture {
position:absolute;
left:20px;
bottom:-8px;
height:90%;
aspect-ratio:1/1;
border-radius:50%;
background-color: white;
}
#card h1, #card h2, #card pre {
margin:0;
margin-left:10px;
padding:none;
}
#card #name {
margin:10px;
margin-bottom:0;
font-size: 14pt;
font-weight: bold;
}
#card #universalUsername {
margin:0 10px;
}
#card #headline {
margin-top:10px;
margin-bottom:4px;
font-size: 12pt;
font-weight: normal;
}
#card #bio {
color: lightgray;
font-size: 10pt;
border-left: 2px solid gray;
margin-left:12px;
padding-left: 4px;
}
#card #locationContainer {
margin:0 10px;
margin-top: 4px;
display:flex;
flex-direction: row;
font-size: 10pt;
}
#card #locationContainer svg {
margin-right:4px;
height: 10pt;
aspect-ratio: 1/1;
fill:white;
stroke:none;
}
#card #locationContainer p {
margin:0;
}
#card #interests {
width:100%;
height:fit-content;
display:flex;
flex-direction: row;
padding:8px;
}
#card #interests .interest {
background-image: linear-gradient(#444, #444, black);
border-radius: 10px;
height:20px;
width:fit-content;
margin:0 4px;
padding:4px 8px;
font-size: 8pt;
font-weight: bold;
color: lightgray;
}
.row {
width:100%;
display: flex;
flex-direction: row;
padding:8px;
}
.row > a {
display: flex;
flex-direction: column;
align-content: space-evenly;
justify-content: space-evenly;
position: relative;
flex:1;
margin-left:22px;
padding-left: 33px;
height:44px;
background-color: #222;
color:white;
border-radius: 8px;
text-decoration: none;
}
.row > a h1 {
margin:0;
font-size: 12pt;
}
.row > a p {
margin:0;
font-size: 10pt;
color:lightgray;
}
.row .icon {
position:absolute;
display:flex;
height:100%;
aspect-ratio:1/1;
top:0; left:-22px;
/* border-radius:50%; */
background-color:#444;
padding:auto;
overflow:visible;
}
.row .arrow {
position:absolute;
display:flex;
height:100%;
aspect-ratio:1/1;
top:0; right:0;
background-color:transparent;
padding:auto;
overflow:hidden;
}
.row .icon svg,
.row .arrow svg
{
width: 50%;
height: auto;
fill:white;
stroke: white;
margin:auto;
overflow:visible;
}
.row .icon svg .shaddow {
fill:white;
}
.row .icon svg.mail {
stroke:#444;
}
</style>
</head>
<body>
<div id="card">
<div id="banner">
<img id="picture" src="cardAssets/profile.jpg"/>
</div>
<h1 id="name">Daniel ████</h1>
<p id="universalUsername"></p>
<h2 id="headline">Let's connect</h2>
<pre id="bio"></pre>
<div id="locationContainer">
<svg version="1.0" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 64 64" enable-background="new 0 0 64 64" xml:space="preserve">
<path d="M32,0C18.746,0,8,10.746,8,24c0,5.219,1.711,10.008,4.555,13.93c0.051,0.094,0.059,0.199,0.117,0.289l16,24C29.414,63.332,30.664,64,32,64s2.586-0.668,3.328-1.781l16-24c0.059-0.09,0.066-0.195,0.117-0.289C54.289,34.008,56,29.219,56,24C56,10.746,45.254,0,32,0z M32,32c-4.418,0-8-3.582-8-8s3.582-8,8-8s8,3.582,8,8S36.418,32,32,32z"/>
</svg>
<p>Los Angeles, CA</p>
</div>
<div id="interests"></div>
</div>
<div class="row">
<a id="saveContactButton" style="box-shadow: 0 2px 0 0 gray; color:white; font-weight:bold; background-color: #444; border:none; border-radius:8px; margin:8px; padding:0; height:44px; flex:1;">
<p style="margin:auto;">Save Contact</p>
<div class="arrow">
<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<g>
<path d="M6 21H18M12 3V17M12 17L17 12M12 17L7 12" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</g>
</svg>
</div>
</a>
</div>
<script>
const fullName = document.getElementById("name");
const universalUsername = document.getElementById("universalUsername");
const headline = document.getElementById("headline");
const bio = document.getElementById("bio");
const interests = document.getElementById("interests");
const saveContactButton = document.getElementById("saveContactButton");
// Function to fetch the SVG file content
async function fetchSVG(svgPath) {
try {
const response = await fetch(svgPath);
return await response.text(); // Return the SVG content as text
} catch (error) {
console.error('Error fetching SVG:', error);
return '';
}
}
function generateVCard(jsonData) {
let vCard = "BEGIN:VCARD\nVERSION:3.0\n";
// Add details
const details = jsonData.details[0];
if (details.name) vCard += `FN:${details.name}\n`;
if (details.universalUsername) vCard += `NICKNAME:${details.universalUsername}\n`;
if (details.headline) vCard += `TITLE:${details.headline}\n`;
if (details.bio) vCard += `NOTE:${details.bio}\n`;
if (details.location) vCard += `ADR:;;${details.location}\n`;
if (details.interests) vCard += `CATEGORIES:${details.interests.split(", ").join(",")}\n`;
// Add contacts
jsonData.contacts.forEach(contact => {
if (contact.display && contact.link) {
if (contact.contactType === "Phone") {
vCard += `TEL;TYPE=cell:${contact.value}\n`;
} else if (contact.contactType === "Email") {
vCard += `EMAIL;TYPE=internet:${contact.value}\n`;
} else if (contact.contactType === "Website") {
vCard += `URL:${contact.link}\n`;
} else {
vCard += `X-SOCIALPROFILE;TYPE=${contact.contactType}:${contact.link}\n`;
}
}
});
vCard += "END:VCARD";
return vCard;
}
// Function to fetch contact data from contacts.json and render it on the webpage
async function fetchAndRenderContacts() {
try {
const response = await fetch('cardAssets/contacts.json'); // Fetch the JSON file
const contactData = await response.json(); // Parse the JSON data
const contactList = document.querySelector('body'); // Get the HTML element to display contact info
for (const details of contactData.details) {
fullName.innerHTML = details.name;
document.title = details.name;
universalUsername.innerHTML = details.universalUsername;
headline.innerHTML = details.headline;
bio.innerHTML = details.bio;
interestList = details.interests;
const interestsArray = interestList.split(", ");
for (let interest of interestsArray) {
const interestDiv = document.createElement('div');
interestDiv.classList.add("interest");
interestDiv.innerHTML = interest;
interests.appendChild(interestDiv);
}
}
// Iterate over the contacts and display using a for...of loop to allow async/await in the loop
for (const contact of contactData.contacts) {
if (contact.display && contact.value) {
const item = document.createElement('div');
item.classList.add("row");
const button = document.createElement('a');
button.href = contact.link;
const icon = document.createElement('div');
icon.classList.add("icon");
// Fetch the SVG icon and insert it inline
const svgURL = "cardAssets/icons/" + contact.contactType + ".svg";
const svgContent = await fetchSVG(svgURL);
icon.innerHTML = svgContent; // Insert the SVG content
icon.src = contact.icon;
icon.alt = `${contact.contactType} icon`;
if (["Phone", "Email", "Website"].includes(contact.contactType)) {
icon.style.borderRadius = "50%"; // circle icon
} else {
icon.style.borderRadius = "8px"; // square (app) icon
}
button.appendChild(icon);
const arrow = document.createElement('div');
arrow.classList.add("arrow");
const svgArrow = await fetchSVG("cardAssets/icons/right-arrow.svg");
arrow.innerHTML = svgArrow; // Insert the SVG content
// arrow.src = contact.icon;
arrow.alt = `${contact.contactType} icon`;
button.appendChild(arrow);
const name = document.createElement('h1')
name.textContent = contact.contactType;
button.appendChild(name);
const details = document.createElement('p')
details.textContent = contact.value;
button.appendChild(details);
item.appendChild(button);
contactList.appendChild(item);
}
};
const vCardData = generateVCard(contactData);
// Create a Blob from the vCard data
const blob = new Blob([vCardData], { type: 'text/vcard' });
saveContactButton.href = URL.createObjectURL(blob);
saveContactButton.download = 'contact.vcf'; // Set the file name
} catch (error) {
console.error('Error fetching contact data:', error);
}
}
fetchAndRenderContacts(); // Call the function to fetch and render the contacts when the page loads
// Function to request fullscreen
function requestFullscreen() {
const elem = document.documentElement; // This selects the <html> element (the entire document)
if (elem.requestFullscreen) {
elem.requestFullscreen();
} else if (elem.mozRequestFullScreen) { // Firefox
elem.mozRequestFullScreen();
} else if (elem.webkitRequestFullscreen) { // Chrome, Safari, and Opera
elem.webkitRequestFullscreen();
} else if (elem.msRequestFullscreen) { // IE/Edge
elem.msRequestFullscreen();
}
}
requestFullscreen();
</script>
</body>
</html>