2014-01-06 46 views
7

如何觸發聯合js中克隆聯合元素上的指針/拖動啓動? toolBoxPointerDownpointerdown事件在工具箱紙上被觸發時被觸發。當pointerup事件在_this.paperDrag上被觸發時,觸發 addNodejoint.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,這兩個函數的最後一行代碼做出通知如下:

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

和你paper.on('element:pointerdown')已在產生通知後執行。