Load Public Google Calendar Events

Event data can be loaded from remote sources, like public google calendars. Through the integration plugin you can easily show events that are available in a public calendar. The integration plugin needs to be added to the download package or installed separately from a dedicated NPM package.

You will just need the CALENDAR_ID and an apiKey from google and you should be ready to roll.

Public calendars are read-only. If you are interested in syncing private google calendars with read/write/delete access, check out this example.

This example uses the integration plugin to connect to and load events from Google Calendar and it is not available in the trial. Give the live demo a try and see how it can be configured.
Get started with the agenda

Demo

Loading the live demo

Preview in full screen

Load events from a public Google Calendar into the agenda view using the integration plugin — connect with a Calendar ID and API key.

Code

mobiscroll.setOptions({
  locale:  ,
  theme: ' ',
  themeVariant: ' '
});

$(function () {
  var CALENDAR_ID = 'theacidmedia.net_8l6v679q5j2f7q8lpmcjr4mm3k@group.calendar.google.com';
  var googleCalendarSync = mobiscroll.googleCalendarSync;
  var currentView = 'agenda';
  var firstDay;
  var lastDay;
  var loader;
  var apiLoaded;

  function showLoader() {
    loader = loader || $('#demo-google-cal-loader');
    loader.css('visibility', 'visible');
  }

  function hideLoader() {
    loader.css('visibility', 'hidden');
  }

  function loadEvents() {
    showLoader();
    googleCalendarSync
      .getEvents(CALENDAR_ID, firstDay, lastDay)
      .then(function (resp) {
        apiLoaded = true;
        hideLoader();
        calendar.setEvents(resp);
      })
      .catch(onError);
  }

  function onError(resp) {
    mobiscroll.toast({
      message: resp.error ? resp.error : resp.result.error.message,
    });
  }

  var calendar = $('#demo-google-cal')
    .mobiscroll()
    .eventcalendar({
      view: {
        calendar: { type: 'week' },
        agenda: { type: 'week' },
      },
      exclusiveEndDates: true,
      onPageLoading: function (args) {
        var start = args.viewStart;
        var end = args.viewEnd;

        // Calculate dates
        // (pre-load events for previous and next pages as well)
        if (currentView == 'month') {
          firstDay = start;
          lastDay = end;
        } else {
          firstDay = new Date(start.getFullYear(), start.getMonth(), start.getDate() - 7);
          lastDay = new Date(end.getFullYear(), end.getMonth(), end.getDate() + 7);
        }

        if (apiLoaded) {
          loadEvents();
        }
      },
      renderHeader: function () {
        return (
          '<div mbsc-calendar-nav class="mds-google-cal-nav"></div>' +
          '<div id="demo-google-cal-loader" class="mds-loader"></div>' +
          '<div class="mds-google-cal-switch mbsc-flex-1-0">' +
          '<label>Month<input mbsc-segmented type="radio" name="view" value="month" class="mds-google-cal-view"></label>' +
          '<label>Week<input mbsc-segmented type="radio" name="view" value="week" class="mds-google-cal-view"></label>' +
          '<label>Day<input mbsc-segmented type="radio" name="view" value="day" class="mds-google-cal-view"></label>' +
          '<label>Agenda<input mbsc-segmented type="radio" name="view" value="agenda" class="mds-google-cal-view" checked></label>' +
          '</div>' +
          '<div mbsc-calendar-prev class="mds-google-cal-prev"></div>' +
          '<div mbsc-calendar-today class="mds-google-cal-today"></div>' +
          '<div mbsc-calendar-next class="mds-google-cal-next"></div>'
        );
      },
    })
    .mobiscroll('getInst');

  $('.mds-google-cal-view').on('change', function (ev) {
    currentView = ev.target.value;
    switch (currentView) {
      case 'month':
        calendar.setOptions({
          view: { calendar: { labels: true } },
        });
        break;
      case 'week':
        calendar.setOptions({
          view: { scheduler: { type: 'week' } },
        });
        break;
      case 'day':
        calendar.setOptions({
          view: { scheduler: { type: 'day' } },
        });
        break;
      case 'agenda':
        calendar.setOptions({
          view: {
            calendar: { type: 'week' },
            agenda: { type: 'week' },
          },
        });
        break;
    }
  });
    googleCalendarSync.init({
      apiKey: '<YOUR_GOOGLE_API_KEY>',
      onInit: loadEvents,
    });
});
  

Duplicate Session

You have signed in on a different machine. To keep everything in sync, you have been signed out of this session.

If you need to invite team members, manage seats and accounts you can do it from the licenses page.

Duplicate Session

We noticed you are logged in on a different machine and have closed your old session.

If you need to invite team members, manage seats and accounts you can do it from the licenses page.