Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return function(e) {
if (Blockly.isRightButton(e)) {
// Right-click. Don't create a block, let the context menu show.
return;
}
if (originBlock.disabled) {
// Beyond capacity.
return;
}
Blockly.Events.disable();
// Create the new block by cloning the block in the flyout (via XML).
var xml = Blockly.Xml.blockToDom(originBlock);
var block = Blockly.Xml.domToBlock(xml, workspace);
block.setEditable(true);
block.setCollapsed(false);
// Place it in the same spot as the flyout copy.
var svgRootOld = originBlock.getSvgRoot();
if (!svgRootOld) {
throw 'originBlock is not rendered.';
}
var sourceXY = sourceBlock.getRelativeToSurfaceXY();
var fieldRelativeXY = Blockly.getRelativeXY_(svgRoot);
var originBlockXY = originBlock.getRelativeToSurfaceXY();
block.moveBy(
originBlockXY.x + sourceXY.x + fieldRelativeXY.x + FieldTable.translateX_,
originBlockXY.y + sourceXY.y + fieldRelativeXY.y + FieldTable.translateY_);
Blockly.Events.enable();
if (Blockly.Events.isEnabled()) {
return function(e) {
if (Blockly.isRightButton(e)) {
// Right-click. Don't create a block, let the context menu show.
return;
}
if (originBlock.disabled) {
// Beyond capacity.
return;
}
Blockly.Events.disable();
// Create the new block by cloning the block in the flyout (via XML).
var xml = Blockly.Xml.blockToDom(originBlock);
var block = Blockly.Xml.domToBlock(xml, workspace);
block.setEditable(true);
block.setCollapsed(false);
// Place it in the same spot as the flyout copy.
var svgRootOld = originBlock.getSvgRoot();
if (!svgRootOld) {
throw 'originBlock is not rendered.';
}
var sourceXY = sourceBlock.getRelativeToSurfaceXY();
var fieldRelativeXY = Blockly.getRelativeXY_(svgRoot);
var originBlockXY = originBlock.getRelativeToSurfaceXY();
block.moveBy(
originBlockXY.x + sourceXY.x + fieldRelativeXY.x + FieldTable.translateX_,
originBlockXY.y + sourceXY.y + fieldRelativeXY.y + FieldTable.translateY_);
Blockly.Events.enable();
valueBlock.showTooltip = function() {
var xmlBlock = Blockly.Xml.blockToDom_(valueBlock);
xmlBlock.removeAttribute("editable");
xmlBlock.removeAttribute("movable");
xmlBlock.removeAttribute("deletable");
duplicateBlock = Blockly.Xml.domToBlock(xmlBlock, workspace);
duplicateBlock.isInFlyout = true;
duplicateBlock.hideTooltip = function() {
if (duplicateBlock) {
duplicateBlock.dispose();
}
};
Blockly.Tooltip.poisonedElement_ = Blockly.Tooltip.element_ = duplicateBlock;
var mousedownEvent = Blockly.bindEvent_(
duplicateBlock.getSvgRoot(),
'mousedown', null,
function(e) {
if (Blockly.isRightButton(e)) {
// Right-click. Don't create a block, let the context menu show.
return;
}
if (duplicateBlock.disabled) {
return function (e) {
try {
blockly.mainWorkspace.clear();
var xml = blockly.Xml.textToDom(e.target.result);
blockly.Xml.domToWorkspace(xml, blockly.mainWorkspace);
botUtils.addPurchaseOptions();
var tokenList = storageManager.getTokenList();
if (tokenList.length !== 0) {
blockly.mainWorkspace.getBlockById('trade')
.getField('ACCOUNT_LIST')
.setValue(tokenList[0].token);
blockly.mainWorkspace.getBlockById('trade')
.getField('ACCOUNT_LIST')
.setText(tokenList[0].account_name);
}
blockly.mainWorkspace.clearUndo();
blockly.mainWorkspace.zoomToFit();
botUtils.log(i18n._('Blocks are loaded successfully'), 'success');
} catch (err) {
botUtils.showError(err);
}
return function (e) {
try {
blockly.mainWorkspace.clear();
var xml = blockly.Xml.textToDom(e.target.result);
blockly.Xml.domToWorkspace(xml, blockly.mainWorkspace);
view.addPurchaseOptions();
var tokenList = storageManager.getTokenList();
if (tokenList.length !== 0) {
blockly.mainWorkspace.getBlockById('trade')
.getField('ACCOUNT_LIST')
.setValue(tokenList[0].token);
blockly.mainWorkspace.getBlockById('trade')
.getField('ACCOUNT_LIST')
.setText(tokenList[0].account_name);
}
blockly.mainWorkspace.clearUndo();
blockly.mainWorkspace.zoomToFit();
utils.log(i18n._('Blocks are loaded successfully'), 'success');
} catch (err) {
utils.showError(err);
}
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 bindData = workspace.addChangeListener( function (event) {
var xmlDom = Blockly.Xml.workspaceToDom(workspace);
var xmlText = Blockly.Xml.domToText(xmlDom);
if (startXmlText != xmlText) {
window.location.hash = '';
$('#copy-button').prop('disabled', true);
$('#save-button').prop('disabled', false);
setTimeout( function() { workspace.removeChangeListener(bindData); });
}
});
} );
onchange: function(e) {
if (e.blockId == this.id && !this.usesPrefix_() && e.recordUndo
&& e.type == Blockly.Events.CHANGE && e.element == 'field') {
var luRes = Prefixes.lookForIri(e.newValue);
if (luRes) {
var oldMutation = Blockly.Xml.domToText(this.mutationToDom());
this.removeInput('RESOURCE');
this.appendDummyInput('RESOURCE')
.appendField(new Blockly.FieldTextInput(luRes.prefix), "PREFIX")
.appendField(":")
.appendField(new Blockly.FieldTextInput(luRes.localPart), "LOCAL_NAME");
var newMutation = Blockly.Xml.domToText(this.mutationToDom());
var mutationEvent = new Blockly.Events.Change(
this, 'mutation', null, oldMutation, newMutation);
var changePrefixEvent = new Blockly.Events.Change(
this, 'field', 'PREFIX', '', luRes.prefix);
var changeLocalEvent = new Blockly.Events.Change(
this, 'field', 'LOCAL_NAME', '', luRes.localPart);
mutationEvent.group = e.group;
changePrefixEvent.group = e.group;
changeLocalEvent.group = e.group;
Blockly.Events.fire(mutationEvent);
save(name) {
if (typeof (Storage) !== "undefined") {
let xml = Blockly.Xml.workspaceToDom(this.workspace);
localStorage.setItem(name, Blockly.Xml.domToText(xml));
}
}