Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
blockRows.forEach( function(blockRow) {
colNames.forEach( function(colName) {
var block = blockRow[colName];
parent.setEventBindingsForBlock_(block);
});
});
// IE 11 is an incompetant browser that fails to fire mouseout events.
// When the mouse is over the background, deselect all blocks.
var deselectAll = function(e) {
var blocks = this.workspace_.getTopBlocks(false);
for (var blockIndex = 0; blockIndex < blocks.length; blockIndex++) {
blocks[blockIndex].removeSelect();
}
};
this.flyout_.listeners_.push(Blockly.bindEvent_(
this.flyout_.svgBackground_, 'mouseover',
this.flyout_, deselectAll));
};
var root = block.getSvgRoot();
// Create an invisible rectangle under the block to act as a button. Just
// using the block as a button is poor, since blocks have holes in them.
var rect = Blockly.createSvgElement('rect', {'fill-opacity': 0}, null);
// Add the rectangles under the blocks, so that the blocks' tooltips work.
this.flyout_.workspace_.getCanvas().insertBefore(rect, root);
block.flyoutRect_ = rect;
var lstnrs = this.flyout_.listeners_;
lstnrs.push(Blockly.bindEvent_(
root, 'mousedown', null,
this.flyout_.blockMouseDown_(block)));
lstnrs.push(Blockly.bindEvent_(root, 'mouseover', block,
block.addSelect));
lstnrs.push(Blockly.bindEvent_(root, 'mouseout', block,
block.removeSelect));
lstnrs.push(Blockly.bindEvent_(rect, 'mousedown', null,
this.createBlockFunc_(block)));
lstnrs.push(Blockly.bindEvent_(rect, 'mouseover', block,
block.addSelect));
lstnrs.push(Blockly.bindEvent_(rect, 'mouseout', block,
block.removeSelect));
}
};
BlocklyDialogs.dialogMouseDown_ = function(e) {
BlocklyDialogs.dialogUnbindDragEvents_();
if (Blockly.isRightButton(e)) {
// Right-click.
return;
}
// Left click (or middle click).
// Record the starting offset between the current location and the mouse.
var dialog = document.getElementById('dialog');
BlocklyDialogs.dialogStartX_ = dialog.offsetLeft - e.clientX;
BlocklyDialogs.dialogStartY_ = dialog.offsetTop - e.clientY;
BlocklyDialogs.dialogMouseUpWrapper_ = Blockly.bindEvent_(document,
'mouseup', null, BlocklyDialogs.dialogUnbindDragEvents_);
BlocklyDialogs.dialogMouseMoveWrapper_ = Blockly.bindEvent_(document,
'mousemove', null, BlocklyDialogs.dialogMouseMove_);
// This event has been handled. No need to bubble up to the document.
e.stopPropagation();
};
// Create an invisible rectangle under the block to act as a button. Just
// using the block as a button is poor, since blocks have holes in them.
var rect = Blockly.createSvgElement('rect', {'fill-opacity': 0}, null);
// Add the rectangles under the blocks, so that the blocks' tooltips work.
this.flyout_.workspace_.getCanvas().insertBefore(rect, root);
block.flyoutRect_ = rect;
var lstnrs = this.flyout_.listeners_;
lstnrs.push(Blockly.bindEvent_(
root, 'mousedown', null,
this.flyout_.blockMouseDown_(block)));
lstnrs.push(Blockly.bindEvent_(root, 'mouseover', block,
block.addSelect));
lstnrs.push(Blockly.bindEvent_(root, 'mouseout', block,
block.removeSelect));
lstnrs.push(Blockly.bindEvent_(rect, 'mousedown', null,
this.createBlockFunc_(block)));
lstnrs.push(Blockly.bindEvent_(rect, 'mouseover', block,
block.addSelect));
lstnrs.push(Blockly.bindEvent_(rect, 'mouseout', block,
block.removeSelect));
}
};
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) {
// Beyond capacity.
return;
}
duplicateBlock.isInFlyout = false;
Blockly.unbindEvent_(mousedownEvent);
duplicateBlock.hideTooltip = null;
Blockly.Tooltip.hide();
duplicateBlock.onMouseDown_(e);
FieldTable.prototype.setEventBindingsForBlock_ = function(block) {
if (block) {
var root = block.getSvgRoot();
// Create an invisible rectangle under the block to act as a button. Just
// using the block as a button is poor, since blocks have holes in them.
var rect = Blockly.createSvgElement('rect', {'fill-opacity': 0}, null);
// Add the rectangles under the blocks, so that the blocks' tooltips work.
this.flyout_.workspace_.getCanvas().insertBefore(rect, root);
block.flyoutRect_ = rect;
var lstnrs = this.flyout_.listeners_;
lstnrs.push(Blockly.bindEvent_(
root, 'mousedown', null,
this.flyout_.blockMouseDown_(block)));
lstnrs.push(Blockly.bindEvent_(root, 'mouseover', block,
block.addSelect));
lstnrs.push(Blockly.bindEvent_(root, 'mouseout', block,
block.removeSelect));
lstnrs.push(Blockly.bindEvent_(rect, 'mousedown', null,
this.createBlockFunc_(block)));
lstnrs.push(Blockly.bindEvent_(rect, 'mouseover', block,
block.addSelect));
lstnrs.push(Blockly.bindEvent_(rect, 'mouseout', block,
block.removeSelect));
}
};
var rect = Blockly.createSvgElement('rect', {'fill-opacity': 0}, null);
// Add the rectangles under the blocks, so that the blocks' tooltips work.
this.flyout_.workspace_.getCanvas().insertBefore(rect, root);
block.flyoutRect_ = rect;
var lstnrs = this.flyout_.listeners_;
lstnrs.push(Blockly.bindEvent_(
root, 'mousedown', null,
this.flyout_.blockMouseDown_(block)));
lstnrs.push(Blockly.bindEvent_(root, 'mouseover', block,
block.addSelect));
lstnrs.push(Blockly.bindEvent_(root, 'mouseout', block,
block.removeSelect));
lstnrs.push(Blockly.bindEvent_(rect, 'mousedown', null,
this.createBlockFunc_(block)));
lstnrs.push(Blockly.bindEvent_(rect, 'mouseover', block,
block.addSelect));
lstnrs.push(Blockly.bindEvent_(rect, 'mouseout', block,
block.removeSelect));
}
};
var shadow = document.getElementById('dialogShadow');
var border = document.getElementById('dialogBorder');
// Copy all the specified styles to the dialog.
for (var name in style) {
dialog.style[name] = style[name];
}
if (modal) {
shadow.style.visibility = 'visible';
shadow.style.opacity = 0.3;
shadow.style.zIndex = 9;
var header = document.createElement('div');
header.id = 'dialogHeader';
dialog.appendChild(header);
BlocklyDialogs.dialogMouseDownWrapper_ =
Blockly.bindEvent_(header, 'mousedown', null,
BlocklyDialogs.dialogMouseDown_);
}
dialog.appendChild(content);
content.className = content.className.replace('dialogHiddenContent', '');
function endResult() {
// Check that the dialog wasn't closed during opening.
if (BlocklyDialogs.isDialogVisible_) {
dialog.style.visibility = 'visible';
dialog.style.zIndex = 10;
border.style.visibility = 'hidden';
}
}
if (animate && origin) {
BlocklyDialogs.matchBorder_(origin, false, 0.2);
BlocklyDialogs.matchBorder_(dialog, true, 0.8);
FieldTable.prototype.setEventBindingsForBlock_ = function(block) {
if (block) {
var root = block.getSvgRoot();
// Create an invisible rectangle under the block to act as a button. Just
// using the block as a button is poor, since blocks have holes in them.
var rect = Blockly.createSvgElement('rect', {'fill-opacity': 0}, null);
// Add the rectangles under the blocks, so that the blocks' tooltips work.
this.flyout_.workspace_.getCanvas().insertBefore(rect, root);
block.flyoutRect_ = rect;
var lstnrs = this.flyout_.listeners_;
lstnrs.push(Blockly.bindEvent_(
root, 'mousedown', null,
this.flyout_.blockMouseDown_(block)));
lstnrs.push(Blockly.bindEvent_(root, 'mouseover', block,
block.addSelect));
lstnrs.push(Blockly.bindEvent_(root, 'mouseout', block,
block.removeSelect));
lstnrs.push(Blockly.bindEvent_(rect, 'mousedown', null,
this.createBlockFunc_(block)));
lstnrs.push(Blockly.bindEvent_(rect, 'mouseover', block,
block.addSelect));
lstnrs.push(Blockly.bindEvent_(rect, 'mouseout', block,
block.removeSelect));
}
};
this.flyout_.workspace_.getCanvas().insertBefore(rect, root);
block.flyoutRect_ = rect;
var lstnrs = this.flyout_.listeners_;
lstnrs.push(Blockly.bindEvent_(
root, 'mousedown', null,
this.flyout_.blockMouseDown_(block)));
lstnrs.push(Blockly.bindEvent_(root, 'mouseover', block,
block.addSelect));
lstnrs.push(Blockly.bindEvent_(root, 'mouseout', block,
block.removeSelect));
lstnrs.push(Blockly.bindEvent_(rect, 'mousedown', null,
this.createBlockFunc_(block)));
lstnrs.push(Blockly.bindEvent_(rect, 'mouseover', block,
block.addSelect));
lstnrs.push(Blockly.bindEvent_(rect, 'mouseout', block,
block.removeSelect));
}
};