drakosfire commited on
Commit
2d15a52
1 Parent(s): 2c14dbc

Added autofill function, event listener, and button

Browse files
Files changed (2) hide show
  1. scripts.js +40 -2
  2. storeUI.html +2 -0
scripts.js CHANGED
@@ -6,6 +6,7 @@ document.addEventListener("DOMContentLoaded", function() {
6
  const pageContainer = document.getElementById('pages');
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');
@@ -124,7 +125,39 @@ document.addEventListener("DOMContentLoaded", function() {
124
  document.querySelector('.toggle-text-block-button').textContent = 'Hide All Image Descriptions';
125
  }
126
  }
127
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
  window.printPageContainer = function(newTab) {
129
  var pageContainer = document.getElementById('brewRenderer');
130
 
@@ -889,6 +922,7 @@ document.addEventListener("DOMContentLoaded", function() {
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,
@@ -949,15 +983,19 @@ document.addEventListener("DOMContentLoaded", function() {
949
  initializeTextareaResizing();
950
  }
951
 
952
-
953
  addPageButton.addEventListener('click', addPage);
954
  removePageButton.addEventListener('click', removePage);
955
  toggleButton.addEventListener('click', toggleAllTextBlocks);
 
 
 
956
  blockContainer.addEventListener('dragover', handleDragOver);
957
  blockContainer.addEventListener('drop', handleDrop);
958
  pageContainer.addEventListener('dragover', handleDragOver);
959
  pageContainer.addEventListener('drop', handleDrop);
960
 
 
961
  trashArea.addEventListener('dragover', handleTrashOver);
962
  trashArea.addEventListener('dragleave', handleTrashLeave);
963
  trashArea.addEventListener('drop', handleTrashDrop);
 
6
  const pageContainer = document.getElementById('pages');
7
  const trashArea = document.getElementById('trashArea');
8
  const toggleButton = document.getElementById('toggle-text-block-button');
9
+ const autofillButton = document.getElementById('autofill-button');
10
  const resetButton = document.getElementById('resetButton');
11
  const addPageButton = document.getElementById('add-page-button');
12
  const removePageButton = document.getElementById('remove-page-button');
 
125
  document.querySelector('.toggle-text-block-button').textContent = 'Hide All Image Descriptions';
126
  }
127
  }
128
+ function autofillBlocks() {
129
+ console.log('Autofill button clicked');
130
+
131
+ const blocks = Array.from(blockContainer.querySelectorAll('.block-item'));
132
+ let currentPage = pageContainer.querySelector('.page');
133
+ // If no existing page is found, create the first page
134
+ if (!currentPage) {
135
+ currentPage = addPage();
136
+ console.log('No existing pages found. Created the first page:', currentPage.id);
137
+ }
138
+
139
+ // Iterate over each block and move it to the pageContainer
140
+ blocks.forEach(block => {
141
+ block.setAttribute('class', 'block-content');
142
+ block.setAttribute('data-page-id', currentPage.getAttribute('data-page-id'));
143
+ // Append the block to the current page's columnWrapper
144
+ const newPage = currentPage.querySelector('.block.monster.frame.wide');
145
+ newPage.appendChild(block);
146
+ console.log(`Moved block with ID: ${block.getAttribute('data-block-id')} to page with ID: ${currentPage.getAttribute('data-page-id')}`);
147
+ // Adjust the layout after adding the block; this function handles creating a new page if needed
148
+ adjustPageLayout(currentPage.getAttribute('data-page-id'));
149
+
150
+ // Check if a new page was created and update curtrrentPage accordingly
151
+ const lastPageInContainer = pageContainer.querySelector('.page:last-child');
152
+ if (lastPageInContainer !== currentPage) {
153
+ currentPage = lastPageInContainer;
154
+ console.log('Moved to a new page:', currentPage.getAttribute('data-page-id')); }
155
+
156
+
157
+
158
+ });
159
+ console.log('Autofill complete, all blocks moved to page-container');
160
+ }
161
  window.printPageContainer = function(newTab) {
162
  var pageContainer = document.getElementById('brewRenderer');
163
 
 
922
  const blocksOnPage = page.querySelectorAll('[data-block-id]');
923
 
924
  blocksOnPage.forEach(block => {
925
+ block.setAttribute('display', 'block');
926
  const blockId = block.getAttribute('data-block-id');
927
  allBlocks.push({
928
  id: blockId,
 
983
  initializeTextareaResizing();
984
  }
985
 
986
+ // Event listeners for buttons
987
  addPageButton.addEventListener('click', addPage);
988
  removePageButton.addEventListener('click', removePage);
989
  toggleButton.addEventListener('click', toggleAllTextBlocks);
990
+ autofillButton.addEventListener('click', autofillBlocks);
991
+
992
+ // Event listeners for drag and drop functionality
993
  blockContainer.addEventListener('dragover', handleDragOver);
994
  blockContainer.addEventListener('drop', handleDrop);
995
  pageContainer.addEventListener('dragover', handleDragOver);
996
  pageContainer.addEventListener('drop', handleDrop);
997
 
998
+ // Event listeners for trash area
999
  trashArea.addEventListener('dragover', handleTrashOver);
1000
  trashArea.addEventListener('dragleave', handleTrashLeave);
1001
  trashArea.addEventListener('drop', handleTrashDrop);
storeUI.html CHANGED
@@ -29,11 +29,13 @@
29
  hx-target="#user-description" hx-swap="outerHTML"
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">
38
 
39
  <div class="pages" id="pages">
 
29
  hx-target="#user-description" hx-swap="outerHTML"
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="autofill-button">Autofill Pages</button>
33
  <button id="toggle-text-block-button">Toggle Image Descriptions</button>
34
  <button id="add-page-button">Add New Page</button>
35
  <button id="remove-page-button">Remove Last Page</button>
36
  <button id="resetButton">Reset</button>
37
  <button id="printButton">Open Tab to print</button>
38
+
39
  <div class="brewRenderer" id="brewRenderer">
40
 
41
  <div class="pages" id="pages">