Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
ardublockly
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
ardublockly
Commits
7d1f2c17
Commit
7d1f2c17
authored
Feb 15, 2016
by
carlosperate
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow additional blocks to extend the Ardublockly functionality.
parent
192bb341
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
75 additions
and
34 deletions
+75
-34
ardublockly/ardublockly.js
ardublockly/ardublockly.js
+44
-11
ardublockly/ardublockly_blockly.js
ardublockly/ardublockly_blockly.js
+3
-5
ardublockly/ardublocklyserver_ajax.js
ardublockly/ardublocklyserver_ajax.js
+8
-1
blocks/blocks_data.json
blocks/blocks_data.json
+10
-8
blocks/test/blocks_config.json
blocks/test/blocks_config.json
+5
-5
blocks/test_2/blocks_config.json
blocks/test_2/blocks_config.json
+5
-4
No files found.
ardublockly/ardublockly.js
View file @
7d1f2c17
...
...
@@ -689,19 +689,52 @@ Ardublockly.importExtraBlocks = function() {
if
(
jsonDataObj
===
null
)
return
Ardublockly
.
openNotConnectedModal
();
if
(
jsonDataObj
.
categories
!==
undefined
)
{
var
head
=
document
.
getElementsByTagName
(
'
head
'
)[
0
];
for
(
var
cat
egory
Dir
in
jsonDataObj
.
categories
)
{
for
(
var
catDir
in
jsonDataObj
.
categories
)
{
var
blocksJsLoad
=
document
.
createElement
(
'
script
'
);
blocksJsLoad
.
src
=
'
../blocks/
'
+
cat
egory
Dir
+
'
/blocks.js
'
;
blocksJsLoad
.
src
=
'
../blocks/
'
+
catDir
+
'
/blocks.js
'
;
head
.
appendChild
(
blocksJsLoad
);
var
blocksLangJsLoad
=
document
.
createElement
(
'
script
'
);
blocksLangJsLoad
.
src
=
'
../blocks/
'
+
cat
egoryDir
+
'
/msg/
'
+
blocksLangJsLoad
.
src
=
'
../blocks/
'
+
cat
Dir
+
'
/msg/
'
+
'
messages.js
'
;
//'lang/' + Ardublockly.LANG + '.js';
'
messages.js
'
;
head
.
appendChild
(
blocksLangJsLoad
);
var
blocksGeneratorJsLoad
=
document
.
createElement
(
'
script
'
);
blocksGeneratorJsLoad
.
src
=
'
../blocks/
'
+
cat
egory
Dir
+
blocksGeneratorJsLoad
.
src
=
'
../blocks/
'
+
catDir
+
'
/generator_arduino.js
'
;
head
.
appendChild
(
blocksGeneratorJsLoad
);
// Check if the blocks add additional Ardublockly functionality
var
extensions
=
jsonDataObj
.
categories
[
catDir
].
extensions
if
(
extensions
)
{
for
(
var
i
=
0
;
i
<
extensions
.
length
;
i
++
)
{
var
blockExtensionJsLoad
=
document
.
createElement
(
'
script
'
);
blockExtensionJsLoad
.
src
=
'
../blocks/
'
+
catDir
+
'
/extensions.js
'
;
head
.
appendChild
(
blockExtensionJsLoad
);
// Add function to scheduler as lazy loading has to complete first
setTimeout
(
function
(
category
,
extension
)
{
var
extensionNamespaces
=
extension
.
split
(
'
.
'
);
var
extensionCall
=
window
;
var
invalidFunc
=
false
;
for
(
var
j
=
0
;
j
<
extensionNamespaces
.
length
;
j
++
)
{
extensionCall
=
extensionCall
[
extensionNamespaces
[
j
]];
if
(
extensionCall
===
undefined
)
{
invalidFunc
=
true
;
break
;
}
}
if
(
typeof
extensionCall
!=
'
function
'
)
{
invalidFunc
=
true
;
}
if
(
invalidFunc
)
{
throw
'
Blocks
'
+
category
.
categoryName
+
'
extension "
'
+
extension
+
'
" is not a valid function.
'
;
}
else
{
extensionCall
();
}
},
800
,
jsonDataObj
.
categories
[
catDir
],
extensions
[
i
]);
}
}
}
}
};
...
...
@@ -721,21 +754,21 @@ Ardublockly.openExtraCategoriesSelect = function() {
if
(
jsonDataObj
===
null
)
return
Ardublockly
.
openNotConnectedModal
();
var
htmlContent
=
document
.
createElement
(
'
div
'
);
if
(
jsonDataObj
.
categories
!==
undefined
)
{
for
(
var
cat
egory
Dir
in
jsonDataObj
.
categories
)
{
for
(
var
catDir
in
jsonDataObj
.
categories
)
{
// Function required to maintain each loop variable scope separated
(
function
(
cat
)
{
var
clickBind
=
function
(
tickValue
)
{
if
(
tickValue
)
{
var
catDom
=
(
new
DOMParser
()).
parseFromString
(
cat
.
toolbox
,
'
text/xml
'
)
;
Ardublockly
.
addToolboxCategory
(
cat
.
category
Name
,
catDom
);
cat
.
toolbox
.
join
(
''
),
'
text/xml
'
).
firstChild
;
Ardublockly
.
addToolboxCategory
(
cat
.
toolbox
Name
,
catDom
);
}
else
{
Ardublockly
.
removeToolboxCategory
(
cat
.
category
Name
);
Ardublockly
.
removeToolboxCategory
(
cat
.
toolbox
Name
);
}
};
htmlContent
.
appendChild
(
Ardublockly
.
createExtraBlocksCatHtml
(
cat
.
n
ame
,
cat
.
description
,
clickBind
));
})(
jsonDataObj
.
categories
[
cat
egory
Dir
]);
cat
.
categoryN
ame
,
cat
.
description
,
clickBind
));
})(
jsonDataObj
.
categories
[
catDir
]);
}
}
Ardublockly
.
openAdditionalBlocksModal
(
htmlContent
);
...
...
ardublockly/ardublockly_blockly.js
View file @
7d1f2c17
...
...
@@ -225,12 +225,10 @@ Ardublockly.updateToolboxLanguage = function() {
* @param {!Element} categoryDom Toolbox category to add add the end of tree.
*/
Ardublockly
.
addToolboxCategory
=
function
(
categoryTitle
,
categoryDom
)
{
var
categoryNode
=
document
.
createElement
(
'
category
'
);
categoryNode
.
id
=
'
cat
'
+
categoryTitle
.
replace
(
/
\s
+/g
,
''
);
categoryNode
.
setAttribute
(
'
name
'
,
categoryTitle
);
categoryNode
.
appendChild
(
categoryDom
.
firstChild
);
categoryDom
.
id
=
'
cat
'
+
categoryTitle
.
replace
(
/
\s
+/g
,
''
);
categoryDom
.
setAttribute
(
'
name
'
,
categoryTitle
);
Ardublockly
.
xmlTree
.
appendChild
(
document
.
createElement
(
'
sep
'
));
Ardublockly
.
xmlTree
.
appendChild
(
category
Node
);
Ardublockly
.
xmlTree
.
appendChild
(
category
Dom
);
Ardublockly
.
workspace
.
updateToolbox
(
Ardublockly
.
xmlTree
);
};
...
...
ardublockly/ardublocklyserver_ajax.js
View file @
7d1f2c17
...
...
@@ -94,7 +94,14 @@ Ardublockly.getJsonData = function(fileLocation, jsonDataCb) {
var
requestCb
=
function
()
{
if
(
request
.
readyState
==
4
)
{
if
(
request
.
status
==
200
)
{
jsonDataCb
(
JSON
.
parse
(
request
.
responseText
));
var
jsonObj
=
null
;
try
{
jsonObj
=
JSON
.
parse
(
request
.
responseText
);
}
catch
(
e
)
{
console
.
error
(
'
Incorrectly formatted JSON data from
'
+
fileLocation
);
throw
e
;
}
jsonDataCb
(
jsonObj
);
}
else
{
jsonDataCb
(
null
);
}
...
...
blocks/blocks_data.json
View file @
7d1f2c17
{
"categories"
:
{
"test"
:
{
"
n
ame"
:
"Test blocks"
,
"
categoryN
ame"
:
"Test blocks"
,
"description"
:
"Test blocks to demonstrate the feature."
,
"categoryName"
:
"Test"
,
"languages"
:
[
"en"
,
"es"
],
"toolboxName"
:
"Test"
,
"toolbox"
:
[
"<block type=
\"
ardublockly_name_top
\"
>"
,
"</block>"
"<category>"
,
" <block type=
\"
ardublockly_name_top
\"
></block>"
,
"</category>"
]
},
"test_2"
:
{
"
n
ame"
:
"Another Test blocks Section 2"
,
"
categoryN
ame"
:
"Another Test blocks Section 2"
,
"description"
:
"Second test blocks to demonstrate the feature."
,
"categoryName"
:
"Test 2"
,
"languages"
:
[
"en"
,
"es"
],
"toolboxName"
:
"Test 2"
,
"toolbox"
:
[
"<block type=
\"
ardublockly_name_bottom
\"
>"
,
"</block>"
"<category>"
,
" <block type=
\"
ardublockly_name_bottom
\"
></block>"
,
"</category>"
]
}
}
...
...
blocks/test/blocks_config.json
View file @
7d1f2c17
{
"
n
ame"
:
"Test blocks"
,
"
categoryN
ame"
:
"Test blocks"
,
"description"
:
"Test blocks to demonstrate the feature."
,
"categoryName"
:
"Test"
,
"languages"
:
[
"en"
,
"es"
],
"toolboxName"
:
"Test"
,
"toolbox"
:
[
"<block type=
\"
ardublockly_name_top
\"
>"
,
"</block>"
"<category>"
,
" <block type=
\"
ardublockly_name_top
\"
></block>"
,
"</category>"
]
}
blocks/test_2/blocks_config.json
View file @
7d1f2c17
{
"
n
ame"
:
"Another Test blocks Section 2"
,
"
categoryN
ame"
:
"Another Test blocks Section 2"
,
"description"
:
"Second test blocks to demonstrate the feature."
,
"categoryName"
:
"Test 2"
,
"languages"
:
[
"en"
,
"es"
],
"toolboxName"
:
"Test 2"
,
"toolbox"
:
[
"<block type=
\"
ardublockly_name_bottom
\"
>"
,
"</block>"
"<category>"
,
" <block type=
\"
ardublockly_name_bottom
\"
></block>"
,
"</category>"
]
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment