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
5c10f64a
Commit
5c10f64a
authored
Dec 23, 2014
by
carlosperate
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed dependency to common.js file in Arduino App.
parent
b7ffa86c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
108 additions
and
19 deletions
+108
-19
apps/arduino/arduino.js
apps/arduino/arduino.js
+108
-16
apps/arduino/index.html
apps/arduino/index.html
+0
-3
No files found.
apps/arduino/arduino.js
View file @
5c10f64a
...
@@ -35,7 +35,7 @@ Arduino.tabClick = function(clickedName) {
...
@@ -35,7 +35,7 @@ Arduino.tabClick = function(clickedName) {
xmlDom
=
Blockly
.
Xml
.
textToDom
(
xmlText
);
xmlDom
=
Blockly
.
Xml
.
textToDom
(
xmlText
);
}
catch
(
e
)
{
}
catch
(
e
)
{
var
q
=
var
q
=
window
.
confirm
(
BlocklyApps
.
getMsg
(
'
Code_badXml
'
).
replace
(
'
%1
'
,
e
));
window
.
confirm
(
Arduino
.
getMsg
(
'
Code_badXml
'
).
replace
(
'
%1
'
,
e
));
if
(
!
q
)
{
if
(
!
q
)
{
// Leave the user on the XML tab.
// Leave the user on the XML tab.
return
;
return
;
...
@@ -96,7 +96,7 @@ Arduino.init = function() {
...
@@ -96,7 +96,7 @@ Arduino.init = function() {
var
container
=
document
.
getElementById
(
'
content_area
'
);
var
container
=
document
.
getElementById
(
'
content_area
'
);
var
onresize
=
function
(
e
)
{
var
onresize
=
function
(
e
)
{
var
bBox
=
BlocklyApps
.
getBBox_
(
container
);
var
bBox
=
Arduino
.
getBBox_
(
container
);
for
(
var
i
=
0
;
i
<
Arduino
.
TABS_
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
Arduino
.
TABS_
.
length
;
i
++
)
{
var
el
=
document
.
getElementById
(
'
content_
'
+
Arduino
.
TABS_
[
i
]);
var
el
=
document
.
getElementById
(
'
content_
'
+
Arduino
.
TABS_
[
i
]);
el
.
style
.
top
=
bBox
.
y
+
'
px
'
;
el
.
style
.
top
=
bBox
.
y
+
'
px
'
;
...
@@ -123,7 +123,7 @@ Arduino.init = function() {
...
@@ -123,7 +123,7 @@ Arduino.init = function() {
rtl
:
false
,
rtl
:
false
,
toolbox
:
toolbox
});
toolbox
:
toolbox
});
//
BlocklyApps
.loadBlocks('');
//
Arduino
.loadBlocks('');
//if ('BlocklyStorage' in window) {
//if ('BlocklyStorage' in window) {
// // Hook a save function onto unload.
// // Hook a save function onto unload.
...
@@ -134,14 +134,14 @@ Arduino.init = function() {
...
@@ -134,14 +134,14 @@ Arduino.init = function() {
Blockly
.
fireUiEvent
(
window
,
'
resize
'
);
Blockly
.
fireUiEvent
(
window
,
'
resize
'
);
// Binding buttons
// Binding buttons
BlocklyApps
.
bindClick
(
'
trashButton
'
,
Arduino
.
discard
);
Arduino
.
bindClick
(
'
trashButton
'
,
Arduino
.
discard
);
BlocklyApps
.
bindClick
(
'
runButton
'
,
Arduino
.
loadToArduino
);
Arduino
.
bindClick
(
'
runButton
'
,
Arduino
.
loadToArduino
);
BlocklyApps
.
bindClick
(
'
peekCode
'
,
Arduino
.
peekCode
);
Arduino
.
bindClick
(
'
peekCode
'
,
Arduino
.
peekCode
);
// Binding tabs
// Binding tabs
for
(
var
i
=
0
;
i
<
Arduino
.
TABS_
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
Arduino
.
TABS_
.
length
;
i
++
)
{
var
name
=
Arduino
.
TABS_
[
i
];
var
name
=
Arduino
.
TABS_
[
i
];
BlocklyApps
.
bindClick
(
'
tab_
'
+
name
,
Arduino
.
bindClick
(
'
tab_
'
+
name
,
function
(
name_
)
{
return
function
()
{
Arduino
.
tabClick
(
name_
);};}(
name
));
function
(
name_
)
{
return
function
()
{
Arduino
.
tabClick
(
name_
);};}(
name
));
}
}
};
};
...
@@ -156,13 +156,13 @@ Arduino.adjustViewport = function() {
...
@@ -156,13 +156,13 @@ Arduino.adjustViewport = function() {
viewport
.
setAttribute
(
'
content
'
,
viewport
.
setAttribute
(
'
content
'
,
'
width=725, initial-scale=.35, user-scalable=no
'
);
'
width=725, initial-scale=.35, user-scalable=no
'
);
}
}
}
}
;
/**
/**
* Load and execute the user's code to the Arduino.
* Load and execute the user's code to the Arduino.
*/
*/
Arduino
.
loadToArduino
=
function
()
{
Arduino
.
loadToArduino
=
function
()
{
//
TODO
//
TODO: Add ajax function call to send string with code to Python server
};
};
/**
/**
...
@@ -171,7 +171,7 @@ Arduino.loadToArduino = function() {
...
@@ -171,7 +171,7 @@ Arduino.loadToArduino = function() {
Arduino
.
discard
=
function
()
{
Arduino
.
discard
=
function
()
{
var
count
=
Blockly
.
mainWorkspace
.
getAllBlocks
().
length
;
var
count
=
Blockly
.
mainWorkspace
.
getAllBlocks
().
length
;
if
(
count
<
2
||
if
(
count
<
2
||
window
.
confirm
(
BlocklyApps
.
getMsg
(
'
Code_discard
'
).
replace
(
'
%1
'
,
count
)))
{
window
.
confirm
(
Arduino
.
getMsg
(
'
Code_discard
'
).
replace
(
'
%1
'
,
count
)))
{
Blockly
.
mainWorkspace
.
clear
();
Blockly
.
mainWorkspace
.
clear
();
window
.
location
.
hash
=
''
;
window
.
location
.
hash
=
''
;
}
}
...
@@ -198,8 +198,8 @@ Arduino.peekCode = function(visible) {
...
@@ -198,8 +198,8 @@ Arduino.peekCode = function(visible) {
Arduino
.
sideContent
(
true
);
Arduino
.
sideContent
(
true
);
code_peek_content
.
style
.
display
=
'
inline-block
'
;
code_peek_content
.
style
.
display
=
'
inline-block
'
;
// Regenerate arduino code and ensure every click does as well
// Regenerate arduino code and ensure every click does as well
Arduino
.
renderArduinoPe
ak
();
Arduino
.
renderArduinoPe
ekCode
();
Blockly
.
addChangeListener
(
Arduino
.
renderArduinoPe
ak
);
Blockly
.
addChangeListener
(
Arduino
.
renderArduinoPe
ekCode
);
}
else
{
}
else
{
Arduino
.
peek_code
=
false
;
Arduino
.
peek_code
=
false
;
peek_code_button
.
className
=
"
notext
"
;
peek_code_button
.
className
=
"
notext
"
;
...
@@ -207,7 +207,7 @@ Arduino.peekCode = function(visible) {
...
@@ -207,7 +207,7 @@ Arduino.peekCode = function(visible) {
Arduino
.
sideContent
(
false
);
Arduino
.
sideContent
(
false
);
// Remove action listeners. TODO: track listener so that first time does not
// Remove action listeners. TODO: track listener so that first time does not
// crashes
// crashes
//Blockly.removeChangeListener(renderArduinoPe
ak
);
//Blockly.removeChangeListener(renderArduinoPe
ekCode
);
}
}
};
};
...
@@ -244,15 +244,107 @@ Arduino.sideContent = function(visible) {
...
@@ -244,15 +244,107 @@ Arduino.sideContent = function(visible) {
Blockly
.
fireUiEvent
(
window
,
'
resize
'
);
Blockly
.
fireUiEvent
(
window
,
'
resize
'
);
Arduino
.
renderContent
();
Arduino
.
renderContent
();
}
}
;
/**
/**
* Updates the arduino code in the pre area based on the blocks
* Updates the arduino code in the pre area based on the blocks
*/
*/
Arduino
.
renderArduinoPe
ak
=
function
()
{
Arduino
.
renderArduinoPe
ekCode
=
function
()
{
var
code_peak_pre
=
document
.
getElementById
(
'
arduino_pre
'
);
var
code_peak_pre
=
document
.
getElementById
(
'
arduino_pre
'
);
code_peak_pre
.
textContent
=
Blockly
.
Arduino
.
workspaceToCode
();
code_peak_pre
.
textContent
=
Blockly
.
Arduino
.
workspaceToCode
();
if
(
typeof
prettyPrintOne
==
'
function
'
)
{
if
(
typeof
prettyPrintOne
==
'
function
'
)
{
code_peak_pre
.
innerHTML
=
prettyPrintOne
(
code_peak_pre
.
innerHTML
,
'
cpp
'
);
code_peak_pre
.
innerHTML
=
prettyPrintOne
(
code_peak_pre
.
innerHTML
,
'
cpp
'
);
}
}
}
};
/**
* Gets the message with the given key from the document.
* @param {string} key The key of the document element.
* @return {string} The textContent of the specified element,
* or an error message if the element was not found.
*/
Arduino
.
getMsg
=
function
(
key
)
{
var
element
=
document
.
getElementById
(
key
);
if
(
element
)
{
var
text
=
element
.
textContent
;
// Convert newline sequences.
text
=
text
.
replace
(
/
\\
n/g
,
'
\n
'
);
return
text
;
}
else
{
return
'
[Unknown message:
'
+
key
+
'
]
'
;
}
};
/**
* Bind a function to a button's click event.
* On touch enabled browsers, ontouchend is treated as equivalent to onclick.
* @param {!Element|string} el Button element or ID thereof.
* @param {!Function} func Event handler to bind.
*/
Arduino
.
bindClick
=
function
(
el
,
func
)
{
if
(
typeof
el
==
'
string
'
)
{
el
=
document
.
getElementById
(
el
);
}
el
.
addEventListener
(
'
click
'
,
func
,
true
);
el
.
addEventListener
(
'
touchend
'
,
func
,
true
);
};
/**
* Compute the absolute coordinates and dimensions of an HTML or SVG element.
* @param {!Element} element Element to match.
* @return {!Object} Contains height, width, x, and y properties.
* @private
*/
Arduino
.
getBBox_
=
function
(
element
)
{
if
(
element
.
getBBox
)
{
// SVG element.
var
bBox
=
element
.
getBBox
();
var
height
=
bBox
.
height
;
var
width
=
bBox
.
width
;
var
xy
=
Blockly
.
getAbsoluteXY_
(
element
);
var
x
=
xy
.
x
;
var
y
=
xy
.
y
;
}
else
{
// HTML element.
var
height
=
element
.
offsetHeight
;
var
width
=
element
.
offsetWidth
;
var
x
=
0
;
var
y
=
0
;
do
{
x
+=
element
.
offsetLeft
;
y
+=
element
.
offsetTop
;
element
=
element
.
offsetParent
;
}
while
(
element
);
}
return
{
height
:
height
,
width
:
width
,
x
:
x
,
y
:
y
};
};
/**
* Load blocks saved in session/local storage.
* @param {string} defaultXml Text representation of default blocks.
*/
Arduino
.
loadBlocks
=
function
(
defaultXml
)
{
try
{
var
loadOnce
=
window
.
sessionStorage
.
loadOnceBlocks
;
}
catch
(
e
)
{
// Firefox sometimes throws a SecurityError when accessing sessionStorage.
// Restarting Firefox fixes this, so it looks like a bug.
var
loadOnce
=
null
;
}
if
(
loadOnce
)
{
// Language switching stores the blocks during the reload.
delete
window
.
sessionStorage
.
loadOnceBlocks
;
var
xml
=
Blockly
.
Xml
.
textToDom
(
loadOnce
);
Blockly
.
Xml
.
domToWorkspace
(
Blockly
.
mainWorkspace
,
xml
);
}
else
if
(
defaultXml
)
{
// Load the editor with default starting blocks.
var
xml
=
Blockly
.
Xml
.
textToDom
(
defaultXml
);
Blockly
.
Xml
.
domToWorkspace
(
Blockly
.
mainWorkspace
,
xml
);
}
};
apps/arduino/index.html
View file @
5c10f64a
...
@@ -8,9 +8,7 @@
...
@@ -8,9 +8,7 @@
<link
rel=
"stylesheet"
href=
"style.css"
>
<link
rel=
"stylesheet"
href=
"style.css"
>
<link
rel=
"stylesheet"
href=
"../../demos/prettify.css"
>
<link
rel=
"stylesheet"
href=
"../../demos/prettify.css"
>
<script
src=
"../../demos/prettify.js"
></script>
<script
src=
"../../demos/prettify.js"
></script>
<script
src=
"../common.js"
></script>
<script
src=
"arduino.js"
></script>
<script
src=
"arduino.js"
></script>
<!--script src="../../blockly_compressed.js"></script-->
<!--script src="../../blockly_compressed.js"></script-->
<script
src=
"../../blockly_uncompressed.js"
></script>
<script
src=
"../../blockly_uncompressed.js"
></script>
<!--script src="../../blocks_compressed.js"></script-->
<!--script src="../../blocks_compressed.js"></script-->
...
@@ -36,7 +34,6 @@
...
@@ -36,7 +34,6 @@
<script
src=
"../../generators/arduino/text.js"
></script>
<script
src=
"../../generators/arduino/text.js"
></script>
<script
src=
"../../generators/arduino/time.js"
></script>
<script
src=
"../../generators/arduino/time.js"
></script>
<script
src=
"../../generators/arduino/variables.js"
></script>
<script
src=
"../../generators/arduino/variables.js"
></script>
<script
src=
"../../msg/js/en.js"
></script>
<script
src=
"../../msg/js/en.js"
></script>
</head>
</head>
...
...
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