Trigger.js triggers a trigger on a new cloned item

How can I call a direction indicator / dragstart on a cloned joint element in shared js? toolBoxPointerDown fired when the pointerdown event is pointerdown on the toolbar. addNode is pointerup on a _this.paperDrag event on _this.paperDrag .

 var toolBoxPointerDown = function(cell, event) { _this.action = 'addNode'; $(document.body).append(_this.paperDrag.$el); _this.clone = cell.model.clone(), _this.cloneBbox = cell.getBBox(); _this.clone.set("position", { x: cell.model.attributes.position.x, y: cell.model.attributes.position.y }), _this.paperDrag.addCell(_this.clone), _this.paperDrag.setDimensions("100%", "100%"); _this.paperDrag.$el.offset({ left: 0, top: 0 }); _this.paperDrag.findViewByModel(_this.clone.id).pointerdown(); } var addNode = function(node, position) { var celltoAdd = _this.clone.clone(); celltoAdd.set('position', { x: _this.clone.get('position').x - $('.toolbox').width(), y: _this.clone.get('position').y }); if(celltoAdd.attributes.position.x > - 50){ renderNode(celltoAdd.attributes); } _this.paperDrag.$el.detach(); _this.clone.remove(); _this.action = 'nodeAdded'; } 
+7
jquery jointjs
source share
1 answer

add this code to your builder:

 _this.paperDrag.on('element:pointerup', this.addNode , this); _this.paperDrag.on('element:pointerdown', this.toolBoxPointerDown , this); 

Some explanations: joint.dia.ElementView has a built-in pointer and pointer, the last line of code of these two functions makes the following notifications:

this.notify('element:pointerdown', evt, x, y);

and your paper.on('element:pointerdown') will be executed after this notification is accrued.

0
source share

All Articles