File size: 2,281 Bytes
22db057 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | document.addEventListener('DOMContentLoaded', function() {
// Make blocks draggable
const blocks = document.querySelectorAll('[draggable]');
blocks.forEach(block => {
block.addEventListener('dragstart', function(e) {
e.dataTransfer.setData('text/plain', block.id);
block.classList.add('block-drag');
});
block.addEventListener('dragend', function() {
block.classList.remove('block-drag');
});
});
// Code area drop target
const codeArea = document.getElementById('codeArea');
codeArea.addEventListener('dragover', function(e) {
e.preventDefault();
this.classList.add('border-blue-500');
});
codeArea.addEventListener('dragleave', function() {
this.classList.remove('border-blue-500');
});
codeArea.addEventListener('drop', function(e) {
e.preventDefault();
this.classList.remove('border-blue-500');
const blockId = e.dataTransfer.getData('text/plain');
const block = document.getElementById(blockId);
if (block) {
const clone = block.cloneNode(true);
clone.removeAttribute('draggable');
clone.classList.remove('hover:shadow-md', 'cursor-move');
clone.classList.add('m-2');
this.appendChild(clone);
}
});
// Sprite selection
const sprites = document.querySelectorAll('.bg-white.cursor-pointer');
sprites.forEach(sprite => {
sprite.addEventListener('click', function() {
sprites.forEach(s => s.classList.remove('ring-2', 'ring-blue-500'));
this.classList.add('ring-2', 'ring-blue-500');
// Update stage with selected sprite
const stage = document.getElementById('stage');
const icon = this.querySelector('i');
const iconName = icon.getAttribute('data-feather');
stage.innerHTML = '';
const spriteIcon = document.createElement('i');
spriteIcon.setAttribute('data-feather', iconName);
spriteIcon.classList.add('text-6xl', 'text-blue-500');
stage.appendChild(spriteIcon);
feather.replace();
});
});
}); |