Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor(options) {
options = options || {}
// if someone is changing the workspace
this.isCoding = false;
// if use the strat block
this.start = options.start === true;
// set custom highlight
this.customHighlight = options.customHighlight === true;
// set the workspace, default is Blockly.getMainWorkspace()
this.workspace = options.workspace || Blockly.getMainWorkspace();
this.workspace.addChangeListener((event) => {
if (event.type == Blockly.Events.BLOCK_MOVE) {
// update codinge state and remove block highlight
if (!this.isCoding) this.removeHighlight();
this.isCoding = true;
}
});
this.reset();
}
var startup = function(opt_workspace, callback) {
var workspace = opt_workspace || Blockly.getMainWorkspace();
// An href with #key trigers an AJAX call to retrieve saved blocks.
if (window.location.hash.length > 1) {
retrieveXml(window.location.hash.substring(1), workspace, callback);
} else {
monitorChanges_(workspace);
if (Blockly.Events.isEnabled()) {
var newEvent = new Blockly.Events.Abstract(null);
newEvent.type = "new-workspace";
newEvent.workspaceId = workspace.id;
Blockly.Events.fire(newEvent);
}
if (_.isFunction(callback))
callback();
}
};
var restoreBlocks = function(opt_workspace) {
var url = window.location.href.split('#')[0];
if ('localStorage' in window && window.localStorage[url]) {
var workspace = opt_workspace || Blockly.getMainWorkspace();
var xml = Blockly.Xml.textToDom(window.localStorage[url]);
Blockly.Xml.domToWorkspace(xml, workspace);
}
};
var retrieveXml = function(key, opt_workspace, callback) {
MessageDisplay.alert("Loading Saved Workspace...");
var workspace = opt_workspace || Blockly.getMainWorkspace();
urlFromKey_(key, function(url) {
makeRequest_({
headers: {Accept: "text/xml"},
dataType: "text",
method: "GET",
url: url,
success: function(data) {
if (!data.length) {
MessageDisplay.alert(HASH_ERROR.replace('%1', window.location.hash), 'error');
if (_.isFunction(callback))
callback('Unknown error');
} else {
if (Blockly.Events.isEnabled()) {
Blockly.Events.setGroup(true);
var loadEvent = new Blockly.Events.Abstract(null);
loadEvent.type = "load-snapshot";
var linkGist = function(opt_workspace, callback) {
MessageDisplay.alert("Saving Workspace as Gist on GitHub...");
var workspace = opt_workspace || Blockly.getMainWorkspace();
var xml = Blockly.Xml.workspaceToDom(workspace);
var data = Blockly.Xml.domToPrettyText(xml);
var testState = TestBlocks && TestBlocks.getState();
var metaData = _.extend(
{
generator: "SparqlBlocks",
version: packageJson.version,
baseURI: location.href,
timestamp: $.now(),
workspaceXmlFile: "workspace.xml"
},
workspace.eventStack ? {
eventHistoryFile: "eventHistory.json"
} : {},
testState ? {
testStateFile: "testState.json"
var backupOnUnload = function(opt_workspace) {
var workspace = opt_workspace || Blockly.getMainWorkspace();
window.addEventListener('unload',
function() {backupBlocks_(workspace);}, false);
};