Spaces:
Building
Building
Commit
·
2c14dbc
1
Parent(s):
9028290
Fixed reset, blockContainerPage needed to be reinitialized, renamed image textareas ids to sdprompt- in template
Browse files- scripts.js +63 -38
- template_update.html +3 -3
scripts.js
CHANGED
@@ -877,53 +877,78 @@ document.addEventListener("DOMContentLoaded", function() {
|
|
877 |
}
|
878 |
|
879 |
function handleReset() {
|
880 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
881 |
|
882 |
-
|
883 |
-
|
884 |
-
|
885 |
-
|
886 |
-
|
887 |
-
|
888 |
-
|
889 |
-
allBlocks.push({
|
890 |
-
id: blockId,
|
891 |
-
innerHTML: block.innerHTML
|
892 |
-
});
|
893 |
-
block.remove();
|
894 |
-
console.log(`Removed block with ID: ${blockId} from page ID: ${page.getAttribute('data-page-id')}`);
|
895 |
});
|
|
|
|
|
896 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
897 |
|
898 |
-
|
899 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
900 |
|
901 |
-
|
902 |
-
|
|
|
903 |
|
904 |
-
|
|
|
|
|
905 |
|
906 |
-
if (
|
907 |
-
|
908 |
-
blockContainerPage.
|
909 |
-
|
910 |
-
|
|
|
911 |
}
|
912 |
-
|
913 |
-
|
914 |
-
|
915 |
-
|
916 |
-
|
917 |
-
|
918 |
-
|
919 |
-
|
920 |
-
|
921 |
-
});
|
922 |
-
addPage();
|
923 |
|
924 |
-
console.log('Reset complete, all blocks moved back to block-container');
|
925 |
-
initializeTextareaResizing();
|
926 |
-
}
|
927 |
|
928 |
addPageButton.addEventListener('click', addPage);
|
929 |
removePageButton.addEventListener('click', removePage);
|
|
|
877 |
}
|
878 |
|
879 |
function handleReset() {
|
880 |
+
console.log('Reset button clicked');
|
881 |
+
|
882 |
+
// Collect all blocks from all pages
|
883 |
+
const allBlocks = [];
|
884 |
+
const pages = document.querySelectorAll('.page');
|
885 |
+
|
886 |
+
pages.forEach(page => {
|
887 |
+
console.log(`Processing page with ID: ${page.getAttribute('data-page-id')}`);
|
888 |
|
889 |
+
const blocksOnPage = page.querySelectorAll('[data-block-id]');
|
890 |
+
|
891 |
+
blocksOnPage.forEach(block => {
|
892 |
+
const blockId = block.getAttribute('data-block-id');
|
893 |
+
allBlocks.push({
|
894 |
+
id: blockId,
|
895 |
+
innerHTML: block.innerHTML
|
|
|
|
|
|
|
|
|
|
|
|
|
896 |
});
|
897 |
+
block.remove();
|
898 |
+
console.log(`Removed block with ID: ${blockId} from page ID: ${page.getAttribute('data-page-id')}`);
|
899 |
});
|
900 |
+
});
|
901 |
+
|
902 |
+
// Log blocks collected
|
903 |
+
console.log('All blocks collected:', allBlocks);
|
904 |
+
|
905 |
+
// Clear all pages
|
906 |
+
pages.forEach(page => {
|
907 |
+
console.log(`Removing page with ID: ${page.getAttribute('data-page-id')}`);
|
908 |
+
page.remove();
|
909 |
+
});
|
910 |
+
|
911 |
+
// Clear blockContainer before reinserting blocks
|
912 |
+
console.log('Clearing blockContainer...');
|
913 |
+
blockContainer.innerHTML = '';
|
914 |
|
915 |
+
// Check and create blockContainerPage if it doesn't exist
|
916 |
+
let blockContainerPage = document.getElementById('block-page');
|
917 |
+
if (!blockContainerPage) {
|
918 |
+
blockContainerPage = document.createElement('div');
|
919 |
+
blockContainerPage.classList.add('page');
|
920 |
+
blockContainerPage.setAttribute('id', 'block-page');
|
921 |
+
blockContainer.appendChild(blockContainerPage);
|
922 |
+
console.log('Created new blockContainerPage');
|
923 |
+
} else {
|
924 |
+
console.log('blockContainerPage already exists');
|
925 |
+
}
|
926 |
|
927 |
+
// Reassign blockContainerPage to the newly created block-page element
|
928 |
+
|
929 |
+
console.log('blockContainerPage reassigned to:', blockContainerPage);
|
930 |
|
931 |
+
// Reinsert blocks back into the blockContainer in their original order
|
932 |
+
initialPositions.forEach(pos => {
|
933 |
+
const blockData = allBlocks.find(block => block.id === pos.id);
|
934 |
|
935 |
+
if (blockData) {
|
936 |
+
console.log(`Reinserting block with ID: ${blockData.id} into blockContainerPage`);
|
937 |
+
reinsertBlock(blockContainerPage, blockData.id, blockData.innerHTML);
|
938 |
+
sortBlocksById();
|
939 |
+
} else {
|
940 |
+
console.log(`Block with ID: ${pos.id} not found in collected blocks.`);
|
941 |
}
|
942 |
+
});
|
943 |
+
|
944 |
+
// Add a new page after reset
|
945 |
+
addPage();
|
946 |
+
console.log('Added new page after reset.');
|
947 |
+
|
948 |
+
console.log('Reset complete, all blocks moved back to block-container');
|
949 |
+
initializeTextareaResizing();
|
950 |
+
}
|
|
|
|
|
951 |
|
|
|
|
|
|
|
952 |
|
953 |
addPageButton.addEventListener('click', addPage);
|
954 |
removePageButton.addEventListener('click', removePage);
|
template_update.html
CHANGED
@@ -9,7 +9,7 @@
|
|
9 |
</div>
|
10 |
|
11 |
<div class="block-item" data-block-id="1" data-page-id="block-container" draggable="true">
|
12 |
-
<textarea class="image-textarea" id="
|
13 |
<button class="generate-image-button" data-block-id="1">Generate Image</button>
|
14 |
<img id="generated-image-1" alt="" style="display: none; cursor: pointer;">
|
15 |
</div>
|
@@ -75,7 +75,7 @@
|
|
75 |
</div>
|
76 |
|
77 |
<div class="block-item" data-block-id="3" data-page-id="block-container" draggable="true">
|
78 |
-
<textarea class="image-textarea" id="
|
79 |
<button class="generate-image-button" data-block-id="3">Generate Image</button>
|
80 |
<img id="generated-image-3" alt="" style="display: none; cursor: pointer;">
|
81 |
</div>
|
@@ -124,7 +124,7 @@
|
|
124 |
</div>
|
125 |
|
126 |
<div class="block-item" data-block-id="5" data-page-id="block-container" draggable="true">
|
127 |
-
<textarea class="
|
128 |
<button class="generate-image-button" data-block-id="5">Generate Image</button>
|
129 |
<img id="generated-image-5" alt="" style="display: none; cursor: pointer;">
|
130 |
</div>
|
|
|
9 |
</div>
|
10 |
|
11 |
<div class="block-item" data-block-id="1" data-page-id="block-container" draggable="true">
|
12 |
+
<textarea class="image-textarea" id="sdprompt-1" hx-post="/update-stats" hx-trigger="change" hx-target="#user-sd-prompt" hx-swap="outerHTML" title="Storefront image description" style="height: 80px;">A highly detailed fantasy painting of a curious sentient potted plant in a vibrant gear shop. The plant has phosphorescent leaves and delicate, intricate roots. The shop is filled with glowing flora, magical tools, and adventure gear. The background shows enchanted trees intertwined with the walls and ceiling.</textarea>
|
13 |
<button class="generate-image-button" data-block-id="1">Generate Image</button>
|
14 |
<img id="generated-image-1" alt="" style="display: none; cursor: pointer;">
|
15 |
</div>
|
|
|
75 |
</div>
|
76 |
|
77 |
<div class="block-item" data-block-id="3" data-page-id="block-container" draggable="true">
|
78 |
+
<textarea class="image-textarea" id="sdprompt-3" hx-post="/update-stats" hx-trigger="change" hx-target="#user-sd-prompt" hx-swap="outerHTML" title="Storefront image description" style="height: 48px;">A highly detailed fantasy drawing of a sentient potted plant with glowing tendrils, set in an enchanting gear shop filled with vibrant flora and a myriad of magical items.</textarea>
|
79 |
<button class="generate-image-button" data-block-id="3">Generate Image</button>
|
80 |
<img id="generated-image-3" alt="" style="display: none; cursor: pointer;">
|
81 |
</div>
|
|
|
124 |
</div>
|
125 |
|
126 |
<div class="block-item" data-block-id="5" data-page-id="block-container" draggable="true">
|
127 |
+
<textarea class="image-textarea" id="sdprompt-5" hx-post="/update-stats" hx-trigger="change" hx-target="#user-sd-prompt" hx-swap="outerHTML" title="Storefront image description" style="height: 49px;">A highly detailed fantasy image of a half-elf shopkeeper with forest-green eyes and flower-adorned hair, set in a magical gear shop filled with glowing plants and enchanted equipment.</textarea>
|
128 |
<button class="generate-image-button" data-block-id="5">Generate Image</button>
|
129 |
<img id="generated-image-5" alt="" style="display: none; cursor: pointer;">
|
130 |
</div>
|