2013-12-17 47 views
-1

这里我有一个例子:http://jsbin.com/oLaqoToH/5(时间轴与事件) 双击我可以创建一个新的事件,但我的问题是如何找到这样做的函数,所以如何找到代码是为此操作创建。如何查找函数的代码

这个例子也有外部资源(发动机)timeline.js http://almende.github.io/chap-links-library/js/timeline/timeline.js

我尝试用onNew(); new Item.等,但没有什么的,是不是一个答案...文档是坏的,我不知道该怎么从事实际工作。

帮助?

+2

阅读他们的来源。 – SLaks

+0

最有可能所有需要的代码都在JS文件中,打开它并查看。 – RealityDysfunction

+0

我打开,但我没有看到那个功能在哪里,我找不到她......这是我的问题,我试着整天找到它...... – MikiMrki

回答

0

我相信这是你在找什么:

/** 
* Double click event occurred for an item 
* @param {Event} event 
*/ 
links.Timeline.prototype.onDblClick = function (event) { 
    var params = this.eventParams, 
     options = this.options, 
     dom = this.dom, 
     size = this.size; 
    event = event || window.event; 

    if (params.itemIndex != undefined) { 
     var item = this.items[params.itemIndex]; 
     if (item && this.isEditable(item)) { 
      // fire the edit event 
      this.trigger('edit'); 
     } 
    } 
    else { 
     if (options.editable) { 
      // create a new item 

      // get mouse position 
      params.mouseX = links.Timeline.getPageX(event); 
      params.mouseY = links.Timeline.getPageY(event); 
      var x = params.mouseX - links.Timeline.getAbsoluteLeft(dom.content); 
      var y = params.mouseY - links.Timeline.getAbsoluteTop(dom.content); 

      // create a new event at the current mouse position 
      var xstart = this.screenToTime(x); 
      var xend = this.screenToTime(x + size.frameWidth/10); // add 10% of timeline width 
      if (options.snapEvents) { 
       this.step.snap(xstart); 
       this.step.snap(xend); 
      } 

      var content = options.NEW; 
      var group = this.getGroupFromHeight(y); // (group may be undefined) 
      var preventRender = true; 
      this.addItem({ 
       'start': xstart, 
       'end': xend, 
       'content': content, 
       'group': this.getGroupName(group) 
      }, preventRender); 
      params.itemIndex = (this.items.length - 1); 
      this.selectItem(params.itemIndex); 

      this.applyAdd = true; 

      // fire an add event. 
      // Note that the change can be canceled from within an event listener if 
      // this listener calls the method cancelAdd(). 
      this.trigger('add'); 

      if (this.applyAdd) { 
       // render and select the item 
       this.render({animate: false}); 
       this.selectItem(params.itemIndex); 
      } 
      else { 
       // undo an add 
       this.deleteItem(params.itemIndex); 
      } 
     } 
    } 

    links.Timeline.preventDefault(event); 
}; 

source

+0

谢谢! .............. – MikiMrki