📄 suite.js
字号:
function uiCalendar_Suite(domTable, dayLabels, classResolver, actionResolver) { this._super(); this.__elementHandler = uiHtml_ElementWrapper.getInstance(); this.__selectedDate = new uiUtil_Calendar(); this.__domTable = domTable; this.__yearListers = new Array(); this.__monthListers = new Array(); this.__classResolver = classResolver; this.__actionResolver = actionResolver; this.__selectedDate.addUpdateListener(this); this.__initGrid(this.__domTable, dayLabels);}uiCalendar_Suite = uiUtil_Object.declareClass(uiCalendar_Suite, uiUtil_Object);uiCalendar_Suite.GRID_TOTAL_ROW_COUNT = 7; uiCalendar_Suite.GRID_DATA_ROW_START = 1;uiCalendar_Suite.GRID_TOTAL_COL_COUNT = uiUtil_Calendar.NUM_DAYS_IN_A_WEEK;uiCalendar_Suite.prototype.__initGrid = function(domTable, dayLabels) { this.__addHeaderTo(domTable, dayLabels); this.__addBodyTo(domTable); this.__updateGrid(domTable);};uiCalendar_Suite.prototype.__translateToCustomDayIndex = function(origDayOfWeekId) { return origDayOfWeekId; };uiCalendar_Suite.prototype.__addHeaderTo = function(gridTable, dayLabels) { var dayNameRow = this.__addRowTo(gridTable); var maxDayId = uiUtil_Calendar.NUM_DAYS_IN_A_WEEK; for (var dayOfWeekId = 0; dayOfWeekId < maxDayId; ++dayOfWeekId) { var dayOfThisCell = this.__translateToCustomDayIndex(dayOfWeekId); var cell = this.__addCellTo(dayNameRow, dayLabels[dayOfThisCell]); var classOfThisCell = this.__classResolver.getForHeader(dayOfWeekId); cell.className = classOfThisCell; }};uiCalendar_Suite.prototype.__addRowTo = function(table) { return table.insertRow(-1);};uiCalendar_Suite.prototype.__addCellTo = function(row, text) { var cell = row.insertCell(-1); uiHtml_Document.createTextNode(text, cell); return cell;};uiCalendar_Suite.prototype.__addBodyTo = function(gridTable) { var rowStart = uiCalendar_Suite.GRID_DATA_ROW_START; var rowCount = uiCalendar_Suite.GRID_TOTAL_ROW_COUNT; for (var row = rowStart; row < rowCount; row++) { var currentRow = this.__addRowTo(gridTable); for (var col=0; col < uiCalendar_Suite.GRID_TOTAL_COL_COUNT; col++) { this.__addCellTo(currentRow, " "); } }};uiCalendar_Suite.prototype.dateUpdated = function(date) { for (var i = 0; i < this.__yearListers.length; i++) { this.__updateYearLister(this.__yearListers[i], date); } for (var i = 0; i < this.__monthListers.length; i++) { this.__updateMonthLister(this.__monthListers[i]); }};uiCalendar_Suite.prototype.__updateYearLister = function(lister, date) { var select = lister.__select; select.clearItems(); var years = lister.__strategy.getYearArray(this.__selectedDate.getYear()); for (var i = 0; i < years.length; ++i) { select.addItem(uiHtml_SelectOptionWrapper.create(years[i], years[i])); } select.setSelectedValue(this.__selectedDate.getYear());};uiCalendar_Suite.prototype._addYearLister = function(select, strategy) { var lister = new uiCalendar_Suite.YearLister(select, strategy); this.__yearListers.push(lister); this._addUpdater(select, "change", new uiCalendar_Suite.YearExtractor(select.getDomObject())); this.__updateYearLister(lister);};uiCalendar_Suite.prototype.__updateMonthLister = function(lister) { lister.__select.setSelectedValue(this.__selectedDate.getMonth());};uiCalendar_Suite.prototype._addMonthLister = function(select, monthLabels) { var lister = new uiCalendar_Suite.MonthLister(select); this.__monthListers.push(lister); select.clearItems(); for (var i = 0; i < monthLabels.length; ++i) { select.addItem(uiHtml_SelectOptionWrapper.create(monthLabels[i], i)); } this._addUpdater(select, "change", new uiCalendar_Suite.MonthExtractor(select.getDomObject())); this.__updateMonthLister(lister);};uiCalendar_Suite.prototype._addUpdater = function(trigger, event, strategy) { var suite = this; trigger.appendEventHandler(event, function(e) { var jsSelectedDate = new Date(suite.__selectedDate.toDate()); var jsNewDate = strategy.getNewDate(jsSelectedDate); suite.update(jsNewDate); });};uiCalendar_Suite.prototype.update = function(jsNewDate) { var newDate = new uiUtil_Calendar(jsNewDate); if (this.__selectedDate.getDay() != newDate.getDay() || this.__selectedDate.getMonth() != newDate.getMonth() || this.__selectedDate.getYear() != newDate.getYear()) { this.__selectedDate.fromDate(jsNewDate); this.__updateGrid(this.__domTable); }};uiCalendar_Suite.prototype.__updateGrid = function(gridTable) { var firstDayInMonth = this.__selectedDate.getFirstDayInMonth(); var numDaysInMonth = this.__selectedDate.getNumDaysInMonth(); var currentDate = new uiUtil_Calendar(this.__selectedDate.toDate()); currentDate.setDay(1); for (var i = 0; i <= firstDayInMonth; ++i) { currentDate.decrementDay(); } var rowIndex = uiCalendar_Suite.GRID_DATA_ROW_START; var rowCount = uiCalendar_Suite.GRID_TOTAL_ROW_COUNT; for (var row = rowIndex; row < rowCount; ++row) { currentRow = gridTable.rows[row]; for (var col=0; col < uiUtil_Calendar.NUM_DAYS_IN_A_WEEK; ++col) { currentDate.incrementDay(); this.__updateCellData(currentRow.cells[col], currentDate); } }};uiCalendar_Suite.prototype.__updateCellData = function(cell, date) { this.__detachCellClickHandler(cell); this.__elementHandler.clearChildDomObjects(cell); if (date == null) { uiHtml_Document.createTextNode(" ", cell); } else { uiHtml_Document.createTextNode(date.getDay(), cell); this.__attachCellClickHandler(cell, date); this.__updateCellClass(cell, date); }};uiCalendar_Suite.prototype.__updateCellClass = function(cell, date) { var cssClass = this.__classResolver.getForDate( date.toDate(), this.__selectedDate.toDate()); cell.className = cssClass;};uiCalendar_Suite.prototype.__attachCellClickHandler = function(domCell, date) { if (this.__actionResolver == null) { return null; } var eventNames = this.__actionResolver.getEventsOfInterest(); for (var i = 0; i < eventNames.length; ++i) { var action = this.__actionResolver.getAction( eventNames[i], this, date.toDate(), this.__selectedDate.toDate()); if (action != null) { this.__elementHandler.appendEventHandler(domCell, eventNames[i], action); } }};uiCalendar_Suite.prototype.__detachCellClickHandler = function(domCell) { if (this.__actionResolver == null) { return; } var eventNames = this.__actionResolver.getEventsOfInterest(); for (var i = 0; i < eventNames.length; ++i) { this.__elementHandler.clearEventHandlerExtension(domCell, eventNames[i]); }};function uiCalendar_Suite$YearLister(select, strategy) { this.__select = select; this.__strategy = strategy; this.__select.enableOptionValueMapping();}uiCalendar_Suite.YearLister = uiUtil_Object.declareClass(uiCalendar_Suite$YearLister, uiUtil_Object);function uiCalendar_Suite$MonthLister(select) { this.__select = select; this.__select.enableOptionValueMapping();}uiCalendar_Suite.MonthLister = uiUtil_Object.declareClass(uiCalendar_Suite$MonthLister, uiUtil_Object);function uiCalendar_Suite$MonthExtractor(domMonthInput) { this.__domMonthInput = domMonthInput;}uiCalendar_Suite.MonthExtractor = uiUtil_Object.declareClass( uiCalendar_Suite$MonthExtractor, uiUtil_Object);uiCalendar_Suite.MonthExtractor.prototype.getNewDate = function(selectedDate) { selectedDate.setMonth(this.__domMonthInput.value); return selectedDate;};function uiCalendar_Suite$YearExtractor(domYearInput) { this.__domYearInput = domYearInput;}uiCalendar_Suite.YearExtractor = uiUtil_Object.declareClass( uiCalendar_Suite$YearExtractor, uiUtil_Object);uiCalendar_Suite.YearExtractor.prototype.getNewDate = function(selectedDate) { selectedDate.setYear(this.__domYearInput.value); return selectedDate;};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -