Skip to content

Commit 11b5002

Browse files
committed
Merge branch 'staging' of github.com:code-dot-org/code-dot-org into staging
2 parents 3cdafca + c8175d8 commit 11b5002

File tree

9 files changed

+201
-38
lines changed

9 files changed

+201
-38
lines changed

blockly/src/base.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,8 @@ BlocklyApps.init = function(config) {
441441
BlocklyApps.editor = new droplet.Editor(document.getElementById('codeTextbox'), {
442442
mode: 'javascript',
443443
modeOptions: utils.generateDropletModeOptions(config.level.codeFunctions),
444-
palette: utils.generateDropletPalette(config.level.codeFunctions)
444+
palette: utils.generateDropletPalette(config.level.codeFunctions,
445+
config.level.categoryInfo)
445446
});
446447

447448
if (config.afterInject) {

blockly/src/utils.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ exports.generateCodeAliases = function (codeFunctions, parentObjName) {
163163
/**
164164
* Generate a palette for the droplet editor based on some level data.
165165
*/
166-
exports.generateDropletPalette = function (codeFunctions) {
166+
exports.generateDropletPalette = function (codeFunctions, categoryInfo) {
167167
// TODO: figure out localization for droplet scenario
168168
var palette = [
169169
{
@@ -253,14 +253,16 @@ exports.generateDropletPalette = function (codeFunctions) {
253253
}
254254
];
255255

256-
var appPaletteCategory = {
257-
name: 'Actions',
258-
color: 'blue',
259-
blocks: []
256+
var defCategoryInfo = {
257+
'Actions': {
258+
'color': 'blue',
259+
'blocks': []
260+
}
260261
};
262+
categoryInfo = categoryInfo || defCategoryInfo;
261263

262264
if (codeFunctions) {
263-
for (var i = 0, blockIndex = 0; i < codeFunctions.length; i++) {
265+
for (var i = 0; i < codeFunctions.length; i++) {
264266
var cf = codeFunctions[i];
265267
if (cf.category === 'hidden') {
266268
continue;
@@ -279,12 +281,14 @@ exports.generateDropletPalette = function (codeFunctions) {
279281
block: block,
280282
title: cf.func
281283
};
282-
appPaletteCategory.blocks[blockIndex] = blockPair;
283-
blockIndex++;
284+
categoryInfo[cf.category || 'Actions'].blocks.push(blockPair);
284285
}
285286
}
286287

287-
palette.unshift(appPaletteCategory);
288+
for (var category in categoryInfo) {
289+
categoryInfo[category].name = category;
290+
palette.unshift(categoryInfo[category]);
291+
}
288292

289293
return palette;
290294
};
@@ -310,10 +314,13 @@ exports.generateDropletModeOptions = function (codeFunctions) {
310314

311315
if (codeFunctions) {
312316
for (var i = 0; i < codeFunctions.length; i++) {
313-
if (codeFunctions[i].category === 'value') {
317+
if (codeFunctions[i].type === 'value') {
314318
modeOptions.valueFunctions.push(codeFunctions[i].func);
315319
}
316-
else if (codeFunctions[i].category !== 'hidden') {
320+
else if (codeFunctions[i].type === 'either') {
321+
modeOptions.eitherFunctions.push(codeFunctions[i].func);
322+
}
323+
else if (codeFunctions[i].type !== 'hidden') {
317324
modeOptions.blockFunctions.push(codeFunctions[i].func);
318325
}
319326
}

blockly/src/webapp/api.js

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,22 @@ exports.createButton = function (blockId, elementId, text) {
3333
'text': text });
3434
};
3535

36-
exports.createCanvas = function (blockId, elementId) {
36+
exports.setPosition = function (blockId, elementId, left, top, width, height) {
37+
return Webapp.executeCmd(String(blockId),
38+
'setPosition',
39+
{'elementId': elementId,
40+
'left': left,
41+
'top': top,
42+
'width': width,
43+
'height': height });
44+
};
45+
46+
exports.createCanvas = function (blockId, elementId, width, height) {
3747
return Webapp.executeCmd(String(blockId),
3848
'createCanvas',
39-
{'elementId': elementId });
49+
{'elementId': elementId,
50+
'width': width,
51+
'height': height });
4052
};
4153

4254
exports.canvasDrawLine = function (blockId, elementId, x1, y1, x2, y2) {
@@ -58,6 +70,27 @@ exports.canvasDrawCircle = function (blockId, elementId, x, y, radius) {
5870
'radius': Number(radius) });
5971
};
6072

73+
exports.canvasSetLineWidth = function (blockId, elementId, width) {
74+
return Webapp.executeCmd(String(blockId),
75+
'canvasSetLineWidth',
76+
{'elementId': elementId,
77+
'width': Number(width) });
78+
};
79+
80+
exports.canvasSetStrokeColor = function (blockId, elementId, color) {
81+
return Webapp.executeCmd(String(blockId),
82+
'canvasSetStrokeColor',
83+
{'elementId': elementId,
84+
'color': color });
85+
};
86+
87+
exports.canvasSetFillColor = function (blockId, elementId, color) {
88+
return Webapp.executeCmd(String(blockId),
89+
'canvasSetFillColor',
90+
{'elementId': elementId,
91+
'color': color });
92+
};
93+
6194
exports.canvasClear = function (blockId, elementId) {
6295
return Webapp.executeCmd(String(blockId),
6396
'canvasClear',
@@ -71,6 +104,13 @@ exports.createTextInput = function (blockId, elementId, text) {
71104
'text': text });
72105
};
73106

107+
exports.createTextLabel = function (blockId, elementId, text) {
108+
return Webapp.executeCmd(String(blockId),
109+
'createTextLabel',
110+
{'elementId': elementId,
111+
'text': text });
112+
};
113+
74114
exports.getText = function (blockId, elementId) {
75115
return Webapp.executeCmd(String(blockId),
76116
'getText',
@@ -84,6 +124,13 @@ exports.setText = function (blockId, elementId, text) {
84124
'text': text });
85125
};
86126

127+
exports.setParent = function (blockId, elementId, parentId) {
128+
return Webapp.executeCmd(String(blockId),
129+
'setParent',
130+
{'elementId': elementId,
131+
'parentId': parentId });
132+
};
133+
87134
exports.setStyle = function (blockId, elementId, style) {
88135
return Webapp.executeCmd(String(blockId),
89136
'setStyle',

blockly/src/webapp/levels.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,34 @@ levels.ec_simple = {
3434
'codeFunctions': [
3535
{'func': 'createButton', 'params': ["'id'", "'text'"] },
3636
{'func': 'createTextInput', 'params': ["'id'", "'text'"] },
37-
{'func': 'getText', 'params': ["'id'"], 'category': 'value' },
37+
{'func': 'createTextLabel', 'params': ["'id'", "'text'"] },
38+
{'func': 'getText', 'params': ["'id'"], 'type': 'value' },
3839
{'func': 'setText', 'params': ["'id'", "'text'"] },
40+
{'func': 'setParent', 'params': ["'id'", "'parentId'"] },
41+
{'func': 'setPosition', 'params': ["'id'", "0", "0", "100", "100"] },
3942
{'func': 'setStyle', 'params': ["'id'", "'color:red;'"] },
4043
{'func': 'createHtmlBlock', 'params': ["'id'", "'html'"] },
4144
{'func': 'replaceHtmlBlock', 'params': ["'id'", "'html'"] },
4245
{'func': 'deleteHtmlBlock', 'params': ["'id'"] },
43-
{'func': 'createCanvas', 'params': ["'id'"] },
44-
{'func': 'canvasDrawLine', 'params': ["'id'", "0", "0", "400", "400"] },
45-
{'func': 'canvasDrawCircle', 'params': ["'id'", "200", "200", "100"] },
46-
{'func': 'canvasClear', 'params': ["'id'"] },
4746
{'func': 'attachEventHandler', 'params': ["'id'", "'click'", "function() {\n \n}"] },
47+
{'func': 'createCanvas', 'category': 'Canvas', 'params': ["'id'", "400", "400"] },
48+
{'func': 'canvasDrawLine', 'category': 'Canvas', 'params': ["'id'", "0", "0", "400", "400"] },
49+
{'func': 'canvasDrawCircle', 'category': 'Canvas', 'params': ["'id'", "200", "200", "100"] },
50+
{'func': 'canvasSetLineWidth', 'category': 'Canvas', 'params': ["'id'", "3"] },
51+
{'func': 'canvasSetStrokeColor', 'category': 'Canvas', 'params': ["'id'", "'red'"] },
52+
{'func': 'canvasSetFillColor', 'category': 'Canvas', 'params': ["'id'", "'yellow'"] },
53+
{'func': 'canvasClear', 'category': 'Canvas', 'params': ["'id'"] },
4854
],
55+
'categoryInfo': {
56+
'Canvas': {
57+
'color': 'yellow',
58+
'blocks': []
59+
},
60+
'Actions': {
61+
'color': 'blue',
62+
'blocks': []
63+
},
64+
},
4965
};
5066

5167
levels.full_sandbox = {

blockly/src/webapp/webapp.js

Lines changed: 94 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,10 +1011,16 @@ Webapp.callCmd = function (cmd) {
10111011
case 'createCanvas':
10121012
case 'canvasDrawLine':
10131013
case 'canvasDrawCircle':
1014+
case 'canvasSetLineWidth':
1015+
case 'canvasSetStrokeColor':
1016+
case 'canvasSetFillColor':
10141017
case 'canvasClear':
10151018
case 'createTextInput':
1019+
case 'createTextLabel':
10161020
case 'getText':
10171021
case 'setText':
1022+
case 'setPosition':
1023+
case 'setParent':
10181024
case 'setStyle':
10191025
case 'attachEventHandler':
10201026
BlocklyApps.highlight(cmd.id);
@@ -1049,12 +1055,22 @@ Webapp.createCanvas = function (opts) {
10491055
var divWebapp = document.getElementById('divWebapp');
10501056

10511057
var newElement = document.createElement("canvas");
1052-
newElement.id = opts.elementId;
1053-
// TODO: support creating canvas elements of different sizes
1054-
newElement.width = 400 * Webapp.canvasScale;
1055-
newElement.height = 400 * Webapp.canvasScale;
1056-
1057-
return Boolean(divWebapp.appendChild(newElement));
1058+
var ctx = newElement.getContext("2d");
1059+
if (newElement && ctx) {
1060+
newElement.id = opts.elementId;
1061+
// default width/height if params are missing
1062+
var width = opts.width || 400;
1063+
var height = opts.height || 400;
1064+
newElement.width = width * Webapp.canvasScale;
1065+
newElement.height = height * Webapp.canvasScale;
1066+
newElement.style.width = width + 'px';
1067+
newElement.style.height = height + 'px';
1068+
// set transparent fill by default:
1069+
ctx.fillStyle = "rgba(255, 255, 255, 0)";
1070+
1071+
return Boolean(divWebapp.appendChild(newElement));
1072+
}
1073+
return false;
10581074
};
10591075

10601076
Webapp.canvasDrawLine = function (opts) {
@@ -1081,17 +1097,52 @@ Webapp.canvasDrawCircle = function (opts) {
10811097
opts.radius * Webapp.canvasScale,
10821098
0,
10831099
2 * Math.PI);
1100+
ctx.fill();
10841101
ctx.stroke();
10851102
}
10861103
return false;
10871104
};
10881105

1106+
Webapp.canvasSetLineWidth = function (opts) {
1107+
var divWebapp = document.getElementById('divWebapp');
1108+
var div = document.getElementById(opts.elementId);
1109+
var ctx = div.getContext("2d");
1110+
if (ctx && divWebapp.contains(div)) {
1111+
ctx.setLineWidth(opts.width * Webapp.canvasScale);
1112+
return true;
1113+
}
1114+
return false;
1115+
};
1116+
1117+
Webapp.canvasSetStrokeColor = function (opts) {
1118+
var divWebapp = document.getElementById('divWebapp');
1119+
var div = document.getElementById(opts.elementId);
1120+
var ctx = div.getContext("2d");
1121+
if (ctx && divWebapp.contains(div)) {
1122+
ctx.setStrokeColor(opts.color);
1123+
return true;
1124+
}
1125+
return false;
1126+
};
1127+
1128+
Webapp.canvasSetFillColor = function (opts) {
1129+
var divWebapp = document.getElementById('divWebapp');
1130+
var div = document.getElementById(opts.elementId);
1131+
var ctx = div.getContext("2d");
1132+
if (ctx && divWebapp.contains(div)) {
1133+
ctx.setFillColor(opts.color);
1134+
return true;
1135+
}
1136+
return false;
1137+
};
1138+
10891139
Webapp.canvasClear = function (opts) {
10901140
var divWebapp = document.getElementById('divWebapp');
10911141
var div = document.getElementById(opts.elementId);
10921142
var ctx = div.getContext("2d");
10931143
if (ctx && divWebapp.contains(div)) {
10941144
ctx.clearRect(0, 0, div.width, div.height);
1145+
return true;
10951146
}
10961147
return false;
10971148
};
@@ -1106,6 +1157,17 @@ Webapp.createTextInput = function (opts) {
11061157
return Boolean(divWebapp.appendChild(newInput));
11071158
};
11081159

1160+
Webapp.createTextLabel = function (opts) {
1161+
var divWebapp = document.getElementById('divWebapp');
1162+
1163+
var newLabel = document.createElement("label");
1164+
var textNode = document.createTextNode(opts.text);
1165+
newLabel.id = opts.elementId;
1166+
1167+
return Boolean(newLabel.appendChild(textNode) &&
1168+
divWebapp.appendChild(newLabel));
1169+
};
1170+
11091171
Webapp.getText = function (opts) {
11101172
var divWebapp = document.getElementById('divWebapp');
11111173
var div = document.getElementById(opts.elementId);
@@ -1150,7 +1212,32 @@ Webapp.setStyle = function (opts) {
11501212
var divWebapp = document.getElementById('divWebapp');
11511213
var div = document.getElementById(opts.elementId);
11521214
if (divWebapp.contains(div)) {
1153-
div.style.cssText = opts.style;
1215+
div.style.cssText += opts.style;
1216+
return true;
1217+
}
1218+
return false;
1219+
};
1220+
1221+
Webapp.setParent = function (opts) {
1222+
var divWebapp = document.getElementById('divWebapp');
1223+
var div = document.getElementById(opts.elementId);
1224+
var divNewParent = document.getElementById(opts.parentId);
1225+
if (divWebapp.contains(div) && divWebapp.contains(divNewParent)) {
1226+
return Boolean(div.parentElement.removeChild(div) &&
1227+
divNewParent.appendChild(div));
1228+
}
1229+
return false;
1230+
};
1231+
1232+
Webapp.setPosition = function (opts) {
1233+
var divWebapp = document.getElementById('divWebapp');
1234+
var div = document.getElementById(opts.elementId);
1235+
if (divWebapp.contains(div)) {
1236+
div.style.position = 'absolute';
1237+
div.style.left = String(opts.left) + 'px';
1238+
div.style.top = String(opts.top) + 'px';
1239+
div.style.width = String(opts.width) + 'px';
1240+
div.style.height = String(opts.height) + 'px';
11541241
return true;
11551242
}
11561243
return false;

blockly/style/webapp/style.scss

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
$root: '/blockly/media/webapp/'; //TODO: Parameterize for asset pipeline
22

3+
.droplet-palette-group-header.yellow {
4+
border-left:10px solid #e0e053;
5+
}
6+
.droplet-palette-group-header-selected.yellow {
7+
background-color: #e0e053;
8+
}
9+
310
#divWebapp {
411
overflow: hidden;
512
position: relative;
@@ -14,8 +21,6 @@ $root: '/blockly/media/webapp/'; //TODO: Parameterize for asset pipeline
1421
overflow: hidden;
1522
top: 0px;
1623
left: 0px;
17-
width: 400px;
18-
height: 400px;
1924
z-index: -1;
2025
}
2126

pegasus/emails/hoc_signup_2014_receipt.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ litmus_tracking_id: "5g5lyi1a"
55
---
66
<% hostname = CDO.canonical_hostname('hourofcode.com') %>
77

8+
<% if @country == 'ro' %>
9+
10+
Va multumim pentru inregistrare. Daca aveti nevoie de ajutor sau aveti orice intrebare contactati Echipa Hour of Code Romania la adresa: [email protected].
11+
12+
<% end %>
13+
814
# Thanks for signing up to host an Hour of Code!
915

1016
**EVERY** Hour of Code organizer will receive 10 GB of Dropbox space or $10 of Skype credit as a thank you. [Details](http://<%= hostname %>/prizes)
@@ -28,15 +34,6 @@ Recruit a local group — boy/girl scouts club, church, university, veterans gro
2834
## 5. Ask a local elected official to support the Hour of Code
2935
[Send this email](http://<%= hostname %>/resources#politicians) to your mayor, city council, or school board. Or [give them this handout](http://<%= hostname %>/resources/hoc-one-pager.pdf) and invite them to visit your school.
3036

31-
<% if @country == 'ro' %>
32-
33-
Multumim ca ne-ai anuntat despre evenimentul tau! Anunta-ne daca doresti informatii suplimentare sau daca ai intrebari. Hai sa facem istorie impreuna!
34-
35-
Echipa Hour of Code Romania
36-
37-
38-
<% end %>
39-
4037
<hr/>
4138

4239
Code.org is a 501c3 non-profit. Our address is 1301 5th Ave, Suite 1225, Seattle, WA, 98101. Don't like these emails? [Unsubscribe](<%= unsubscribe_link %>).

0 commit comments

Comments
 (0)