Spaces:
Sleeping
Sleeping
Commit
·
f434b03
1
Parent(s):
d4b9975
Removed some white spaces, added functions to lock textares during drop events, and unlock at end of drop events, added check for 'description-textarea' while handling drop
Browse files- scripts.js +45 -17
scripts.js
CHANGED
@@ -200,22 +200,17 @@ document.addEventListener("DOMContentLoaded", function() {
|
|
200 |
function insertHtmlBlocks(blocks) {
|
201 |
console.log('blockContainerPage = ', blockContainerPage)
|
202 |
console.log('List of blocks:', blocks);
|
203 |
-
|
204 |
const parser = new DOMParser();
|
205 |
|
206 |
blocks.forEach(blockHtml => {
|
207 |
console.log('Original blockHtml:', blockHtml);
|
208 |
-
|
209 |
// Parse the HTML string
|
210 |
const doc = parser.parseFromString(blockHtml, 'text/html');
|
211 |
-
console.log('Parsed document:', doc);
|
212 |
const block = doc.body.firstChild;
|
213 |
-
console.log('Parsed block:', block);
|
214 |
if (block) {
|
215 |
blockContainerPage.appendChild(block); // Append the parsed block to the container
|
216 |
console.log('Appended block:', block);
|
217 |
}
|
218 |
-
|
219 |
});
|
220 |
// console.log('Final state of blockContainer:', blockContainer.innerHTML);
|
221 |
initializeTextareaResizing();
|
@@ -342,8 +337,31 @@ document.addEventListener("DOMContentLoaded", function() {
|
|
342 |
console.error('Error:', error);
|
343 |
});
|
344 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
345 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
346 |
function handleDragStart(e) {
|
|
|
347 |
const target = e.target.closest('.block-item, .block-content');
|
348 |
if (!target) {
|
349 |
console.error('Drag started for an element without a valid target');
|
@@ -359,6 +377,8 @@ document.addEventListener("DOMContentLoaded", function() {
|
|
359 |
console.error('Drag started for an element without a data-page-id');
|
360 |
return;
|
361 |
}
|
|
|
|
|
362 |
const innerHTML = target.innerHTML;
|
363 |
e.dataTransfer.setData('block-id', blockId);
|
364 |
e.dataTransfer.setData('text/plain', innerHTML); // Store inner HTML
|
@@ -393,7 +413,21 @@ document.addEventListener("DOMContentLoaded", function() {
|
|
393 |
|
394 |
function handleDragOver(e) {
|
395 |
e.preventDefault();
|
396 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
397 |
// Check if the drop target is a TEXTAREA or any other non-droppable area
|
398 |
if (e.target.tagName === 'TEXTAREA' || e.target.closest('.block-item')) {
|
399 |
e.dataTransfer.dropEffect = 'none'; // Indicate that drop is not allowed
|
@@ -418,26 +452,18 @@ document.addEventListener("DOMContentLoaded", function() {
|
|
418 |
targetBlock.classList.remove('highlight-block');
|
419 |
}
|
420 |
}
|
421 |
-
|
422 |
-
|
423 |
function handleDrop(e) {
|
424 |
e.preventDefault();
|
425 |
-
|
426 |
// Ensure we are not dropping into a textarea or another block
|
427 |
-
if (e.target.classList.contains('block-item', 'block-content') || e.target.tagName === 'TEXTAREA') {
|
428 |
console.log('Cannot drop block inside another block or textarea');
|
429 |
return;
|
430 |
-
}
|
431 |
const blockId = e.dataTransfer.getData('block-id');
|
432 |
const originalPageId = e.dataTransfer.getData('data-page-id');
|
433 |
const innerHTML = e.dataTransfer.getData('text/plain');
|
434 |
console.log(`Drop event for block ID: ${blockId} from page ID: ${originalPageId}`);
|
435 |
-
|
436 |
-
// Ensure we are not dropping into a textarea or another block
|
437 |
-
if (r.target.classList.contains('block-item', 'block-content') || event.target.tagName === 'TEXTAREA') {
|
438 |
-
console.log('Cannot drop block inside another block or textarea');
|
439 |
-
return;
|
440 |
-
}
|
441 |
|
442 |
if (blockId && originalPageId) {
|
443 |
const originalBlock = document.querySelector(`[data-block-id="${blockId}"]`);
|
@@ -525,6 +551,8 @@ document.addEventListener("DOMContentLoaded", function() {
|
|
525 |
|
526 |
// Ensure the column number is within valid bounds (1 or 2)
|
527 |
const validColumnNumber = Math.min(Math.max(columnNumber, 1), 2);
|
|
|
|
|
528 |
return validColumnNumber;
|
529 |
}
|
530 |
|
|
|
200 |
function insertHtmlBlocks(blocks) {
|
201 |
console.log('blockContainerPage = ', blockContainerPage)
|
202 |
console.log('List of blocks:', blocks);
|
|
|
203 |
const parser = new DOMParser();
|
204 |
|
205 |
blocks.forEach(blockHtml => {
|
206 |
console.log('Original blockHtml:', blockHtml);
|
|
|
207 |
// Parse the HTML string
|
208 |
const doc = parser.parseFromString(blockHtml, 'text/html');
|
|
|
209 |
const block = doc.body.firstChild;
|
|
|
210 |
if (block) {
|
211 |
blockContainerPage.appendChild(block); // Append the parsed block to the container
|
212 |
console.log('Appended block:', block);
|
213 |
}
|
|
|
214 |
});
|
215 |
// console.log('Final state of blockContainer:', blockContainer.innerHTML);
|
216 |
initializeTextareaResizing();
|
|
|
337 |
console.error('Error:', error);
|
338 |
});
|
339 |
}
|
340 |
+
function lockTextareas() {
|
341 |
+
const textareas = blockContainer.querySelectorAll('textarea');
|
342 |
+
textareas.forEach(textarea => {
|
343 |
+
textarea.setAttribute('disabled', true);
|
344 |
+
});
|
345 |
+
const descriptionTextareas = blockContainer.querySelectorAll('description-textarea');
|
346 |
+
descriptionTextareas.forEach(descriptionTextareas => {
|
347 |
+
descriptionTextareas.setAttribute('disabled', false);
|
348 |
+
});
|
349 |
+
console.log('All textareas have been locked.');
|
350 |
+
}
|
351 |
|
352 |
+
function unlockTextareas() {
|
353 |
+
const textareas = blockContainer.querySelectorAll('textarea');
|
354 |
+
textareas.forEach(textarea => {
|
355 |
+
textarea.removeAttribute('disabled');
|
356 |
+
});
|
357 |
+
const descriptionTextareas = blockContainer.querySelectorAll('description-textarea');
|
358 |
+
textareas.forEach(descriptionTextareas => {
|
359 |
+
descriptionTextareas.setAttribute('disabled', True);
|
360 |
+
console.log('All textareas have been unlocked.');
|
361 |
+
});
|
362 |
+
}
|
363 |
function handleDragStart(e) {
|
364 |
+
lockTextareas();
|
365 |
const target = e.target.closest('.block-item, .block-content');
|
366 |
if (!target) {
|
367 |
console.error('Drag started for an element without a valid target');
|
|
|
377 |
console.error('Drag started for an element without a data-page-id');
|
378 |
return;
|
379 |
}
|
380 |
+
|
381 |
+
// Store the block ID and inner HTML in the data transfer object
|
382 |
const innerHTML = target.innerHTML;
|
383 |
e.dataTransfer.setData('block-id', blockId);
|
384 |
e.dataTransfer.setData('text/plain', innerHTML); // Store inner HTML
|
|
|
413 |
|
414 |
function handleDragOver(e) {
|
415 |
e.preventDefault();
|
416 |
+
// Get the element currently under the cursor
|
417 |
+
const elementUnderCursor = document.elementFromPoint(e.clientX, e.clientY);
|
418 |
+
|
419 |
+
if (elementUnderCursor) {
|
420 |
+
// Check if the element is a block or textarea
|
421 |
+
if (elementUnderCursor.classList.contains('block-item')) {
|
422 |
+
console.log('Dragging over a block-item:', elementUnderCursor);
|
423 |
+
console.log('Block ID:', elementUnderCursor.getAttribute('data-block-id'));
|
424 |
+
} else if (elementUnderCursor.tagName === 'TEXTAREA') {
|
425 |
+
console.log('Dragging over a textarea:', elementUnderCursor);
|
426 |
+
} else {
|
427 |
+
// Log other elements if needed
|
428 |
+
console.log('Dragging over another element:', elementUnderCursor.tagName);
|
429 |
+
}
|
430 |
+
}
|
431 |
// Check if the drop target is a TEXTAREA or any other non-droppable area
|
432 |
if (e.target.tagName === 'TEXTAREA' || e.target.closest('.block-item')) {
|
433 |
e.dataTransfer.dropEffect = 'none'; // Indicate that drop is not allowed
|
|
|
452 |
targetBlock.classList.remove('highlight-block');
|
453 |
}
|
454 |
}
|
455 |
+
|
|
|
456 |
function handleDrop(e) {
|
457 |
e.preventDefault();
|
|
|
458 |
// Ensure we are not dropping into a textarea or another block
|
459 |
+
if (e.target.classList.contains('block-item', 'block-content', 'description-textarea') || e.target.tagName === 'TEXTAREA') {
|
460 |
console.log('Cannot drop block inside another block or textarea');
|
461 |
return;
|
462 |
+
}
|
463 |
const blockId = e.dataTransfer.getData('block-id');
|
464 |
const originalPageId = e.dataTransfer.getData('data-page-id');
|
465 |
const innerHTML = e.dataTransfer.getData('text/plain');
|
466 |
console.log(`Drop event for block ID: ${blockId} from page ID: ${originalPageId}`);
|
|
|
|
|
|
|
|
|
|
|
|
|
467 |
|
468 |
if (blockId && originalPageId) {
|
469 |
const originalBlock = document.querySelector(`[data-block-id="${blockId}"]`);
|
|
|
551 |
|
552 |
// Ensure the column number is within valid bounds (1 or 2)
|
553 |
const validColumnNumber = Math.min(Math.max(columnNumber, 1), 2);
|
554 |
+
|
555 |
+
unlockTextareas();
|
556 |
return validColumnNumber;
|
557 |
}
|
558 |
|