Skip to content

Commit 9aafb9c

Browse files
committed
looping works
1 parent 174f66b commit 9aafb9c

3 files changed

Lines changed: 20 additions & 17 deletions

File tree

blockcode/blocks.css

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ html, body{
44
border: 0;
55
margin: 0;
66
}
7-
.menu, .script{
7+
.menu, .script, .block{
88
border: 1px inset #021429;
99
border-radius: 7px;
1010
}
@@ -64,6 +64,7 @@ h1, h2, h3, h4, h5, h6{
6464
background-color: Coral;
6565
}
6666
.script .block{
67+
margin: 5px;
6768
background-color: DodgerBlue;
6869
}
6970

@@ -76,6 +77,7 @@ h1, h2, h3, h4, h5, h6{
7677
.container{
7778
margin-left: 20px;
7879
padding-bottom: 10px;
80+
/*padding-top: 5px;*/
7981
border: 0;
8082
background-color: LightSteelBlue;
8183
border-bottom-right-radius: 0;
@@ -91,10 +93,3 @@ h1, h2, h3, h4, h5, h6{
9193
background-color: CadetBlue;
9294
}
9395

94-
.pseudo-cursor{
95-
position: absolute;
96-
width: 10px;
97-
height: 10px;
98-
border: 1px solid yellow;
99-
pointer-events: none;
100-
}

blockcode/blocks.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585

8686
function dragEnter(evt){
8787
// evlog(evt);
88-
if (matches(evt.target, '.menu, .script')){
88+
if (matches(evt.target, '.menu, .script, .content')){
8989
evt.target.classList.add('over');
9090
}else{
9191
if (!matches(evt.target, '.menu *, .script *')){
@@ -105,7 +105,7 @@
105105

106106
function dragOver(evt){
107107
// evlog(evt);
108-
if (!matches(evt.target, '.menu, .menu *, .script, .script *')) return;
108+
if (!matches(evt.target, '.menu, .menu *, .script, .script *, .content')) return;
109109
if (evt.preventDefault) {
110110
evt.preventDefault(); // Necessary. Allows us to drop.
111111
}
@@ -119,8 +119,9 @@
119119
document.addEventListener('dragover', dragOver, false);
120120

121121
function drop(evt){
122-
if (!matches(evt.target, '.menu, .menu *, .script, .script *')) return;
123-
var dropTarget = closest(evt.target, '.menu, .script');
122+
if (!matches(evt.target, '.menu, .menu *, .script, .script *, .container, .container *')) return;
123+
var dropTarget = closest(evt.target, '.menu, .script, .container');
124+
console.log('dropTarget: %s', dropTarget.textContent);
124125
var dropType = 'script';
125126
if (matches(dropTarget, '.menu')){
126127
dropType = 'menu';

blockcode/menu.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,17 @@
5656

5757
function repeat(block){
5858
var count = value(block);
59-
// FIXME: Actually repeat the contained blocks
59+
var children = [].slice.call(block.querySelector('.container').children);
60+
for (var i = 0; i < count; i++){
61+
runBlocks(children);
62+
}
63+
}
64+
65+
function runBlocks(blocks){
66+
var evt = new CustomEvent('run', {bubbles: true, cancelable: false});
67+
blocks.forEach(function(block){
68+
block.dispatchEvent(evt);
69+
});
6070
}
6171

6272
function run(){
@@ -65,10 +75,7 @@
6575
scriptDirty = false;
6676
clear();
6777
var blocks = [].slice.call(document.querySelectorAll('.script > .block'));
68-
var evt = new CustomEvent('run', {bubbles: true, cancelable: false});
69-
blocks.forEach(function(block){
70-
block.dispatchEvent(evt);
71-
});
78+
runBlocks(blocks);
7279
turtle.draw();
7380
}
7481
requestAnimationFrame(run);

0 commit comments

Comments
 (0)