aboutsummaryrefslogtreecommitdiffstats
path: root/library/fullcalendar/packages/web-component/index.global.js
blob: aa22a52a3244e6470c772e09dacde7b481d7d269 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*!
FullCalendar Web Component v6.0.3
Docs & License: https://fullcalendar.io
(c) 2022 Adam Shaw
*/
(function (core) {
    'use strict';

    class FullCalendarElement extends HTMLElement {
        constructor() {
            super(...arguments);
            this._calendar = null;
            this._options = null;
        }
        connectedCallback() {
            this._handleOptionsStr(this.getAttribute('options'));
        }
        disconnectedCallback() {
            this._handleOptionsStr(null);
        }
        attributeChangedCallback(name, oldVal, newVal) {
            if (name === 'options' &&
                this._calendar // initial render happened
            ) {
                this._handleOptionsStr(newVal);
            }
        }
        get options() {
            return this._options;
        }
        set options(options) {
            this._handleOptions(options);
        }
        getApi() {
            return this._calendar;
        }
        _handleOptionsStr(optionsStr) {
            this._handleOptions(optionsStr ? JSON.parse(optionsStr) : null);
        }
        _handleOptions(options) {
            if (options) {
                if (this._calendar) {
                    this._calendar.resetOptions(options);
                }
                else {
                    this.innerHTML = '<div></div>';
                    let calendarEl = this.querySelector('div');
                    let calendar = new core.Calendar(calendarEl, options);
                    calendar.render();
                    this._calendar = calendar;
                }
                this._options = options;
            }
            else {
                if (this._calendar) {
                    this._calendar.destroy();
                    this._calendar = null;
                }
                this._options = null;
            }
        }
        static get observedAttributes() {
            return ['options'];
        }
    }

    globalThis.FullCalendarElement = FullCalendarElement;
    customElements.define('full-calendar', FullCalendarElement);

})(FullCalendar);