Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
199 lines (164 loc) · 7.62 KB
/
Copy pathscript.js
File metadata and controls
199 lines (164 loc) · 7.62 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
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
// Function to handle adding elements to the editor
function addElement(elementType) {
const headerBlock = document.getElementById('headerBlock');
const imageBlock = document.getElementById('imageBlock');
const descriptionBlock = document.getElementById('descriptionBlock');
if (elementType === 'Header') {
headerBlock.classList.remove('hidden');
document.getElementById('headerInput').addEventListener('input', function() {
updatePreview();
});
document.getElementById('cancelHeaderBtn').addEventListener('click', function() {
headerBlock.classList.add('hidden');
document.getElementById('headerInput').value = '';
updatePreview();
});
}
else if (elementType === 'Image') {
imageBlock.classList.remove('hidden');
document.getElementById('imageInput').addEventListener('change', function(e) {
if (e.target.files && e.target.files[0]) {
const reader = new FileReader();
reader.onload = function(event) {
const uploadedImageName = document.getElementById('uploadedImageName');
uploadedImageName.textContent = e.target.files[0].name;
// Show the image preview on the right side
const imagePreview = document.getElementById('preview');
if (imagePreview.firstChild) {
imagePreview.removeChild(imagePreview.firstChild);
}
const imagePreviewDiv = document.createElement('img');
imagePreviewDiv.src = event.target.result;
imagePreviewDiv.classList.add('w-full', 'h-auto', 'mt-4');
updatePreview();
};
reader.readAsDataURL(e.target.files[0]);
}
});
document.getElementById('cancelImageBtn').addEventListener('click', function() {
imageBlock.classList.add('hidden');
document.getElementById('imageInput').value = '';
const uploadedImageName = document.getElementById('uploadedImageName');
uploadedImageName.textContent = '';
updatePreview();
});
}
else if (elementType === 'Description') {
descriptionBlock.classList.remove('hidden');
document.getElementById('descriptionInput').addEventListener('input', function() {
updatePreview();
});
document.getElementById('cancelDescriptionBtn').addEventListener('click', function() {
descriptionBlock.classList.add('hidden');
document.getElementById('descriptionInput').value = '';
updatePreview();
});
}
}
// Function to apply text color to the header in the right-side preview
function applyTextColor(color) {
const headerInput = document.getElementById('headerInput');
const previewHeader = document.getElementById('previewHeader');
if (headerInput.value.trim() !== '') {
previewHeader.innerText = headerInput.value;
}
previewHeader.style.color = headerTextColor = color;
}
// Function to apply text alignment to the header in the right-side preview
function applyTextAlignment(align) {
const headerInput = document.getElementById('headerInput');
const previewHeader = document.getElementById('previewHeader');
if (headerInput.value.trim() !== '') {
previewHeader.innerText = headerInput.value;
}
previewHeader.style.textAlign = align;
}
let headerTextColor = 'black'; // Default header text color
let imageObjectURL = null; // To store the created object URL for the image
// Function to update the preview with header, image, and description
function updatePreview() {
const headerInput = document.getElementById('headerInput');
const imageInput = document.getElementById('imageInput');
const descriptionInput = document.getElementById('descriptionInput');
// Update header in the preview
const previewHeader = document.getElementById('previewHeader');
previewHeader.innerText = headerInput.value;
// Update image in the preview
const previewImage = document.getElementById('previewImage');
if (imageInput.files.length > 0) {
const file = imageInput.files[0];
// Release the previous object URL if it exists
if (imageObjectURL) {
URL.revokeObjectURL(imageObjectURL);
}
// Create a new object URL for the current image
imageObjectURL = URL.createObjectURL(file);
previewImage.innerHTML = `<img src="${imageObjectURL}" alt="Uploaded Image">`;
} else {
// Clear the preview if no image is selected
previewImage.innerHTML = '';
}
// Update description in the preview
const previewDescription = document.getElementById('previewDescription');
previewDescription.innerText = descriptionInput.value;
}
// Event listener for "Add Header" button
document.getElementById('headerBtn').addEventListener('click', function() {
const headerBlock = document.getElementById('headerBlock');
headerBlock.classList.remove('hidden');
});
// Event listeners for text color buttons in the header section
document.getElementById('blueBtn').addEventListener('click', function() {
applyTextColor('blue');
});
document.getElementById('greenBtn').addEventListener('click', function() {
applyTextColor('green');
});
document.getElementById('redBtn').addEventListener('click', function() {
applyTextColor('red');
});
// Event listeners for text alignment buttons in the header section
document.getElementById('leftAlignBtn').addEventListener('click', function() {
applyTextAlignment('left');
});
document.getElementById('centerAlignBtn').addEventListener('click', function() {
applyTextAlignment('center');
});
document.getElementById('rightAlignBtn').addEventListener('click', function() {
applyTextAlignment('right');
});
// Event listener for header input to update the preview
document.getElementById('headerInput').addEventListener('input', updatePreview);
// Event listener for image input to update the preview
document.getElementById('imageInput').addEventListener('change', updatePreview);
// Event listener for description input to update the preview
document.getElementById('descriptionInput').addEventListener('input', updatePreview);
// Function to handle clearing the editor
function clearEditor() {
const headerInput = document.getElementById('headerInput');
const imageInput = document.getElementById('imageInput');
const descriptionInput = document.getElementById('descriptionInput');
const uploadedImageName = document.getElementById('uploadedImageName');
const imagePreview = document.getElementById('imagePreview');
headerInput.value = '';
if (imageInput) {
imageInput.value = '';
}
uploadedImageName.textContent = '';
if (imagePreview.firstChild) {
imagePreview.removeChild(imagePreview.firstChild);
}
descriptionInput.value = '';
updatePreview();
}
// Function to handle downloading the poster
function downloadPoster() {
}
// Event listeners for adding elements, updating preview, and downloading
document.addEventListener('DOMContentLoaded', () => {
document.getElementById('downloadBtn').addEventListener('click', downloadPoster);
document.getElementById('clearBtn').addEventListener('click', clearEditor);
document.getElementById('headerBtn').addEventListener('click', () => addElement('Header'));
document.getElementById('imageBtn').addEventListener('click', () => addElement('Image'));
document.getElementById('descriptionBtn').addEventListener('click', () => addElement('Description'));
});