0
|
1 /*==================================================
|
|
2 * Event Utils
|
|
3 *==================================================
|
|
4 */
|
|
5 Timeline.EventUtils = {};
|
|
6
|
|
7 Timeline.EventUtils.getNewEventID = function() {
|
|
8 // global across page
|
|
9 if (this._lastEventID == null) {
|
|
10 this._lastEventID = 0;
|
|
11 }
|
|
12
|
|
13 this._lastEventID += 1;
|
|
14 return "e" + this._lastEventID;
|
|
15 };
|
|
16
|
|
17 Timeline.EventUtils.decodeEventElID = function(elementID) {
|
|
18 /*==================================================
|
|
19 *
|
|
20 * Use this function to decode an event element's id on a band (label div,
|
|
21 * tape div or icon img).
|
|
22 *
|
|
23 * Returns {band: <bandObj>, evt: <eventObj>}
|
|
24 *
|
|
25 * To enable a single event listener to monitor everything
|
|
26 * on a Timeline, a set format is used for the id's of the
|
|
27 * elements on the Timeline--
|
|
28 *
|
|
29 * element id format for labels, icons, tapes:
|
|
30 * labels: label-tl-<timelineID>-<band_index>-<evt.id>
|
|
31 * icons: icon-tl-<timelineID>-<band_index>-<evt.id>
|
|
32 * tapes: tape1-tl-<timelineID>-<band_index>-<evt.id>
|
|
33 * tape2-tl-<timelineID>-<band_index>-<evt.id>
|
|
34 * // some events have more than one tape
|
|
35 * highlight: highlight1-tl-<timelineID>-<band_index>-<evt.id>
|
|
36 * highlight2-tl-<timelineID>-<band_index>-<evt.id>
|
|
37 * // some events have more than one highlight div (future)
|
|
38 * Note: use split('-') to get array of the format's parts
|
|
39 *
|
|
40 * You can then retrieve the timeline object and event object
|
|
41 * by using Timeline.getTimeline, Timeline.getBand, or
|
|
42 * Timeline.getEvent and passing in the element's id
|
|
43 *
|
|
44 *==================================================
|
|
45 */
|
|
46
|
|
47 var parts = elementID.split('-');
|
|
48 if (parts[1] != 'tl') {
|
|
49 alert("Internal Timeline problem 101, please consult support");
|
|
50 return {band: null, evt: null}; // early return
|
|
51 }
|
|
52
|
|
53 var timeline = Timeline.getTimelineFromID(parts[2]);
|
|
54 var band = timeline.getBand(parts[3]);
|
|
55 var evt = band.getEventSource.getEvent(parts[4]);
|
|
56
|
|
57 return {band: band, evt: evt};
|
|
58 };
|
|
59
|
|
60 Timeline.EventUtils.encodeEventElID = function(timeline, band, elType, evt) {
|
|
61 // elType should be one of {label | icon | tapeN | highlightN}
|
|
62 return elType + "-tl-" + timeline.timelineID +
|
|
63 "-" + band.getIndex() + "-" + evt.getID();
|
|
64 }; |