app/assets/htmls/gs-element-blockly.html in gobstones-blockly-0.10.3 vs app/assets/htmls/gs-element-blockly.html in gobstones-blockly-0.11.0
- old
+ new
@@ -5657,10 +5657,13 @@
'stroke-width: 3px;',
'}',
];</script>
<script>
+ const BLOCKLY_PRIMITIVE_PROCEDURES = "Procedimientos primitivos";
+ const BLOCKLY_PRIMITIVE_FUNCTIONS = "Funciones primitivas";
+
Polymer({
is: 'gs-element-blockly',
properties: {
/*
@@ -5743,10 +5746,18 @@
*/
media: {
type: String,
value: "../bower_components/blockly-package/media/"
},
+
+ /*
+ * `readOnly` Use blockly in readOnly mode.
+ */
+ readOnly: {
+ type: Boolean,
+ value: false
+ },
},
_onPrimitiveProceduresChange: function() {
if(typeof this.primitiveProcedures == 'string') {
this.primitiveProcedures = JSON.parse(this.primitiveProcedures);
@@ -5795,17 +5806,16 @@
},
/**
* Retorna el arbol por defecto de bloques y categorias
*/
- _defaultToolboxTree : function() {
+ _defaultToolboxTree : function(toolboxXML) {
const primitiveProcedures = this._getPrimitiveNames(this.primitiveProcedures);
const primitiveFunctions = this._getPrimitiveNames(this.primitiveFunctions);
let tree = []
- let toolboxDefault = this.$$('#toolbox');
- let toolboxDefaultLines = toolboxDefault.innerHTML.split("\n");
+ let toolboxDefaultLines = (toolboxXML || this.$$('#toolbox').innerHTML).split("\n");
let ignore_last = false;
let parent = tree;
let stack = [];
for(var i in toolboxDefaultLines) {
let line = toolboxDefaultLines[i];
@@ -5819,31 +5829,31 @@
}
}
else if(line.indexOf('<category') >= 0) {
let m = line.match('name="([^"]*)"')
if(m.length == 2 && (
- (m[1] == 'Procedimientos primitivos' && primitiveProcedures && primitiveProcedures.length > 0) ||
- (m[1] == 'Funciones primitivas' && primitiveFunctions && primitiveFunctions.length > 0) ||
- (m[1] != 'Procedimientos primitivos' && m[1] != 'Funciones primitivas'))) {
+ (m[1] == BLOCKLY_PRIMITIVE_PROCEDURES && primitiveProcedures && primitiveProcedures.length > 0) ||
+ (m[1] == BLOCKLY_PRIMITIVE_FUNCTIONS && primitiveFunctions && primitiveFunctions.length > 0) ||
+ (m[1] != BLOCKLY_PRIMITIVE_PROCEDURES && m[1] != BLOCKLY_PRIMITIVE_FUNCTIONS))) {
parent.push({
type: 'category',
name: m[1],
child: [],
xml: line
});
stack.push(parent);
parent = parent[parent.length - 1].child;
- if(m[1] == 'Procedimientos primitivos')
+ if(m[1] == BLOCKLY_PRIMITIVE_PROCEDURES)
{
for(var i in primitiveProcedures) {
parent.push({
type: 'block',
name: primitiveProcedures[i],
});
}
}
- if(m[1] == 'Funciones primitivas')
+ if(m[1] == BLOCKLY_PRIMITIVE_FUNCTIONS)
{
for(var i in primitiveFunctions) {
parent.push({
type: 'block',
name: primitiveFunctions[i],
@@ -5889,11 +5899,11 @@
const primitiveFunctions = this._getPrimitiveNames(this.primitiveFunctions);
let tree = this._defaultToolboxTree();
let toolbox = [];
- if(this.toolbox) {
+ if (this.toolbox) {
let visibles = this._homogenizeIDs(this.toolbox.visible);
let disabled = this._homogenizeIDs(this.toolbox.disabled);
if(visibles.length > 0) {
visibles = visibles.concat(disabled);
if(primitiveProcedures) {
@@ -5934,12 +5944,32 @@
}
}
}
marcarDisabled(toolbox);
- }
- else {
+ const addCustomActions = (type, categoryName) => {
+ if (this.toolbox[type]) {
+ const customTree = this._defaultToolboxTree(this.toolbox[type]);
+
+ const addCustomActionsChilds = (ttree) => {
+ for (var item of ttree) {
+ if (item.type !== "category") continue;
+
+ if (item.name === BLOCKLY_PRIMITIVE_PROCEDURES)
+ item.child = customTree;
+ else
+ addCustomActionsChilds(item.child);
+ }
+ };
+
+ addCustomActionsChilds(toolbox);
+ }
+ };
+
+ addCustomActions("primitiveProcedures", BLOCKLY_PRIMITIVE_PROCEDURES);
+ addCustomActions("primitiveFunctions", BLOCKLY_PRIMITIVE_FUNCTIONS);
+ } else {
toolbox = tree;
}
return this._toolboxTreeToXML(toolbox);
},
@@ -6327,9 +6357,10 @@
toolboxPosition: "start",
scrollbars: true,
horizontalLayout: false,
collapse: true,
css: true,
+ readOnly: this.readOnly,
zoom: {
controls: true,
wheel: true
}
});
\ No newline at end of file