JointJS - Mouse click event triggers cell position

2019-06-14 02:30发布

I need to define mouse click event for my each cell. I used cell:pointerup event; but this event is triggered when I change positions of cells too. How can I differentiate these 2 events?

Thanks in advance.

1条回答
ゆ 、 Hurt°
2楼-- · 2019-06-14 03:18

What you can do is to create a custom element view and distinct click from dragging by checking whether a pointermove event was triggered between pointerdown and pointerup events.

var ClickableView = joint.dia.ElementView.extend({
  pointerdown: function () {
    this._click = true;
    joint.dia.ElementView.prototype.pointerdown.apply(this, arguments);
  },
  pointermove: function () {
    this._click = false;
    joint.dia.ElementView.prototype.pointermove.apply(this, arguments);
  },
  pointerup: function (evt, x, y) {
    if (this._click) {
      // triggers an event on the paper and the element itself
      this.notify('cell:click', evt, x, y); 
    } else {
      joint.dia.ElementView.prototype.pointerup.apply(this, arguments);
    }
  }
});

And then tell the joint.dia.Paper to use the view.

var paper = new joint.dia.Paper({
  // el, width, height etc.
  elementView: ClickableView
});

A fiddle can be found here.

查看更多
登录 后发表回答