src/timeline-window.js
function(timeline) {
        let eventIndex;

        const events = timeline.getEvents();

        if (!initialEventId) {
            // we were looking for the live timeline: initialise to the end
            eventIndex = events.length;
        } else {
            for (let i = 0; i < events.length; i++) {
                if (events[i].getId() == initialEventId) {
                    eventIndex = i;
                    break;
                }
            }

            if (eventIndex === undefined) {
                throw new Error("getEventTimeline result didn't include requested event");
            }
        }

        const endIndex = Math.min(events.length,
                                eventIndex + Math.ceil(initialWindowSize / 2));
        const startIndex = Math.max(0, endIndex - initialWindowSize);
        self._start = new TimelineIndex(timeline, startIndex - timeline.getBaseIndex());
        self._end = new TimelineIndex(timeline, endIndex - timeline.getBaseIndex());
        self._eventCount = endIndex - startIndex;
    }
function(timeline) {
        let eventIndex;

        const events = timeline.getEvents();

        if (!initialEventId) {
            // we were looking for the live timeline: initialise to the end
            eventIndex = events.length;
        } else {
            for (let i = 0; i < events.length; i++) {
                if (events[i].getId() == initialEventId) {
                    eventIndex = i;
                    break;
                }
            }

            if (eventIndex === undefined) {
                throw new Error("getEventTimeline result didn't include requested event");
            }
        }

        const endIndex = Math.min(events.length,
                                eventIndex + Math.ceil(initialWindowSize / 2));
        const startIndex = Math.max(0, endIndex - initialWindowSize);
        self._start = new TimelineIndex(timeline, startIndex - timeline.getBaseIndex());
        self._end = new TimelineIndex(timeline, endIndex - timeline.getBaseIndex());
        self._eventCount = endIndex - startIndex;
    }
function ( timeline ) { let eventIndex ; const events = timeline . getEvents ( ) ; if ( ! initialEventId ) { // we were looking for the live timeline: initialise to the end eventIndex = events . length ; } else { for ( let i = 0 ; i < events . length ; i ++ ) { if ( events [ i ] . getId ( ) == initialEventId ) { eventIndex = i ; break ; } } if ( eventIndex === undefined ) { throw new Error ( "getEventTimeline result didn't include requested event" ) ; } } const endIndex = Math . min ( events . length , eventIndex + Math . ceil ( initialWindowSize / 2 ) ) ; const startIndex = Math . max ( 0 , endIndex - initialWindowSize ) ; self . _start = new TimelineIndex ( timeline , startIndex - timeline . getBaseIndex ( ) ) ; self . _end = new TimelineIndex ( timeline , endIndex - timeline . getBaseIndex ( ) ) ; self . _eventCount = endIndex - startIndex ; }
given an EventTimeline, find the event we were looking for, and initialise our fields so that the event in question is in the middle of the window.
given an EventTimeline find the event we were looking for and initialise our fields so that the event in question is in the middle of the window .