You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

5 lines
19 KiB

/*! Zabuto Calendar - v2.1.0 - 2022-12-29
* https://github.com/zabuto/calendar
* Copyright (c) 2022 Anke Heijnen; Licensed MIT */
!function (a) { !function (a, b, c, d) { "use strict"; function e(b, c) { this.element = b, this._name = f, this._defaults = a.fn[f].defaults, this.settings = a.extend({}, this._defaults, c), null !== this.settings.translation ? this.settings.language = null : this.settings.language = this.settings.language.toLowerCase(), this.init() } var f = "zabuto_calendar", g = new Date; a.fn[f] = function (b) { var c; if (b !== d) { var g = a.makeArray(arguments); c = g.slice(1) } return this.each(function () { var d = a.data(this, "plugin_" + f); d ? "string" == typeof b && "function" == typeof d[b] && d[b].apply(d, c) : a.data(this, "plugin_" + f, new e(this, b)) }) }, a.fn[f].defaults = { year: g.getFullYear(), month: g.getMonth() + 1, language: "en", translation: null, week_starts: "monday", show_days: !0, classname: null, header_format: "[month] [year]", date_format: "y-m-d", navigation_prev: !0, navigation_next: !0, navigation_markup: { prev: "&#9668;", next: "&#9658;" }, today_markup: null, events: null, ajax: null }, a.fn[f].languages = {}, a.extend(e.prototype, { init: function () { var b = a.Event("zabuto:calendar:init"); b.settings = this.settings, a(this.element).trigger(b), this.goto(this.settings.year, this.settings.month) }, destroy: function () { var b = a(this.element); b.removeData("plugin_" + f), b.removeData("year"), b.removeData("month"), b.removeData("event-data"), b.empty(), b.trigger("zabuto:calendar:destroy") }, reload: function () { var b = a(this.element), c = a.Event("zabuto:calendar:reload"); c.year = b.data("year"), c.month = b.data("month"), b.trigger(c), this.data() }, goto: function (b, c) { if (!1 !== this._isValidDate(b, c, 1)) { var d = a.Event("zabuto:calendar:goto"); d.year = b, d.month = c; var e = a(this.element); e.data("year", b), e.data("month", c), e.trigger(d), this.data() } }, data: function () { var b = this, c = a(this.element), d = b._getEventHandle(); if (null === d) c.data("event-data", []), this.render(); else if ("fixed" === d.type) { var e = b._eventsToDays(d.data), f = a.Event("zabuto:calendar:data"); f.type = "fixed", f.eventlist = d.data, f.eventdata = e, c.data("event-data", e), c.trigger(f), b.render() } else if ("ajax" === d.type) { var g = d.settings; g.data = { year: c.data("year"), month: c.data("month") }, g.dataType = "json", a.ajax(g).done(function (d) { var e = b._eventsToDays(d), f = a.Event("zabuto:calendar:data"); f.type = "ajax", f.eventlist = d, f.eventdata = e, c.data("event-data", e), c.trigger(f), b.render() }).fail(function (d, e, f) { var g = a.Event("zabuto:calendar:data-fail"); g.text = e, g.error = f, c.data("event-data", []), c.trigger(g), b.render() }) } }, render: function () { var b = a(this.element), c = b.data("year"), d = b.data("month"), e = a.Event("zabuto:calendar:preRender"); e.year = c, e.month = d, b.trigger(e), b.empty(), this._isValidDate(c, d, 1) && b.append(this._renderTable(c, d)); var f = a.Event("zabuto:calendar:render"); f.year = c, f.month = d, b.trigger(f) }, _renderTable: function (b, c) { var d = a("<table></table>").addClass("zabuto-calendar"); this.settings.classname && d.addClass(this.settings.classname); var e = a("<thead></thead>"); e.append(this._renderNavigation(b, c)), !0 === this.settings.show_days && e.append(this._renderDaysOfWeek()); var f = this._renderDaysInMonth(b, c); return d.append(e), d.append(f), d }, _renderNavigation: function (b, c) { var d = this, e = d.settings.header_format; e = e.replace("[year]", b.toString()); var f = d._getTranslation(); if (null !== f && "months" in f) { var g = f.months; e = e.replace("[month]", g[c.toString()]) } else e = e.replace("[month]", c.toString()); var h = a("<tr></tr>").addClass("zabuto-calendar__navigation").attr("role", "navigation"), i = d._calculatePrevious(b, c), j = d._calculateNext(b, c), k = a("<span></span>").text(e).data("to", { year: d.settings.year, month: d.settings.month }); k.addClass("zabuto-calendar__navigation__item--header__title"), null === i && null === j || k.on("zabuto:calendar:navigate-init", function (b) { var c = a(this).data("to"); b.year = c