Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
369 lines (292 loc) · 12 KB
/
Copy pathscript.js
File metadata and controls
369 lines (292 loc) · 12 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
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
var editando= false;
function trocarEditando(){
if(editando=="off"){
editando="on";
}else{
editando="off";
}
}
function moveAt(ball, pageX, pageY) {
ball.style.left = pageX - ball.offsetWidth / 2 + 'px';
ball.style.top = pageY - ball.offsetHeight / 2 + 'px';
}
function onDragStart(event) {
console.log('Drag start ID:', event.target.id);
event.dataTransfer.setData('text/plain', event.target.id);
console.log(lista);
}
function onDragOver(event) {
event.preventDefault();
}
let lista=[t1.id];
function onDrop(event) {
event.preventDefault();
const id = event.dataTransfer.getData('text/plain');
let draggableElement = document.getElementById(id)
if (lista.includes(draggableElement.id)) {
try {
draggableElement=draggableElement.cloneNode(true);
const dropzone = event.target;
draggableElement.id = "t2"+Math.random();
dropzone.appendChild(draggableElement);
draggableElement.style.position="absolute";
draggableElement.style.left = event.pageX - draggableElement.offsetWidth / 2 - 10+ 'px';
draggableElement.style.top =" 0%";
console.log('Drop zone ID:', dropzone.id);
event.dataTransfer.clearData();
} catch (error) {
console.error('Error appending draggable element:', error);
}
} else {
const dropzone = event.target;
dropzone.appendChild(draggableElement);
draggableElement.style.position="absolute";
draggableElement.style.left = event.pageX - draggableElement.offsetWidth / 2 - 10+ 'px';
draggableElement.style.top =" 0%";
event.dataTransfer.clearData();
console.error('Draggable element not found with ID: ' + id);
}
}
const noteMap = {
'A': 0,
'Bb': 1,
'B': 2,
'C': 3,
'C#': 4,
'D': 5,
'Eb': 6,
'E': 7,
'F': 8,
'F#': 9,
'G': 10,
'Ab': 11
};
let notasUsadas = []
function encontrarChavePorValor(valor) {
for (const chave in noteMap) {
if (noteMap[chave] === valor) {
return chave;
}
}
return null; // Valor não encontrado
}
function processarTexto() {
// Obter o texto do textarea
var inputText = document.getElementById('inputText').value;
inputText = inputText;
// Adicionar uma <div> antes de cada linha
var novoTexto = '<div style="height: 1.5em; align-items:center; position:relative; text-align:center;width:100%; display:flex;background-color:grey;" id="outputContainer" editable="false" ondrop="onDrop(event)" ondragover="onDragOver(event)"></div>' + inputText.replace(/\n/g, '<div style="display:flex; align-items:center; position:relative;height: 1.5em;text-align:center;width:100%;background-color:grey" id="outputContainer" ondrop="onDrop(event)" ondragover="onDragOver(event)"></div>');
// Exibir o texto formatado
document.getElementById('outputImage').innerHTML = '<div style="height: 1em;"></div>' + novoTexto;
}
function processarTexto() {
// Obter o texto do textarea
var inputText = document.getElementById('inputText').value;
inputText = inputText.split("\n");
// Limpar o conteúdo atual do outputImage
document.getElementById('outputImage').innerHTML = '';
// Iterar sobre as linhas do texto e adicionar divs alternadas ao outputImage
for (var i = 0; i < inputText.length; i++) {
// Adicionar div sem texto
var divWithoutText = document.createElement('div');
divWithoutText.style.height = '1.5em';
divWithoutText.style.alignItems = 'center';
divWithoutText.style.position = 'relative';
divWithoutText.style.textAlign = 'center';
divWithoutText.style.width = '100%';
divWithoutText.style.display = 'flex';
divWithoutText.style.backgroundColor = '#dbdbdb';
divWithoutText.style.margin = "0 0 0 0";
divWithoutText.id = 'outputContainer' + i; // Adiciona um ID único para cada div
divWithoutText.setAttribute('contenteditable', 'false');
divWithoutText.setAttribute('ondrop', 'onDrop(event)');
divWithoutText.setAttribute('ondragover', 'onDragOver(event)');
document.getElementById('outputImage').appendChild(divWithoutText);
// Adicionar div com texto
if( inputText[i]!=""){
var divWithText = document.createElement('div');
divWithText.textContent = inputText[i];
divWithText.setAttribute('contenteditable', 'true');
document.getElementById('outputImage').appendChild(divWithText);
}}
}
function adicionar(){
var inputText = document.getElementById('testetext').value;
const el = document.createElement('div');
el.setAttribute('draggable', true);
el.setAttribute('ondragstart', 'onDragStart(event)');
el.setAttribute('id', 't1'+Math.random());
el.classList.add('draggable');
el.style.height = "1.5em";
el.textContent=inputText;
el.style.backgroundColor = "red";
document.getElementById("armazemdeacordes").appendChild(el);
document.getElementById('testetext').value = "";
lista.push(el.id);
console.log(lista);
}
function addChord(){
var notesSelect = document.getElementById("notes");
var chordTypesSelect = document.getElementById("chordTypes");
var selectedNotes = Array.from(notesSelect.selectedOptions).map(option => option.value);
var selectedChordType = chordTypesSelect.value;
notasUsadas.push(selectedNotes);
var resultChord = selectedNotes.join("") + selectedChordType;
const el = document.createElement('div');
el.setAttribute('draggable', true);
el.setAttribute('ondragstart', 'onDragStart(event)');
el.setAttribute('id', 't1'+Math.random());
lista.push(el.id);
el.classList.add('draggable');
el.style.height = "1.5em";
el.textContent=resultChord;
el.style.color= "#7D4F68";
el.style.fontWeight= "bold";
el.style.margin = "0 0 0 0";
el.setAttribute('nota', noteMap[selectedNotes[0]])
el.setAttribute('type', selectedChordType)
document.getElementById("armazemdeacordes").appendChild(el);
console.log(lista);
}
function transporCima() {
const elementosComNota = document.querySelectorAll('[nota]');
elementosComNota.forEach(elemento => {
let valorNota = parseInt(elemento.getAttribute('nota')) + 1;
if (valorNota > 11) {
valorNota = valorNota - 12;
}
elemento.textContent =encontrarChavePorValor(valorNota)+ elemento.getAttribute('type');
elemento.setAttribute('nota', valorNota);
});
}
function transporBaixo() {
const elementosComNota = document.querySelectorAll('[nota]');
elementosComNota.forEach(elemento => {
let valorNota = parseInt(elemento.getAttribute('nota')) - 1;
if (valorNota <0) {
valorNota = valorNota + 12;
}
elemento.textContent =encontrarChavePorValor(valorNota)+ elemento.getAttribute('type');
elemento.setAttribute('nota', valorNota);
});
}
function printInfo(){
const areaID = "outputContainer";
var printContent = document.getElementById(areaID).innerHTML;
var originalContent = document.body.innerHTML;
document.body.innerHTML = printContent;
window.print();
document.body.innerHTML = originalContent;
}
function processarTitulo(){
var input = document.getElementById('inputTitulo').value;
document.getElementById('inputTitulo').value = "";
document.getElementById('titulo').innerHTML = input;
}
function deleteChord(event) {
// Check if dataTransfer is available before using it
if (event.dataTransfer) {
const id = event.dataTransfer.getData('text/plain');
let draggableElement = document.getElementById(id);
draggableElement.parentNode.removeChild(draggableElement);
}
}
document.addEventListener('click', function (event) {
// Verifica se o elemento clicado possui o atributo "contenteditable" igual a "true"
var isContentEditable = event.target && event.target.getAttribute('contenteditable') === 'true';
// Verifica se a variável global "editando" está definida como "true"
if (isContentEditable && editando) {
// Restante do seu código para tornar o conteúdo do elemento editável
event.target.setAttribute('contenteditable', 'true');
// Adiciona um evento de foco para quando o elemento se tornar editável
event.target.addEventListener('focus', function () {
// Adiciona um evento de desfoco para quando o elemento perder o foco
event.target.addEventListener('blur', function onBlur() {
// Atualiza o conteúdo do elemento se o usuário inseriu algo e remove os eventos de foco e desfoco
event.target.setAttribute('contenteditable', 'false');
event.target.removeEventListener('focus', onFocus);
event.target.removeEventListener('blur', onBlur);
// Se o usuário inseriu algo
if (event.target.textContent.trim() !== '') {
// Atualiza o conteúdo do elemento
event.target.textContent = event.target.textContent.trim();
} else {
// Se o usuário não inseriu nada, você pode decidir o que fazer aqui, como remover o elemento
// Neste exemplo, vamos definir um texto padrão
event.target.textContent = 'Novo Texto';
}
});
// Remove o evento de foco após ativá-lo
event.target.removeEventListener('focus', onFocus);
});
// Coloca o foco no elemento para iniciar a edição
event.target.focus();
}
});
function fontSelect(){
console.log("fontSelect");
var font = document.getElementById("Font-Select");
font = font.value;
if(font=="Default"){
var sampleText = document.getElementById("lixo");
var computedStyle = window.getComputedStyle(sampleText);
var fontFamily = computedStyle.getPropertyValue('font-family');
font = fontFamily;
}
document.getElementById("outputImage").style.fontFamily = font;
}
function save(){
// Get the HTML content of the specific div
var divContent = document.getElementById('outputContainer').outerHTML;
// Create a Blob containing the div content
var blob = new Blob([divContent], { type: 'text/html' });
// Create a temporary URL for the Blob
var url = URL.createObjectURL(blob);
// Create a link element
var link = document.createElement('a');
// Set the link's attributes
link.href = url;
link.download = 'your_file_name.html';
// Append the link to the document
document.body.appendChild(link);
// Trigger a click event on the link to start the download
link.click();
// Remove the link from the document
document.body.removeChild(link);
// Revoke the Blob URL to free up resources
URL.revokeObjectURL(url);
}
// Assume you have an input element of type file in your HTML
// Assume you have an input element of type file in your HTML
var fileInput = document.getElementById('fileInput');
// Add an event listener to the input element
fileInput.addEventListener('change', function (event) {
console.log("File selected!"); // Log to check if the event listener is triggered
// Get the selected file
var file = event.target.files[0];
// Check if a file was selected
if (file) {
console.log("File:", file); // Log to check if the file object is correct
// Create a FileReader
var reader = new FileReader();
// Set up the FileReader to handle the file content
reader.onload = function (e) {
// Get the content of the file
var fileContent = e.target.result;
console.log("File content:", fileContent); // Log the content to check if it's being read correctly
// Assume you have a div with the id "targetDiv" where you want to replace the content
var targetDiv = document.getElementById('outputContainer');
// Replace the content of the target div with the content from the file
targetDiv.innerHTML = fileContent;
};
// Set up another event listener for the FileReader to log any potential errors
reader.onerror = function (e) {
console.error("Error reading file:", e.target.error);
};
// Read the file as text
reader.readAsText(file);
}
});
function activateInput() {
document.getElementById('fileInput').click();
}