Follow

Is there a way to set the timeline to the `date` closest to now?

On load, I'd like to start the timeline on something near now. Without having to process the JSON to try to know which slide index I should be pointing to. Possible?

Was this article helpful?
1 out of 2 found this helpful
Have more questions? Submit a request

11 Comments

  • 0
    Avatar
    Joe Germuska

    For now, Timeline only supports specific slide numbers. From your question, I'm assuming that your timeline has events both in the past and the future.

    I think it would be hard to make a clear choice about how to interpret "closest to now" for all users. I suppose one could have options for "first before now" and "first after now."

    I'm also not sure if Timeline could be decisive about slides that are meant to represent an entire month or year -- many users of the Google Spreadsheets, especially, use the feature explained in the FAQ as "If the event is on the first day of the month and no time is specified it shows only the month. The same is true for year. If the event date is the first day of the first month of the year, it only shows the year."

    We'll make note of it as a feature to-be-desired, but TimelineJS is currently in a maintenance mode, not an add-new-features mode, so i don't want to get your hopes up.

  • 0
    Avatar
    Kira Dayco

    Hi, I have the same question, but would be happy to set it manually to a certain slide (the most current/relevant one) if it's not possible to automatically set it to "closest to now". It sounds like this is possible since you reference specific slide numbers. How do I get the timeline to load to a specific slide so that users can navigate backwards or forwards from there? (current it defaults to the first (earliest) post from several years ago. Thanks!

  • 0
    Avatar
    Joe Germuska

    Kira:

    Sorry if my answer wasn't clear. Are you using the Timeline JS authoring tool at http://timeline.knightlab.com? If so, there is an option there for setting the starting slide number.

     

    Pasted_Image_3_17_14__9_48_AM.png

  • 0
    Avatar
    Jasper van Naarden

    I think what he ment and what I am also trying to find is a way that he shows the most recent news item and not a specific slide

  • 0
    Avatar
    Joe Germuska

    Jasper: I believe you are correct, regarding the first question. As noted, this is not something that TimelineJS currently supports. 

     

  • 0
    Avatar
    Kira Dayco

    Hi Joe, yes I have what I need now. I just needed some more detailed support around how to add the start_at_slide piece in WordPress as I was modified a timeline that some else had originally created. Setting the slide manually works for what I need. Thanks!

  • 0
    Avatar
    Jason Radovan

    If you are using google spreadsheets as your data source (I'm not sure of other sources since I am using GSS), you can apply the formula "=TODAY()" to a specific cell to return the specific date. There are other time options here: https://support.google.com/drive/answer/3092984

  • 0
    Avatar
    Jason Radovan

    I've attached a screenshot of my google spreadsheet to show what I'm talking about

  • 0
    Avatar
    Thomas Eitzenberger

    you can do so using the following method as start point. Afterwards you need to issue a window.location.reload(). Not the most sophisticated solution but a workaround until an appropriate API is avail

     

    br

    Thomas

     

    function go2Time(month,year) {

        var model = VMM.Timeline.DataObj.data_template_obj.timeline.date;

        var x = -1; //

        for (var i = 0; i < model.length; i++) {

          var j = model[i];

          var currentDate = j.startDate.split('/');

          if (currentDate[2] == year) {

            if (currentDate[0] == month ) {

              x++;

              if (x == 0) {

                window.location.hash = i+1; // +1 to accommodate title slide count

              }

            }

          }

        }

      }

  • 1
    Avatar
    Xavier Freymuth

    For timelines used as a calendar of past and future events, it may be useful to place the starting slide on the immediately upcoming event. Here a code to get this feature with TimelineJS version 3.

    window.addEventListener("load", function(event) {
    // position of the timeline as close as possible to the future event
    // timeline.on("dataloaded", function(data) { // when dataloaded or loaded events will be debugged
    var aujourdhui = aujourdhui = new Date();
    var ldates = timeline._storyslider.data.events;

    // sorting in case the dates are not chronological
    ldates.forEach(function(item, index, array) {
    array.sort(function(a, b) {
    return a.start_date.data.date_obj ? -1 : b.start_date.data.date_obj ? 1 : 0
    });
    });
    if (ldates) {
    if (navigator.appName == 'Microsoft Internet Explorer' || !!(navigator.userAgent.match(/Trident/) || navigator.userAgent.match(/rv:11/)) || (typeof $.browser !== "undefined" && $.browser.msie == 1)) {
    for (var i = 0; i < ldates.length; i++) {
    if ( Number(ldates[i+1].start_date.data.date_obj) >= Number(aujourdhui) ) {
    while ( aujourdhui.getDate() == ldates[i].start_date.data.date_obj.getDate() ) { // trouver le 1er évènement se déroulant aujourdhui
    i -= 1;
    }
    var levent = ldates[i+1].unique_id;
    timeline.goToId(levent);
    break;
    }
    }
    } else {
    for (var i = 0; i < ldates.length; i++) {
    if ( ldates[i+1].start_date.data.date_obj >= aujourdhui ) {
    while ( aujourdhui.getDate() == ldates[i].start_date.data.date_obj.getDate() ) { // trouver le 1er évènement se déroulant aujourdhui
    i -= 1;
    }
    var levent = ldates[i+1].unique_id;
    timeline.goToId(levent);
    break;
    }
    }
    }
    };
    // }); // end when dataloaded or loaded events will be debugged
    });
     
    Edited by Xavier Freymuth
  • 0
    Avatar
    Chris Aldrich

    In the year column I've previously used the value "=NOW()" without the quotes to have the spreadsheet return the current year.

Please sign in to leave a comment.
Powered by Zendesk