-
Notifications
You must be signed in to change notification settings - Fork 0
/
uiHandlers.js
75 lines (59 loc) · 2.57 KB
/
uiHandlers.js
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
// uiHandlers.js
console.log("uiHandlers.js loaded");
document.addEventListener('DOMContentLoaded', function () {
const bulletPointStyleBtn = document.getElementById('bulletPointStyle');
const helpButton = document.getElementById('helpButton');
const closeModal = document.getElementById('closeModal');
const copyTextBtn = document.getElementById('copyTextBtn');
const textBlock = document.getElementById('textBlock');
// Initially disable the bulletPointStyle button if the textarea is empty
bulletPointStyleBtn.disabled = !textBlock.value.trim();
// Input event for textarea
textBlock.addEventListener('input', () => {
// Disable the bulletPointStyle button if textarea is empty
bulletPointStyleBtn.disabled = !textBlock.value.trim();
});
bulletPointStyleBtn.addEventListener('click', () => {
const text = textBlock.value;
parent.postMessage({ pluginMessage: { type: 'create-text-layers', text } }, '*');
});
helpButton.addEventListener('click', function () {
const helpModal = document.getElementById('helpModal');
helpModal.style.display = "block";
});
closeModal.addEventListener('click', function () {
const helpModal = document.getElementById('helpModal');
helpModal.style.display = "none";
});
window.onclick = function (event) {
const helpModal = document.getElementById('helpModal');
if (event.target == helpModal) {
helpModal.style.display = "none";
}
};
copyTextBtn.addEventListener('click', function () {
const guideText = document.getElementById('guideText');
if (navigator.clipboard && window.isSecureContext) {
// Use the Clipboard API when available
navigator.clipboard.writeText(guideText.innerText).then(() => {
alert('Text copied to clipboard');
}).catch(err => {
console.error('Error copying text: ', err);
});
} else {
// Fallback method for copying text
let textArea = document.createElement("textarea");
textArea.value = guideText.innerText;
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
try {
let successful = document.execCommand('copy');
alert('Text copied to clipboard');
} catch (err) {
console.error('Fallback: Oops, unable to copy', err);
}
document.body.removeChild(textArea);
}
});
});