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
2a9993e5
Commit
2a9993e5
authored
May 13, 2015
by
Neil Fraser
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix cloud storage (issue 100)
parent
bfee4277
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
20 deletions
+22
-20
appengine/storage.js
appengine/storage.js
+9
-7
demos/code/code.js
demos/code/code.js
+13
-13
No files found.
appengine/storage.js
View file @
2a9993e5
...
...
@@ -29,13 +29,12 @@ var BlocklyStorage = {};
/**
* Backup code blocks to localStorage.
* @param {
Blockly.WorkspaceSvg} opt_
workspace Workspace.
* @param {
!Blockly.WorkspaceSvg}
workspace Workspace.
* @private
*/
BlocklyStorage
.
backupBlocks_
=
function
(
opt_
workspace
)
{
BlocklyStorage
.
backupBlocks_
=
function
(
workspace
)
{
if
(
'
localStorage
'
in
window
)
{
var
workspace
=
opt_workspace
||
Blockly
.
getMainWorkspace
();
var
xml
=
Blockly
.
Xml
.
workspaceToDom
(
Blockly
.
workspace
);
var
xml
=
Blockly
.
Xml
.
workspaceToDom
(
workspace
);
// Gets the current URL, not including the hash.
var
url
=
window
.
location
.
href
.
split
(
'
#
'
)[
0
];
window
.
localStorage
.
setItem
(
url
,
Blockly
.
Xml
.
domToText
(
xml
));
...
...
@@ -44,9 +43,12 @@ BlocklyStorage.backupBlocks_ = function(opt_workspace) {
/**
* Bind the localStorage backup function to the unload event.
* @param {Blockly.WorkspaceSvg} opt_workspace Workspace.
*/
BlocklyStorage
.
backupOnUnload
=
function
()
{
window
.
addEventListener
(
'
unload
'
,
BlocklyStorage
.
backupBlocks_
,
false
);
BlocklyStorage
.
backupOnUnload
=
function
(
opt_workspace
)
{
var
workspace
=
opt_workspace
||
Blockly
.
getMainWorkspace
();
window
.
addEventListener
(
'
unload
'
,
function
()
{
BlocklyStorage
.
backupBlocks_
(
workspace
);},
false
);
};
/**
...
...
@@ -70,7 +72,7 @@ BlocklyStorage.link = function(opt_workspace) {
var
workspace
=
opt_workspace
||
Blockly
.
getMainWorkspace
();
var
xml
=
Blockly
.
Xml
.
workspaceToDom
(
workspace
);
var
data
=
Blockly
.
Xml
.
domToText
(
xml
);
BlocklyStorage
.
makeRequest_
(
'
/storage
'
,
'
xml
'
,
data
);
BlocklyStorage
.
makeRequest_
(
'
/storage
'
,
'
xml
'
,
data
,
workspace
);
};
/**
...
...
demos/code/code.js
View file @
2a9993e5
...
...
@@ -335,18 +335,6 @@ Code.renderContent = function() {
Code
.
init
=
function
()
{
Code
.
initLanguage
();
// Disable the link button if page isn't backed by App Engine storage.
var
linkButton
=
document
.
getElementById
(
'
linkButton
'
);
if
(
'
BlocklyStorage
'
in
window
)
{
BlocklyStorage
[
'
HTTPREQUEST_ERROR
'
]
=
MSG
[
'
httpRequestError
'
];
BlocklyStorage
[
'
LINK_ALERT
'
]
=
MSG
[
'
linkAlert
'
];
BlocklyStorage
[
'
HASH_ERROR
'
]
=
MSG
[
'
hashError
'
];
BlocklyStorage
[
'
XML_ERROR
'
]
=
MSG
[
'
xmlError
'
];
Code
.
bindClick
(
linkButton
,
BlocklyStorage
.
link
);
}
else
if
(
linkButton
)
{
linkButton
.
className
=
'
disabled
'
;
}
var
rtl
=
Code
.
isRtl
();
var
container
=
document
.
getElementById
(
'
content_area
'
);
var
onresize
=
function
(
e
)
{
...
...
@@ -390,7 +378,7 @@ Code.init = function() {
if
(
'
BlocklyStorage
'
in
window
)
{
// Hook a save function onto unload.
BlocklyStorage
.
backupOnUnload
();
BlocklyStorage
.
backupOnUnload
(
Code
.
workspace
);
}
Code
.
tabClick
(
Code
.
selected
);
...
...
@@ -399,6 +387,18 @@ Code.init = function() {
Code
.
bindClick
(
'
trashButton
'
,
function
()
{
Code
.
discard
();
Code
.
renderContent
();});
Code
.
bindClick
(
'
runButton
'
,
Code
.
runJS
);
// Disable the link button if page isn't backed by App Engine storage.
var
linkButton
=
document
.
getElementById
(
'
linkButton
'
);
if
(
'
BlocklyStorage
'
in
window
)
{
BlocklyStorage
[
'
HTTPREQUEST_ERROR
'
]
=
MSG
[
'
httpRequestError
'
];
BlocklyStorage
[
'
LINK_ALERT
'
]
=
MSG
[
'
linkAlert
'
];
BlocklyStorage
[
'
HASH_ERROR
'
]
=
MSG
[
'
hashError
'
];
BlocklyStorage
[
'
XML_ERROR
'
]
=
MSG
[
'
xmlError
'
];
Code
.
bindClick
(
linkButton
,
function
()
{
BlocklyStorage
.
link
(
Code
.
workspace
);});
}
else
if
(
linkButton
)
{
linkButton
.
className
=
'
disabled
'
;
}
for
(
var
i
=
0
;
i
<
Code
.
TABS_
.
length
;
i
++
)
{
var
name
=
Code
.
TABS_
[
i
];
...
...
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