How to use the blockly.bindEvent_ function in blockly

To help you get started, we’ve selected a few blockly examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github miguel76 / SparqlBlocks / src / core / field_table.js View on Github external
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));
};
github miguel76 / SparqlBlocks / src / core / field_table.js View on Github external
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));
  }
};
github miguel76 / SparqlBlocks / src / core / lib-dialogs.js View on Github external
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();
};
github miguel76 / SparqlBlocks / src / core / field_table.js View on Github external
// 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));
  }
};
github miguel76 / SparqlBlocks / src / core / jsonToBlocks.js View on Github external
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);
github miguel76 / SparqlBlocks / src / core / field_table.js View on Github external
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));
  }
};
github miguel76 / SparqlBlocks / src / core / field_table.js View on Github external
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));
  }
};
github miguel76 / SparqlBlocks / src / core / lib-dialogs.js View on Github external
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);
github miguel76 / SparqlBlocks / src / core / field_table.js View on Github external
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));
  }
};
github miguel76 / SparqlBlocks / src / core / field_table.js View on Github external
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));
  }
};