joint.js trigger drag start on a new cloned element
Asked Answered
S

1

7

How can I trigger pointerdown/dragstart on a cloned joint element in joint js? toolBoxPointerDown is triggered when pointerdown event is fired on toolbox paper. addNode is triggered when pointerup event is fired 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';
    }
Sumerian answered 6/1, 2014 at 13:30 Comment(0)
T
1

add this code to your paper builder:

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

Some explanations: the joint.dia.ElementView has built in pointerdown and pointerup, the last code line of these two functions make notify like this:

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

and your paper.on('element:pointerdown') is been executed after that notification has accrued.

Triazine answered 31/8, 2017 at 4:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.