-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
87 lines (71 loc) · 3.15 KB
/
script.js
File metadata and controls
87 lines (71 loc) · 3.15 KB
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
document.addEventListener("DOMContentLoaded", () => {
const iframe = document.querySelector(".cv-iframe");
// preview lastet
iframe.addEventListener("load", () => {
const nameInput = document.getElementById("name");
const emailInput = document.getElementById("email");
const phoneInput = document.getElementById("phone");
function updateCV() {
const cvDoc = iframe.contentDocument || iframe.contentWindow.document;
cvDoc.getElementById("cv-name").textContent = nameInput.value;
cvDoc.getElementById("cv-email").textContent = emailInput.value;
cvDoc.getElementById("cv-phone").textContent = phoneInput.value;
}
nameInput.addEventListener("input", updateCV);
emailInput.addEventListener("input", updateCV);
phoneInput.addEventListener("input", updateCV);
});
// om meg
const aboutMeText = document.getElementById("about-me-text");
function updateAboutMePreview() {
const cvDoc = iframe.contentDocument || iframe.contentWindow.document;
const content = aboutMeText.value;
const container = cvDoc.getElementById("cv-about-me");
container.innerHTML = content ? `<p>${content}</p>` : "<p>Fortell litt om deg selv.</p>";
}
aboutMeText.addEventListener("input", updateAboutMePreview);
// utdanning
const educationList = document.getElementById("education-list");
function addEducation() {
const group = document.createElement("div");
group.classList.add("input-group");
const eduInput = document.createElement("input");
eduInput.type = "text";
eduInput.placeholder = "Navn på Utdanning";
const startInput = document.createElement("input");
startInput.type = "text";
startInput.placeholder = "Start";
const endInput = document.createElement("input");
endInput.type = "text";
endInput.placeholder = "Slutt";
[eduInput, startInput, endInput].forEach(input =>
input.addEventListener("input", updateEducationPreview)
);
const removeBtn = document.createElement("button");
removeBtn.classList.add("remove-btn");
removeBtn.textContent = "Remove";
removeBtn.onclick = () => {
educationList.removeChild(group);
updateEducationPreview();
};
group.append(eduInput, startInput, endInput, removeBtn);
educationList.appendChild(group);
updateEducationPreview();
}
function updateEducationPreview() {
const cvDoc = iframe.contentDocument || iframe.contentWindow.document;
const inputGroups = educationList.querySelectorAll(".input-group");
const items = [];
inputGroups.forEach(group => {
const [edu, start, end] = group.querySelectorAll("input");
if (edu.value || start.value || end.value) {
items.push(`• ${edu.value} - ${start.value} - ${end.value}`);
}
});
const container = cvDoc.getElementById("cv-education");
if (container) {
container.innerHTML = "<h2>Utdanninger:</h2>" + items.join("<br>");
}
}
document.getElementById("add-education").addEventListener("click", addEducation);
});