Spaces:
Sleeping
Sleeping
drakosfire
commited on
Commit
•
cf0d79c
1
Parent(s):
b1fa4de
fixed bug where descriptionTextarea in unlock textareas wasn't trageting globablly. Function targets entire document now
Browse files- scripts.js +31 -21
scripts.js
CHANGED
@@ -63,7 +63,8 @@ document.addEventListener("DOMContentLoaded", function() {
|
|
63 |
const userInput = document.getElementById('user-description').value;
|
64 |
// Clear the block container before inserting new blocks
|
65 |
blockContainerPage.innerHTML = '';
|
66 |
-
|
|
|
67 |
|
68 |
fetch('http://127.0.0.1:5000/process-description', {
|
69 |
method: 'POST',
|
@@ -352,42 +353,38 @@ document.addEventListener("DOMContentLoaded", function() {
|
|
352 |
});
|
353 |
}
|
354 |
function lockTextareas() {
|
355 |
-
const textareas =
|
356 |
|
357 |
textareas.forEach(textarea => {
|
358 |
textarea.setAttribute('disabled', true);
|
359 |
-
console.log(`Textarea with ID "${textarea.id}" is now disabled: ${textarea.disabled}`);
|
360 |
});
|
361 |
|
362 |
-
const descriptionTextareas =
|
363 |
|
364 |
descriptionTextareas.forEach(descriptionTextarea => {
|
365 |
descriptionTextarea.removeAttribute('contenteditable');
|
366 |
-
console.log(`Description textarea with ID "${descriptionTextarea.id}" is now enabled: ${!descriptionTextarea.contenteditable}`);
|
367 |
});
|
368 |
|
369 |
console.log('All textareas have been locked.');
|
370 |
}
|
371 |
|
372 |
function unlockTextareas() {
|
373 |
-
const textareas =
|
374 |
|
375 |
textareas.forEach(textarea => {
|
376 |
textarea.removeAttribute('disabled');
|
377 |
-
console.log(`Textarea with ID "${textarea.id}" is now enabled: ${!textarea.disabled}`);
|
378 |
});
|
379 |
|
380 |
-
const descriptionTextareas =
|
381 |
|
382 |
descriptionTextareas.forEach(descriptionTextarea => {
|
383 |
-
descriptionTextarea.
|
384 |
-
console.log(`
|
385 |
});
|
386 |
|
387 |
console.log('All textareas have been unlocked.');
|
388 |
}
|
389 |
|
390 |
-
|
391 |
function handleDragStart(e) {
|
392 |
lockTextareas();
|
393 |
const target = e.target.closest('.block-item, .block-content');
|
@@ -503,6 +500,7 @@ document.addEventListener("DOMContentLoaded", function() {
|
|
503 |
// Ensure the original block exists before proceeding
|
504 |
if (!originalBlock || !newPage) {
|
505 |
console.error(`Block with ID ${blockId} on page ${originalPageId} not found`);
|
|
|
506 |
return;
|
507 |
}
|
508 |
|
@@ -534,9 +532,11 @@ document.addEventListener("DOMContentLoaded", function() {
|
|
534 |
if (offset > bounding.height / 2) {
|
535 |
console.log('Inserting after the target');
|
536 |
target.parentNode.insertBefore(newBlockContent, target.nextSibling);
|
|
|
537 |
} else {
|
538 |
console.log('Inserting before the target');
|
539 |
target.parentNode.insertBefore(newBlockContent, target);
|
|
|
540 |
}
|
541 |
|
542 |
// Remove highlight borders
|
@@ -545,6 +545,7 @@ document.addEventListener("DOMContentLoaded", function() {
|
|
545 |
} else {
|
546 |
console.log('No valid drop target found, appending to the end');
|
547 |
newPage.querySelector('.block.monster.frame.wide').appendChild(newBlockContent);
|
|
|
548 |
}
|
549 |
|
550 |
// Remove the original block from the original container
|
@@ -562,6 +563,7 @@ document.addEventListener("DOMContentLoaded", function() {
|
|
562 |
} else {
|
563 |
console.log('No data transferred');
|
564 |
}
|
|
|
565 |
}
|
566 |
|
567 |
function getColumnFromOffset(block, offset) {
|
@@ -581,7 +583,7 @@ document.addEventListener("DOMContentLoaded", function() {
|
|
581 |
// Ensure the column number is within valid bounds (1 or 2)
|
582 |
const validColumnNumber = Math.min(Math.max(columnNumber, 1), 2);
|
583 |
|
584 |
-
|
585 |
return validColumnNumber;
|
586 |
}
|
587 |
|
@@ -617,7 +619,7 @@ document.addEventListener("DOMContentLoaded", function() {
|
|
617 |
|
618 |
let pageCounter = 1;
|
619 |
// Function to create new page
|
620 |
-
function
|
621 |
const newPage = document.createElement('div');
|
622 |
newPage.classList.add('page');
|
623 |
newPage.setAttribute('data-page-id', `page-${pageCounter}`);
|
@@ -644,6 +646,18 @@ document.addEventListener("DOMContentLoaded", function() {
|
|
644 |
return newPage;
|
645 |
}
|
646 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
647 |
function handleColumnOverflow(page, targetColumn) {
|
648 |
console.log(`Handling overflow for page ID: ${page.getAttribute('data-page-id')} in column ${targetColumn}`);
|
649 |
const blocks = Array.from(page.querySelectorAll('.block-content'));
|
@@ -716,7 +730,7 @@ document.addEventListener("DOMContentLoaded", function() {
|
|
716 |
}
|
717 |
|
718 |
// Otherwise, create a new page and move the overflowing blocks there
|
719 |
-
const newPage =
|
720 |
if (!newPage) {
|
721 |
console.error('Failed to create a new page');
|
722 |
return;
|
@@ -740,12 +754,6 @@ document.addEventListener("DOMContentLoaded", function() {
|
|
740 |
return document.querySelector(`[data-page-id="page-${nextPageId}"]`);
|
741 |
}
|
742 |
|
743 |
-
function moveBlockToPage(block, newPageId) {
|
744 |
-
block.setAttribute('data-page-id', newPageId);
|
745 |
-
const newPage = document.querySelector(`[data-page-id="${newPageId}"] .block-container`);
|
746 |
-
newPage.appendChild(block);
|
747 |
-
}
|
748 |
-
|
749 |
// Handle the drop event on the trash area
|
750 |
function handleTrashDrop(e) {
|
751 |
e.preventDefault();
|
@@ -853,11 +861,13 @@ document.addEventListener("DOMContentLoaded", function() {
|
|
853 |
sortBlocksById();
|
854 |
}
|
855 |
});
|
856 |
-
|
857 |
|
858 |
console.log('Reset complete, all blocks moved back to block-container');
|
859 |
initializeTextareaResizing();
|
860 |
}
|
|
|
|
|
861 |
|
862 |
pageContainer.addEventListener('dragover', handleDragOver);
|
863 |
pageContainer.addEventListener('drop', handleDrop);
|
|
|
63 |
const userInput = document.getElementById('user-description').value;
|
64 |
// Clear the block container before inserting new blocks
|
65 |
blockContainerPage.innerHTML = '';
|
66 |
+
document.getElementById('add-page-button').addEventListener('click', addPage);
|
67 |
+
document.getElementById('remove-page-button').addEventListener('click', removePage);
|
68 |
|
69 |
fetch('http://127.0.0.1:5000/process-description', {
|
70 |
method: 'POST',
|
|
|
353 |
});
|
354 |
}
|
355 |
function lockTextareas() {
|
356 |
+
const textareas = document.querySelectorAll('textarea');
|
357 |
|
358 |
textareas.forEach(textarea => {
|
359 |
textarea.setAttribute('disabled', true);
|
|
|
360 |
});
|
361 |
|
362 |
+
const descriptionTextareas = document.querySelectorAll('.description-textarea');
|
363 |
|
364 |
descriptionTextareas.forEach(descriptionTextarea => {
|
365 |
descriptionTextarea.removeAttribute('contenteditable');
|
|
|
366 |
});
|
367 |
|
368 |
console.log('All textareas have been locked.');
|
369 |
}
|
370 |
|
371 |
function unlockTextareas() {
|
372 |
+
const textareas = document.querySelectorAll('textarea');
|
373 |
|
374 |
textareas.forEach(textarea => {
|
375 |
textarea.removeAttribute('disabled');
|
|
|
376 |
});
|
377 |
|
378 |
+
const descriptionTextareas = document.querySelectorAll('.description-textarea');
|
379 |
|
380 |
descriptionTextareas.forEach(descriptionTextarea => {
|
381 |
+
descriptionTextarea.setAttribute('contenteditable', 'true');
|
382 |
+
console.log(`Contenteditable for element with ID "${descriptionTextarea.id}" is now: ${descriptionTextarea.contentEditable}`);
|
383 |
});
|
384 |
|
385 |
console.log('All textareas have been unlocked.');
|
386 |
}
|
387 |
|
|
|
388 |
function handleDragStart(e) {
|
389 |
lockTextareas();
|
390 |
const target = e.target.closest('.block-item, .block-content');
|
|
|
500 |
// Ensure the original block exists before proceeding
|
501 |
if (!originalBlock || !newPage) {
|
502 |
console.error(`Block with ID ${blockId} on page ${originalPageId} not found`);
|
503 |
+
unlockTextareas();
|
504 |
return;
|
505 |
}
|
506 |
|
|
|
532 |
if (offset > bounding.height / 2) {
|
533 |
console.log('Inserting after the target');
|
534 |
target.parentNode.insertBefore(newBlockContent, target.nextSibling);
|
535 |
+
unlockTextareas();
|
536 |
} else {
|
537 |
console.log('Inserting before the target');
|
538 |
target.parentNode.insertBefore(newBlockContent, target);
|
539 |
+
unlockTextareas();
|
540 |
}
|
541 |
|
542 |
// Remove highlight borders
|
|
|
545 |
} else {
|
546 |
console.log('No valid drop target found, appending to the end');
|
547 |
newPage.querySelector('.block.monster.frame.wide').appendChild(newBlockContent);
|
548 |
+
unlockTextareas();
|
549 |
}
|
550 |
|
551 |
// Remove the original block from the original container
|
|
|
563 |
} else {
|
564 |
console.log('No data transferred');
|
565 |
}
|
566 |
+
|
567 |
}
|
568 |
|
569 |
function getColumnFromOffset(block, offset) {
|
|
|
583 |
// Ensure the column number is within valid bounds (1 or 2)
|
584 |
const validColumnNumber = Math.min(Math.max(columnNumber, 1), 2);
|
585 |
|
586 |
+
|
587 |
return validColumnNumber;
|
588 |
}
|
589 |
|
|
|
619 |
|
620 |
let pageCounter = 1;
|
621 |
// Function to create new page
|
622 |
+
function addPage() {
|
623 |
const newPage = document.createElement('div');
|
624 |
newPage.classList.add('page');
|
625 |
newPage.setAttribute('data-page-id', `page-${pageCounter}`);
|
|
|
646 |
return newPage;
|
647 |
}
|
648 |
|
649 |
+
function removePage() {
|
650 |
+
const pages = pageContainer.querySelectorAll('.page');
|
651 |
+
|
652 |
+
if (pages.length > 1) { // Ensure at least one page remains
|
653 |
+
const lastPage = pages[pages.length - 1];
|
654 |
+
pageContainer.removeChild(lastPage);
|
655 |
+
console.log(`Page removed with ID: ${lastPage.id}`);
|
656 |
+
} else {
|
657 |
+
console.log('Cannot remove the last page.');
|
658 |
+
}
|
659 |
+
}
|
660 |
+
|
661 |
function handleColumnOverflow(page, targetColumn) {
|
662 |
console.log(`Handling overflow for page ID: ${page.getAttribute('data-page-id')} in column ${targetColumn}`);
|
663 |
const blocks = Array.from(page.querySelectorAll('.block-content'));
|
|
|
730 |
}
|
731 |
|
732 |
// Otherwise, create a new page and move the overflowing blocks there
|
733 |
+
const newPage = addPage();
|
734 |
if (!newPage) {
|
735 |
console.error('Failed to create a new page');
|
736 |
return;
|
|
|
754 |
return document.querySelector(`[data-page-id="page-${nextPageId}"]`);
|
755 |
}
|
756 |
|
|
|
|
|
|
|
|
|
|
|
|
|
757 |
// Handle the drop event on the trash area
|
758 |
function handleTrashDrop(e) {
|
759 |
e.preventDefault();
|
|
|
861 |
sortBlocksById();
|
862 |
}
|
863 |
});
|
864 |
+
addPage();
|
865 |
|
866 |
console.log('Reset complete, all blocks moved back to block-container');
|
867 |
initializeTextareaResizing();
|
868 |
}
|
869 |
+
|
870 |
+
|
871 |
|
872 |
pageContainer.addEventListener('dragover', handleDragOver);
|
873 |
pageContainer.addEventListener('drop', handleDrop);
|