ScheduleTooltip

A feature that displays a tooltip containing the time at the mouse position when hovering empty parts of the schedule.

By default, in DayView and WeekView, the time is rounded to the view's increment unless the precise config is set to true.

The example below illustrates how to use this feature in a Calendar instance and add a custom renderer to the tooltip. It shows the time at the pointer position, and if the pointer is outside of the core hours.

It also validates that any event being created or moved does not extend outside of the core hours:

Schedule tooltip
//<code-header>
fiddle.title = 'Schedule tooltip';
//</code-header>
const calendar = new Calendar({
    appendTo : targetElement,
    height   : 700,

    // We have a little less width in our context, so reduce the responsive breakpoints
    responsive : {
        small : {
            when : 480
        },
        medium : {
            when : 640
        }
    },

    // Start life looking at this date
    date : '2020-03-01',

    // Used to create view titles
    dateFormat : 'DD MMM YYYY',

    // CrudManager arranges loading and syncing of data in JSON form from/to a web service
    crudManager : {
        transport : {
            load : {
                url : 'data/Calendar/examples/feature/company-events.json'
            }
        },
        autoLoad : true
    },

    // Features named by the properties are included.
    // An object is used to configure the feature.
    features : {
        scheduleTooltip : {
            // Add to the default content of the tooltip if hovering outside core hours.
            renderer(view, date, preciseDate) {
                const
                    { coreHours } = view,
                    content      = this.defaultRenderer(view, preciseDate),
                    hour         = preciseDate.getHours();

                if (hour < coreHours.start || hour >= coreHours.end) {
                    return `<strong>Outside core hours</strong>${content}`;
                }
                return content;
            }
        },
        drag : {
            // Each drag mode has a separate validation callback.
            // We route them all to one on the calendar instance
            validateCreateFn : 'up.validateDrag',
            validateMoveFn   : 'up.validateDrag',
            validateResizeFn : 'up.validateDrag'
        }
    },

    // Modes are the views available in the Calendar.
    // An object is used to configure the view.
    modes : {
        agenda : null,
        year   : null,
        week   : {
            dayStartTime : 8,
            coreHours    : {
                overlayDay : true,
                start      : 9,
                end        : 18
            }
        },
        day : {
            dayStartTime : 8,
            coreHours    : {
                overlayDay : true,
                start      : 9,
                end        : 18
            }
        }
    },

    onBeforeAutoCreate({ view, startDate, endDate }) {
        return this.validateEventDates(view, startDate, endDate);
    },

    validateDrag({ drag, eventRecord }) {
        return this.validateEventDates(drag.target.view, eventRecord.startDate, eventRecord.endDate);
    },

    validateEventDates(view, startDate, endDate) {
        const
            { coreHours } = view,
            endHour       = endDate.getHours() + (endDate.getMinutes() / 60) + (endDate.getSeconds() / 3600);

        // Enforce core hours.
        if (startDate.getHours() < coreHours.start || endHour > coreHours.end) {
            Toast.show(`Events can only be between ${coreHours.start}:00 and ${coreHours.end}:00`);
            return false;
        }
    }
});

const calendar = new Calendar({
    features : {
        scheduleTooltip : true
    }
});

This feature is disabled by default.

Configs

15

Common

disabledInstancePlugin
listenersEvents

Other

Configure whether the tooltip should anchor to the day cell when not in a DayView.

By default, when not in a DayView, the tooltip will follow the mouse pointer.

If you enable this config, the tooltip will anchor to the day cell under the pointer instead.

precise: Boolean= falseAlso a property

When in a DayView, this config determines whether the tooltip should show the time at the pointer position with a precision of seconds, or rounded to the nearest increment.

renderer: function | StringAlso a property

The function or the name of a function to use to create the tooltip content. The function is passed the full context of the pointer position.

An implementation may call the defaultRenderer method to get the default HTML string content.

ParameterTypeDescription
viewCalendarView

The Calendar view that the pointer is over.

dateDate

The date at the pointer position. If the view is a DayView, this date is snapped to the view's increment based on the view's timeSnapType if any.

preciseDateDate

The precise date at the pointer position. This may differ from date if the view is a DayView. It will be as accurate as can be determined.

eventsEventModel[]

The events which coincide with the pointer position.

timeRangesTimeRangeModel[]

The time ranges which coincide with the pointer position. Each time range has a coincidingEvents property which is an array of events which intersect the time range.

resourceResourceModel

The resource record if any at the pointer position.

Returns: String | DomConfig -

The HTML or DOM configuration to display in the tooltip. A falsy return value will hide the tooltip.

Configure whether the tooltip should also show when hovering events.

By default, the tooltip only shows when hovering empty parts of the schedule.

If you enable this config, the tooltip will also show when hovering events.

This may conflict with the EventTooltip feature if that is configured to show on hover rather than on click.

