2014-01-06 28 views
7

ジョイントのクローンされたジョイント要素でポインタダウン/ドラッグスタートをトリガーするにはどうすればよいですか?ツールボックス用紙でpointerdownイベントが発生すると、 toolBoxPointerDownが発生します。 イベントが_this.paperDragで発生すると、 addNodeがトリガーされます。joint.js新しいクローンされた要素に対してドラッグを開始する

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'; 
    } 

答えて

0

あなたの紙ビルダーにこのコードを追加します。

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

をいくつかの説明:joint.dia.ElementViewはpointerdownとpointerupに建てられた、これら2つの関数の最後のコード行は次のように通知します

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

とあなたその通知が発生した後でが実行されました。

関連する問題