Spaces:
Sleeping
Sleeping
drakosfire
commited on
Commit
•
9028290
1
Parent(s):
3fbe35b
added addPage and removePage function, eventlistener and buttons, remove checks for blocks on page and gives an error popup
Browse files- scripts.js +20 -6
- storeUI.html +2 -0
- template_update.html +2 -2
scripts.js
CHANGED
@@ -7,6 +7,8 @@ document.addEventListener("DOMContentLoaded", function() {
|
|
7 |
const trashArea = document.getElementById('trashArea');
|
8 |
const toggleButton = document.getElementById('toggle-text-block-button');
|
9 |
const resetButton = document.getElementById('resetButton');
|
|
|
|
|
10 |
let currentPage = pageContainer.querySelector('.block.monster.frame.wide');
|
11 |
const modal = document.getElementById('imageModal');
|
12 |
const modalImg = document.getElementById('modalImage');
|
@@ -302,6 +304,7 @@ document.addEventListener("DOMContentLoaded", function() {
|
|
302 |
'properties-textarea',
|
303 |
'string-stat-textarea',
|
304 |
'string-action-description-textarea',
|
|
|
305 |
];
|
306 |
|
307 |
classes.forEach(className => {
|
@@ -387,11 +390,11 @@ document.addEventListener("DOMContentLoaded", function() {
|
|
387 |
|
388 |
// Function to generate image
|
389 |
function generateImage(blockId) {
|
390 |
-
const sdPromptElement = document.getElementById(`
|
391 |
const imageElement = document.getElementById(`generated-image-${blockId}`);
|
392 |
|
393 |
if (!sdPromptElement) {
|
394 |
-
console.error('Element with ID
|
395 |
return;
|
396 |
}
|
397 |
|
@@ -720,11 +723,20 @@ document.addEventListener("DOMContentLoaded", function() {
|
|
720 |
|
721 |
function removePage() {
|
722 |
const pages = pageContainer.querySelectorAll('.page');
|
723 |
-
|
724 |
if (pages.length > 1) { // Ensure at least one page remains
|
725 |
const lastPage = pages[pages.length - 1];
|
726 |
-
|
727 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
728 |
} else {
|
729 |
console.log('Cannot remove the last page.');
|
730 |
}
|
@@ -912,7 +924,9 @@ document.addEventListener("DOMContentLoaded", function() {
|
|
912 |
console.log('Reset complete, all blocks moved back to block-container');
|
913 |
initializeTextareaResizing();
|
914 |
}
|
915 |
-
|
|
|
|
|
916 |
toggleButton.addEventListener('click', toggleAllTextBlocks);
|
917 |
blockContainer.addEventListener('dragover', handleDragOver);
|
918 |
blockContainer.addEventListener('drop', handleDrop);
|
|
|
7 |
const trashArea = document.getElementById('trashArea');
|
8 |
const toggleButton = document.getElementById('toggle-text-block-button');
|
9 |
const resetButton = document.getElementById('resetButton');
|
10 |
+
const addPageButton = document.getElementById('add-page-button');
|
11 |
+
const removePageButton = document.getElementById('remove-page-button');
|
12 |
let currentPage = pageContainer.querySelector('.block.monster.frame.wide');
|
13 |
const modal = document.getElementById('imageModal');
|
14 |
const modalImg = document.getElementById('modalImage');
|
|
|
304 |
'properties-textarea',
|
305 |
'string-stat-textarea',
|
306 |
'string-action-description-textarea',
|
307 |
+
'image-textarea'
|
308 |
];
|
309 |
|
310 |
classes.forEach(className => {
|
|
|
390 |
|
391 |
// Function to generate image
|
392 |
function generateImage(blockId) {
|
393 |
+
const sdPromptElement = document.getElementById(`sdprompt-${blockId}`);
|
394 |
const imageElement = document.getElementById(`generated-image-${blockId}`);
|
395 |
|
396 |
if (!sdPromptElement) {
|
397 |
+
console.error('Element with ID sdprompt not found');
|
398 |
return;
|
399 |
}
|
400 |
|
|
|
723 |
|
724 |
function removePage() {
|
725 |
const pages = pageContainer.querySelectorAll('.page');
|
726 |
+
|
727 |
if (pages.length > 1) { // Ensure at least one page remains
|
728 |
const lastPage = pages[pages.length - 1];
|
729 |
+
const blocks = lastPage.querySelectorAll('.block-content'); // Check for blocks inside the last page
|
730 |
+
|
731 |
+
if (blocks.length > 0) {
|
732 |
+
// If blocks are present, block the removal and display a warning
|
733 |
+
console.log(`Cannot remove page with ID: ${lastPage.id} because it contains ${blocks.length} block(s).`);
|
734 |
+
alert(`Cannot remove this page because it contains ${blocks.length} block(s). Please remove the blocks first.`);
|
735 |
+
} else {
|
736 |
+
// If no blocks are present, allow removal
|
737 |
+
pageContainer.removeChild(lastPage);
|
738 |
+
console.log(`Page removed with ID: ${lastPage.id}`);
|
739 |
+
}
|
740 |
} else {
|
741 |
console.log('Cannot remove the last page.');
|
742 |
}
|
|
|
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);
|
930 |
toggleButton.addEventListener('click', toggleAllTextBlocks);
|
931 |
blockContainer.addEventListener('dragover', handleDragOver);
|
932 |
blockContainer.addEventListener('drop', handleDrop);
|
storeUI.html
CHANGED
@@ -30,6 +30,8 @@
|
|
30 |
title="As much or as little description as you want to provide. You can provide specific employees, inventory etc">A very standard gear store run by a fae potted plant named Gorgeous</textarea>
|
31 |
<button id="submitDescription">Submit</button>
|
32 |
<button id="toggle-text-block-button">Toggle Image Descriptions</button>
|
|
|
|
|
33 |
<button id="resetButton">Reset</button>
|
34 |
<button id="printButton">Open Tab to print</button>
|
35 |
<div class="brewRenderer" id="brewRenderer">
|
|
|
30 |
title="As much or as little description as you want to provide. You can provide specific employees, inventory etc">A very standard gear store run by a fae potted plant named Gorgeous</textarea>
|
31 |
<button id="submitDescription">Submit</button>
|
32 |
<button id="toggle-text-block-button">Toggle Image Descriptions</button>
|
33 |
+
<button id="add-page-button">Add New Page</button>
|
34 |
+
<button id="remove-page-button">Remove Last Page</button>
|
35 |
<button id="resetButton">Reset</button>
|
36 |
<button id="printButton">Open Tab to print</button>
|
37 |
<div class="brewRenderer" id="brewRenderer">
|
template_update.html
CHANGED
@@ -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="
|
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>
|
|
|
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="user-storefront-prompt-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="user-storefront-prompt-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>
|