The anchorToDayCell config will remove this conflict.

A function (or name of a function in the ownership hierarchy) which decides whether to show the ScheduleTooltip depending on the active view. The active view is passed, and if a truthy value is returned, the tip is shown, otherwise it is hidden.

This defaults to only showing for DayViews

ParameterTypeDescription
viewCalendarView

The Calendar view that the pointer is over. Return true to show the ScheduleTooltip for the passed view.

dateDate

The date at the pointer position as accurately as can be determined. If the view is a DayView, this date will have hour and minute resolution.

Returns: Boolean -

Whether to show the ScheduleTooltip.

This config is used to directly configure the associated Tooltip.

Misc

clientInstancePlugin
localeClassLocalizable
localizableLocalizable

Properties

22

Common

disabledInstancePlugin

Class hierarchy

isScheduleTooltip: Boolean= truereadonly
Identifies an object as an instance of ScheduleTooltip class, or subclass thereof.
isScheduleTooltip: Boolean= truereadonlystatic
Identifies an object as an instance of ScheduleTooltip class, or subclass thereof.
isCalendarFeatureCalendarFeature
isEventsEvents
isInstancePluginInstancePlugin
isLocalizableLocalizable

Other

Configure whether the tooltip should anchor to the day cell when not in a DayView.

By default, when not in a DayView, the tooltip will follow the mouse pointer.

If you enable this config, the tooltip will anchor to the day cell under the pointer instead.

precise: Boolean= falseAlso a config

When in a DayView, this config determines whether the tooltip should show the time at the pointer position with a precision of seconds, or rounded to the nearest increment.

renderer: function | StringAlso a config

The function or the name of a function to use to create the tooltip content. The function is passed the full context of the pointer position.

An implementation may call the defaultRenderer method to get the default HTML string content.

ParameterTypeDescription
viewCalendarView

The Calendar view that the pointer is over.

dateDate

The date at the pointer position. If the view is a DayView, this date is snapped to the view's increment based on the view's timeSnapType if any.

preciseDateDate

The precise date at the pointer position. This may differ from date if the view is a DayView. It will be as accurate as can be determined.

eventsEventModel[]

The events which coincide with the pointer position.

timeRangesTimeRangeModel[]

The time ranges which coincide with the pointer position. Each time range has a coincidingEvents property which is an array of events which intersect the time range.

resourceResourceModel

The resource record if any at the pointer position.

Returns: String | DomConfig -

The HTML or DOM configuration to display in the tooltip. A falsy return value will hide the tooltip.

Configure whether the tooltip should also show when hovering events.

By default, the tooltip only shows when hovering empty parts of the schedule.

If you enable this config, the tooltip will also show when hovering events.

This may conflict with the EventTooltip feature if that is configured to show on hover rather than on click.

The anchorToDayCell config will remove this conflict.

A function (or name of a function in the ownership hierarchy) which decides whether to show the ScheduleTooltip depending on the active view. The active view is passed, and if a truthy value is returned, the tip is shown, otherwise it is hidden.

This defaults to only showing for DayViews

ParameterTypeDescription
viewCalendarView

The Calendar view that the pointer is over. Return true to show the ScheduleTooltip for the passed view.

dateDate

The date at the pointer position as accurately as can be determined. If the view is a DayView, this date will have hour and minute resolution.

Returns: Boolean -

Whether to show the ScheduleTooltip.

Gets the Tooltip instance that this feature is using.

Lifecycle

configBase

Misc

clientInstancePlugin
localeHelperLocalizable
localeManagerLocalizable

Functions

29

Other

The default renderer for the tooltip, which shows the time at the pointer position. If the view is a day view, it will also show the time in the format specified by the timeFormat config of the view.

ParameterTypeDescription
viewCalendarView

The view that the pointer is over.

dateDate

The date at the pointer position. If the view is a DayView, this date is snapped to the view's increment based on the view's timeSnapType if any.

preciseDateDate

The precise date at the pointer position. This may differ from date if the view is a DayView. It will be as accurate as can be determined.

eventsEventModel[]

The events which coincide with the pointer position.

timeRangesTimeRangeModel[]

The time ranges which coincide with the pointer position.

resourceResourceModel

The resource record if any at the pointer position.

Returns: String -

The HTML to display in the tooltip.

LstaticLocalizable
onEvents
relayAllEvents
triggerEvents
unEvents

Configuration

applyDefaultsstaticBase

Events

Lifecycle

destroystaticBase

Misc

doDisableInstancePlugin
initClassstaticBase
isOfTypeNamestaticBase
mixinstaticBase
optionalLstaticLocalizable

Events

5
catchAllEvents
destroyEvents
disableInstancePlugin
enableInstancePlugin

Event handlers

5
onDestroyEvents
onDisableInstancePlugin
onEnableInstancePlugin

Typedefs

1