Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timeline: getTarget #32

Closed
Zolrag opened this issue Sep 25, 2012 · 4 comments
Closed

Timeline: getTarget #32

Zolrag opened this issue Sep 25, 2012 · 4 comments
Labels

Comments

@Zolrag
Copy link

Zolrag commented Sep 25, 2012

Hi,

I would like to get the css position of a selected item on the timeline. I have added a listener for the select event. It seems that the only function that I can use to obtain this position is the getTarget(event) function which returns the HTML object. However, I am not sure that I understand correctly getTarget(event). I tried the following approach without success:

 function select(){
  var sel = timeline.getSelection();

  if (sel.length) {
    if (sel[0].row != undefined) {
      var row = sel[0].row;
      var target = timeline.getTarget('click');
      ...
    }
  }
 }

Any idea on solving this problem?
Thank you in advance

@josdejong
Copy link
Contributor

getTarget is a generic method, giving a cross browser solution for getting the target from a browser event. It is meant as a private method for use inside the Timeline. (there is currently no clear separation between private and public methods, but you will see that this method is not described in the docs).

The html elements of the Timeline itself are "hidden" from the outside. If you need the position of an item, you can enclose your own HTML element in the content of a Timeline item, and retrieve the position of this element. Something like this (JSON variant):

var data = [
    {
        'start': new Date(2012, 8, 25),
        'content': '<div id="item0">Item 0</div>'
    },
    {
        'start': new Date(2012, 8, 26),
        'content': '<div id="item1">Item 1</div>'
    },
    // ... more data
];

And inside your select event listener:

// ...
var row = sel[0].row;
var elem = $('#item' + row);
var offset = elem.offset();
console.log('item ' + row + ' selected, left:' + offset.left + ', top: ' + offset.top);
// ...

@Zolrag
Copy link
Author

Zolrag commented Sep 27, 2012

Thank you for your reply.

I found out that an HTML classname 'timeline-event-selected' is added to the element being selected which allowed me to find its position. I added a listener on 'rangechange' so that my new element can follow the one being selected but it does not work well when applying a drag event on the timeline. The position of my new element is updated only at the next drag event, so following one step behind. Scrolling works well though except when scrolling really fast my new element is somewhat left behind.

@josdejong
Copy link
Contributor

Glad you have a solution. Anyway, alternatively, you could insert some HTML+JS+CSS in the Timeline events, and really attach your floating element to a Timeline event (not needing to adjust the position via event listeners using javascript).

@Zolrag
Copy link
Author

Zolrag commented Sep 28, 2012

Sounds good I'll have a look into that as soon as possible
Thanks again for your help :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants