@jswf/core
Version:
JavaScript Window Framework
133 lines • 5.47 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
/* eslint-disable @typescript-eslint/class-name-casing */
var BaseView_1 = require("./BaseView");
require("../scss/CalendarView.scss");
var Libs = __importStar(require("./Libs"));
var CalendarView = /** @class */ (function (_super) {
__extends(CalendarView, _super);
function CalendarView(p) {
var _this = _super.call(this, p) || this;
_this.calendarDate = new Date();
_this.startDate = null;
_this.endDate = null;
_this.holidays = {};
_this.selects = {};
_this.setJwfStyle("CalendarView");
var weekString = "日月火水木金土";
var client = _this.getClient();
var table = document.createElement("table");
client.appendChild(table);
//月表示
var titleLine = table.insertRow(-1);
var prev = titleLine.insertCell(-1);
prev.innerText = "←";
prev.addEventListener("click", function () {
_this.moveMonth(-1);
});
var titleCell = titleLine.insertCell(-1);
_this.titleCell = titleCell;
titleCell.colSpan = 5;
var next = titleLine.insertCell(-1);
next.innerText = "→";
next.addEventListener("click", function () {
_this.moveMonth(1);
});
_this.dateCells = [];
var that = _this;
for (var j = 0; j < 7; j++) {
var line = table.insertRow(-1);
for (var i = 0; i < 7; i++) {
var cell = line.insertCell(-1);
if (j == 0)
cell.innerHTML = weekString.substr(i, 1);
else {
cell.addEventListener("click", function () {
that.onCellClick(this);
});
_this.dateCells.push(cell);
var day = document.createElement("div");
cell.appendChild(day);
var dayText = document.createElement("div");
cell.appendChild(dayText);
var select = document.createElement("div");
cell.appendChild(select);
}
}
}
_this.redraw();
return _this;
}
CalendarView.prototype.moveMonth = function (month) {
var date = this.calendarDate;
this.calendarDate = new Date(date.getFullYear(), date.getMonth() + month);
this.redraw();
};
CalendarView.prototype.redraw = function () {
var calendarDate = this.calendarDate;
var date = new Date(calendarDate.getFullYear(), calendarDate.getMonth(), 1);
this.titleCell.innerText = Libs.sprintf("%d年%d月", date.getFullYear(), date.getMonth() + 1);
date.setDate(date.getDate() - date.getDay());
var dateStart = new Date(date.getTime());
this.startDate = dateStart;
this.endDate = new Date(dateStart.getFullYear(), dateStart.getMonth(), dateStart.getDate() + 42);
var dateCells = this.dateCells;
for (var i = 0; i < 42; i++) {
var cell = dateCells[i];
var day = cell.childNodes[0];
var text = cell.childNodes[1];
day.innerText = date.getDate().toString();
cell.date = new Date(date);
cell.dataset.select = this.selects[date.toDateString()] ? "true" : "";
var holiday = this.holidays[date.toDateString()];
if (holiday) {
text.style.visibility = "visible";
text.innerText = holiday;
}
else {
text.style.visibility = "hidden";
text.innerText = "";
}
date.setDate(date.getDate() + 1);
}
//getHoliday(dateStart);
};
CalendarView.prototype.setHoliday = function (date, text) {
this.holidays[date.toDateString()] = text;
};
CalendarView.prototype.setSelect = function (date, value) {
if (value === void 0) { value = true; }
if (value)
this.selects[date.toDateString()] = true;
else
delete this.selects;
this.redraw();
};
CalendarView.prototype.onCellClick = function (cell) {
if (cell.date)
this.callEvent("date", { date: cell.date });
};
return CalendarView;
}(BaseView_1.BaseView));
exports.CalendarView = CalendarView;
//# sourceMappingURL=CalendarView.js.map