PageSourceSearch

https://www.zoloft.com/-/media/Base-Themes/Components-Theme/Scripts/component-fullcalendar.js

js zoloft.com collected 2026-09-24 20:04:32 UTC 12,794 bytes, 376 lines download raw bytes

1/* global googleCalendarApiKey:true */
2/**
3 * Component Fullcalendar
4 * @module Fullcalendar
5 * @param  {jQuery} $ Instance of jQuery
6 * @return {Object} List of archive methods
7 */
8XA.component.calendar = (function($) {
9    /**
10     * This class is used by [Fullcalendar]{@link module:Fullcalendar} module for
11     * storing events option
12     * @class GetEvents
13     * @memberOf module:Fullcalendar
14     * @param {string} selector selector of event element
15     * @param {Object} options options of component
16     */
17    function GetEvents(selector, options) {
18        this.data = options.data;
19        this.selector = selector;
20        this.options = options;
21        this.events = [];
22
23        this.checkSource();
24    }
25    /**
26     * checkSource method calls ["getJson"]{@link module:Fullcalendar.GetEvents.getJson}
27     * if "options.dataType" equal "json"
28     * and creates instance of
29     * ["InitCalendar"]{@link module:Fullcalendar.InitCalendar} class
30     * @name checkSource
31     * @function
32     * @memberOf module:Fullcalendar.GetEvents
33     */
34    GetEvents.prototype.checkSource = function() {
35        var inst = this;
36
37        switch (inst.options.dataType) {
38            case "json":
39                inst.getJson();
40                new InitCalendar(inst.selector, inst.options, inst.events);
41                break;
42            case "gcalendar":
43                new InitCalendar(inst.selector, inst.options, inst.events);
44                break;
45        }
46    };
47    /**
48     * getJson method fills array of events with
49     * new event
50     * @name getJson
51     * @function
52     * @memberOf module:Fullcalendar.GetEvents
53     */
54    GetEvents.prototype.getJson = function() {
55        var inst = this,
56            date,
57            dateEnd,
58            allDay = false,
59            tempObj = [];
60
61        $.each(inst.data, function() {
62            date = new Date(this.eventStart);
63            dateEnd = new Date(this.eventEnd);
64
65            if (date === dateEnd) {
66                allDay = true;
67            }
68
69            tempObj = {
70                title: this.eventName,
71                start: date,
72                end: dateEnd,
73                eventDescription: this.eventDescription,
74                eventLink: this.eventLink,
75                eventClass: this.eventClass
76            };
77
78            inst.events.push(tempObj);
79        });
80    };
81
82    /**
83     * This class is used by
84     * [GetEvents]{@link module:Fullcalendar.GetEvents} module and
85     * initializes instances of calendar with predefined list of options
86     * @class InitCalendar
87     * @memberOf module:Fullcalendar
88     * @param {string} selector DOM Root element of
89     * @param {Object} options options of component
90     * @param {Array} events options of event calendar ["event object"]{@link https://fullcalendar.io/docs/event-object}
91     */
92    function InitCalendar(selector, options, events) {
93        var inst = this,
94            prevNext = "",
95            title = "",
96            calendarTypes = "";
97
98        if (options.dataType === "gcalendar") {
99            googleCalendarApiKey = options.calendarApiKey;
100            events = options.calendarId;
101        } else {
102            googleCalendarApiKey = null;
103        }
104
105        options.showPrevNext ? (prevNext = "prev, next") : "";
106        options.showMonthCaptions ? (title = "title") : "";
107
108        for (var i in options.calendarTypes) {
109            if (options.calendarTypes[i] === "day") {
110                options.calendarTypes[i] = "basicDay";
111            } else if (options.calendarTypes[i] === "week") {
112                options.calendarTypes[i] = "basicWeek";
113            }
114        }
115
116        if (options.calendarTypes.length > 1) {
117            calendarTypes = options.calendarTypes.join();
118        }
119
120        $(selector).fullCalendar({
121            monthNames: options.localization.monthNames,
122            monthNamesShort: options.localization.monthNamesShort,
123            dayNames: options.localization.dayNames,
124            dayNamesShort: options.localization.dayNamesShort,
125            nextDayThreshold: "00:00",
126
127            buttonText: {
128                agendaDay: "agenda day",
129                agendaWeek: "agenda week"
130            },
131
132            header: {
133                left: prevNext,
134                center: title,
135                right: calendarTypes
136            },
137
138            googleCalendarApiKey: googleCalendarApiKey,
139            events: events,
140            renderEvent: false,
141            eventRender: function(event, element) {
142                if (options.compactView && options.dataType === "json") {
143                    $(element).css("display", "none");
144                } else {
145                    if (options.dataType === "json") {
146                        inst.attachTooltip(event, element, false);
147                    }
148                }
149
150                element.addClass(event.eventClass);
151            },
152            eventAfterAllRender: function() {
153                if (options.compactView && options.dataType === "json") {
154                    inst.renderCompactCalendarEvents(selector, events);
155                }
156            }
157        });
158    }
159    /**
160     * attachTooltip method creates, positions, and
161     * animates tooltips for events.
162     * @method
163     * @alias attachTooltip
164     * @memberOf module:Fullcalendar.InitCalendar
165     * @param {Object} event options of event calendar ["event object"]{@link https://fullcalendar.io/docs/event-object}
166     * @param {DOMElement} element DOM element of an event
167     * @param {boolean} compactCalendar  is calendar in compact mode
168     */
169    InitCalendar.prototype.attachTooltip = function(
170        event,
171        element,
172        compactCalendar
173    ) {
174        var $tooltip, tooltipContent;
175
176        $(element).on("mouseenter", function() {
177            tooltipContent = "";
178            $(".calendar-tooltip").fadeOut();
179            $(".calendar-tooltip").remove();
180
181            if (compactCalendar) {
182                tooltipContent = "";
183                $.each(event, function() {
184                    tooltipContent +=
185                        "<div class='compact-event'>" +
186                        "<span class='title'>" +
187                        this.title +
188                        "</span>" +
189                        "<span class='description'>" +
190                        this.eventDescription +
191                        "</span>" +
192                        "<span class='link'><a href='" +
193                        this.eventLink +
194                        "'>Link</a></span></div>";
195                });
196            } else {
197                tooltipContent =
198                    "<span class='description'>" +
199                    event.eventDescription +
200                    "</span>" +
201                    "<span class='link'>" +
202                    event.eventLink +
203                    "</span>";
204            }
205            $tooltip = $(
206                "<div style='border-radius:5px;border:1px solid #000;position:absolute;z-index:999; paading:5px;background:#FFF' class='calendar-tooltip'><div class='arrow'>" +
207                    "</div><div class='events'>" +
208                    tooltipContent +
209                    "</div></div>"
210            );
211
212            $tooltip.css({
213                left: $(this).offset().left
214            });
215            $tooltip.css({
216                top: $(this).offset().top - $(this).height()
217            });
218            $("body").append($tooltip);
219
220            var timeout;
221            $(this).unbind("mouseleave");
222            $(this).on("mouseleave", function() {
223                timeout = setTimeout(function() {
224                    $tooltip.fadeOut(function() {
225                        $(this).remove();
226                    });
227                }, 300);
228
229                $tooltip.unbind("mouseenter");
230                $tooltip.on("mouseenter", function() {
231                    clearTimeout(timeout);
232                });
233            });
234
235            $tooltip.unbind("mouseleave");
236            $tooltip.on("mouseleave", function() {
237                $(this).fadeOut(function() {
238                    $(this).remove();
239                });
240            });
241        });
242    };
243
244    /**
245     * attaches events for single days - compact calendar
246     * @method
247     * @alias renderCompactCalendarEvents
248     * @memberOf module:Fullcalendar.InitCalendar
249     * @param {Array} events  ["event object"]{@link https://fullcalendar.io/docs/event-object}
250     * @param {string} selector selector of an event in DOM
251     */
252    InitCalendar.prototype.renderCompactCalendarEvents = function(
253        selector,
254        events
255    ) {
256        var inst = this,
257            currentDay,
258            currentDate,
259            currentEvent,
260            dc,
261            mc,
262            yc,
263            d,
264            m,
265            y,
266            de,
267            me,
268            ye,
269            he,
270            startDate,
271            endDate,
272            dayEvents = [];
273
274        $(selector)
275            .find(".fc-day")
276            .each(function() {
277                currentDay = this;
278
279                currentDate = new Date($(this).data("date"));
280                dc = currentDate.getDate();
281                mc = currentDate.getMonth();
282                yc = currentDate.getFullYear();
283
284                dayEvents = [];
285                $.each(events, function() {
286                    currentEvent = this;
287                    startDate = new Date(this.start);
288                    d = startDate.getDate();
289                    m = startDate.getMonth();
290                    y = startDate.getFullYear();
291
292                    if (this.end) {
293                        endDate = new Date(this.end);
294                        de = endDate.getDate();
295                        me = endDate.getMonth();
296                        ye = endDate.getFullYear();
297                        he = endDate.getHours();
298                    }
299
300                    if (
301                        yc >= y &&
302                        yc <= ye &&
303                        mc >= m &&
304                        mc <= me &&
305                        dc >= d &&
306                        dc <= de
307                    ) {
308                        if (yc == ye && mc == me && dc == de && he < 9) {
309                            // If last day and hour < 9 do nothing
310                        } else {
311                            $(currentDay).addClass("selected-day");
312                            dayEvents.push(currentEvent);
313                        }
314                    }
315                });
316
317                if (dayEvents.length) {
318                    inst.attachTooltip(dayEvents, currentDay, true);
319                }
320            });
321    };
322    /**
323     * resizeCalendar method runs render of a calendar
324     * @memberOf module:Fullcalendar
325     * @param {string} selector  Selector of a calendar component
326     * @private
327     */
328    function resizeCalendar(selector) {
329        $(selector).fullCalendar("render");
330    }
331    /**
332     * This object stores all public api methods
333     * @type {Object.<Methods>}
334     * @memberOf module:Fullcalendar
335     * */
336    var api = {};
337    /**
338     * initInstance method creates instance of
339     * ["GetEvents"]{@link module:Fullcalendar.GetEvents} class and bind
340     * ["resizeCalendar"]{@link module:Fullcalendar.resizeCalendar} to window resize
341     * event
342     * @memberOf module:Fullcalendar
343     * @alias module:Fullcalendar.initInstance
344     */
345    api.initInstance = function(component, prop) {
346        var selector = "#" + component.find(".event-calendar-inner").attr("id");
347        if (prop.compactView && prop.dataType === "json") {
348            $(this).addClass("compact-mode");
349        }
350
351        new GetEvents(selector, prop);
352
353        $(window).resize(function() {
354            resizeCalendar(selector);
355        });
356    };
357
358    /**
359     * init method calls in a loop for each
360     * full calendar component on a page and run Full calendar's
361     * ["initInstance"]{@link module:Fullcalendar.api.initInstance} method
362     * @memberOf module:Fullcalendar
363     * @alias module:Fullcalendar.init
364     */
365    api.init = function() {
366        $(".event-calendar:not(.initialized)").each(function() {
367            var properties = $(this).data("properties");
368            api.initInstance($(this), properties);
369            $(this).addClass("initialized");
370        });
371    };
372
373    return api;
374})(jQuery, document);
375
376XA.register("calendar", XA.component.calendar);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.