📄 calendar_core.js
字号:
* Renders the current calendar cell as a non-selectable "black-out" date using the default
* restricted style.
* @param {Date} workingDate The current working Date object being used to generate the calendar
* @param {HTMLTableCellElement} cell The current working cell in the calendar
* @return YAHOO.widget.Calendar_Core.STOP_RENDER if rendering should stop with this style, null or nothing if rendering
* should not be terminated
* @type String
*/
YAHOO.widget.Calendar_Core.prototype.renderBodyCellRestricted = function(workingDate, cell) {
YAHOO.widget.Calendar_Core.setCssClasses(cell, [this.Style.CSS_CELL,this.Style.CSS_CELL_RESTRICTED]);
cell.innerHTML=workingDate.getDate();
return YAHOO.widget.Calendar_Core.STOP_RENDER;
};
/******************** END BUILT-IN TABLE CELL RENDERERS ************************************/
/******************** BEGIN MONTH NAVIGATION METHODS ************************************/
/**
* Adds the designated number of months to the current calendar month, and sets the current
* calendar page date to the new month.
* @param {Integer} count The number of months to add to the current calendar
*/
YAHOO.widget.Calendar_Core.prototype.addMonths = function(count) {
this.pageDate = YAHOO.widget.DateMath.add(this.pageDate, YAHOO.widget.DateMath.MONTH, count);
this.resetRenderers();
this.onChangePage();
};
/**
* Subtracts the designated number of months from the current calendar month, and sets the current
* calendar page date to the new month.
* @param {Integer} count The number of months to subtract from the current calendar
*/
YAHOO.widget.Calendar_Core.prototype.subtractMonths = function(count) {
this.pageDate = YAHOO.widget.DateMath.subtract(this.pageDate, YAHOO.widget.DateMath.MONTH, count);
this.resetRenderers();
this.onChangePage();
};
/**
* Adds the designated number of years to the current calendar, and sets the current
* calendar page date to the new month.
* @param {Integer} count The number of years to add to the current calendar
*/
YAHOO.widget.Calendar_Core.prototype.addYears = function(count) {
this.pageDate = YAHOO.widget.DateMath.add(this.pageDate, YAHOO.widget.DateMath.YEAR, count);
this.resetRenderers();
this.onChangePage();
};
/**
* Subtcats the designated number of years from the current calendar, and sets the current
* calendar page date to the new month.
* @param {Integer} count The number of years to subtract from the current calendar
*/
YAHOO.widget.Calendar_Core.prototype.subtractYears = function(count) {
this.pageDate = YAHOO.widget.DateMath.subtract(this.pageDate, YAHOO.widget.DateMath.YEAR, count);
this.resetRenderers();
this.onChangePage();
};
/**
* Navigates to the next month page in the calendar widget.
*/
YAHOO.widget.Calendar_Core.prototype.nextMonth = function() {
this.addMonths(1);
};
/**
* Navigates to the previous month page in the calendar widget.
*/
YAHOO.widget.Calendar_Core.prototype.previousMonth = function() {
this.subtractMonths(1);
};
/**
* Navigates to the next year in the currently selected month in the calendar widget.
*/
YAHOO.widget.Calendar_Core.prototype.nextYear = function() {
this.addYears(1);
};
/**
* Navigates to the previous year in the currently selected month in the calendar widget.
*/
YAHOO.widget.Calendar_Core.prototype.previousYear = function() {
this.subtractYears(1);
};
/****************** END MONTH NAVIGATION METHODS ************************************/
/************* BEGIN SELECTION METHODS *************************************************************/
/**
* Resets the calendar widget to the originally selected month and year, and
* sets the calendar to the initial selection(s).
*/
YAHOO.widget.Calendar_Core.prototype.reset = function() {
this.selectedDates.length = 0;
this.selectedDates = this._selectedDates.concat();
this.pageDate = new Date(this._pageDate.getTime());
this.onReset();
};
/**
* Clears the selected dates in the current calendar widget and sets the calendar
* to the current month and year.
*/
YAHOO.widget.Calendar_Core.prototype.clear = function() {
this.selectedDates.length = 0;
this.pageDate = new Date(this.today.getTime());
this.onClear();
};
/**
* Selects a date or a collection of dates on the current calendar. This method, by default,
* does not call the render method explicitly. Once selection has completed, render must be
* called for the changes to be reflected visually.
* @param {String/Date/Date[]} date The date string of dates to select in the current calendar. Valid formats are
* individual date(s) (12/24/2005,12/26/2005) or date range(s) (12/24/2005-1/1/2006).
* Multiple comma-delimited dates can also be passed to this method (12/24/2005,12/11/2005-12/13/2005).
* This method can also take a JavaScript Date object or an array of Date objects.
* @return Array of JavaScript Date objects representing all individual dates that are currently selected.
* @type Date[]
*/
YAHOO.widget.Calendar_Core.prototype.select = function(date) {
this.onBeforeSelect();
var aToBeSelected = this._toFieldArray(date);
for (var a=0;a<aToBeSelected.length;++a)
{
var toSelect = aToBeSelected[a]; // For each date item in the list of dates we're trying to select
if (this._indexOfSelectedFieldArray(toSelect) == -1) // not already selected?
{
this.selectedDates[this.selectedDates.length]=toSelect;
}
}
if (this.parent) {
this.parent.sync(this);
}
this.onSelect();
return this.getSelectedDates();
};
/**
* Selects a date on the current calendar by referencing the index of the cell that should be selected.
* This method is used to easily select a single cell (usually with a mouse click) without having to do
* a full render. The selected style is applied to the cell directly.
* @param {Integer} cellIndex The index of the cell to select in the current calendar.
* @return Array of JavaScript Date objects representing all individual dates that are currently selected.
* @type Date[]
*/
YAHOO.widget.Calendar_Core.prototype.selectCell = function(cellIndex) {
this.onBeforeSelect();
this.cells = this.tbody.getElementsByTagName("TD");
var cell = this.cells[cellIndex];
var cellDate = this.cellDates[cellIndex];
var dCellDate = this._toDate(cellDate);
var selectDate = cellDate.concat();
this.selectedDates.push(selectDate);
if (this.parent) {
this.parent.sync(this);
}
this.renderCellStyleSelected(dCellDate,cell);
this.onSelect();
this.doCellMouseOut.call(cell, null, this);
return this.getSelectedDates();
};
/**
* Deselects a date or a collection of dates on the current calendar. This method, by default,
* does not call the render method explicitly. Once deselection has completed, render must be
* called for the changes to be reflected visually.
* @param {String/Date/Date[]} date The date string of dates to deselect in the current calendar. Valid formats are
* individual date(s) (12/24/2005,12/26/2005) or date range(s) (12/24/2005-1/1/2006).
* Multiple comma-delimited dates can also be passed to this method (12/24/2005,12/11/2005-12/13/2005).
* This method can also take a JavaScript Date object or an array of Date objects.
* @return Array of JavaScript Date objects representing all individual dates that are currently selected.
* @type Date[]
*/
YAHOO.widget.Calendar_Core.prototype.deselect = function(date) {
this.onBeforeDeselect();
var aToBeSelected = this._toFieldArray(date);
for (var a=0;a<aToBeSelected.length;++a)
{
var toSelect = aToBeSelected[a]; // For each date item in the list of dates we're trying to select
var index = this._indexOfSelectedFieldArray(toSelect);
if (index != -1)
{
this.selectedDates.splice(index,1);
}
}
if (this.parent) {
this.parent.sync(this);
}
this.onDeselect();
return this.getSelectedDates();
};
/**
* Deselects a date on the current calendar by referencing the index of the cell that should be deselected.
* This method is used to easily deselect a single cell (usually with a mouse click) without having to do
* a full render. The selected style is removed from the cell directly.
* @param {Integer} cellIndex The index of the cell to deselect in the current calendar.
* @return Array of JavaScript Date objects representing all individual dates that are currently selected.
* @type Date[]
*/
YAHOO.widget.Calendar_Core.prototype.deselectCell = function(i) {
this.onBeforeDeselect();
this.cells = this.tbody.getElementsByTagName("TD");
var cell = this.cells[i];
var cellDate = this.cellDates[i];
var cellDateIndex = this._indexOfSelectedFieldArray(cellDate);
var dCellDate = this._toDate(cellDate);
var selectDate = cellDate.concat();
if (cellDateIndex > -1)
{
if (this.pageDate.getMonth() == dCellDate.getMonth() &&
this.pageDate.getFullYear() == dCellDate.getFullYear())
{
YAHOO.widget.Calendar_Core.removeCssClass(cell, this.Style.CSS_CELL_SELECTED);
}
this.selectedDates.splice(cellDateIndex, 1);
}
if (this.parent) {
this.parent.sync(this);
}
this.onDeselect();
return this.getSelectedDates();
};
/**
* Deselects all dates on the current calendar.
* @return Array of JavaScript Date objects representing all individual dates that are currently selected.
* Assuming that this function executes properly, the return value should be an empty array.
* However, the empty array is returned for the sake of being able to check the selection status
* of the calendar.
* @type Date[]
*/
YAHOO.widget.Calendar_Core.prototype.deselectAll = function() {
this.onBeforeDeselect();
var count = this.selectedDates.length;
this.selectedDates.length = 0;
if (this.parent) {
this.parent.sync(this);
}
if (count > 0) {
this.onDeselect();
}
return this.getSelectedDates();
};
/************* END SELECTION METHODS *************************************************************/
/************* BEGIN TYPE CONVERSION METHODS ****************************************************/
/**
* Converts a date (either a JavaScript Date object, or a date string) to the internal data structure
* used to represent dates: [[yyyy,mm,dd],[yyyy,mm,dd]].
* @private
* @param {String/Date/Date[]} date The date string of dates to deselect in the current calendar. Valid formats are
* individual date(s) (12/24/2005,12/26/2005) or date range(s) (12/24/2005-1/1/2006).
* Multiple comma-delimited dates can also be passed to this method (12/24/2005,12/11/2005-12/13/2005).
* This method can also take a JavaScript Date object or an array of Date objects.
* @return Array of date field arrays
* @type Array[](Integer[])
*/
YAHOO.widget.Calendar_Core.prototype._toFieldArray = function(date) {
var returnDate = new Array();
if (date instanceof Date)
{
returnDate = [[date.getFullYear(), date.getMonth()+1, date.getDate()]];
}
else if (typeof date == 'string')
{
returnDate = this._parseDates(date);
}
else if (date instanceof Array)
{
for (var i=0;i<date.length;++i)
{
var d = date[i];
returnDate[returnDate.length] = [d.getFullYear(),d.getMonth()+1,d.getDate()];
}
}
return returnDate;
};
/**
* Converts a date field array [yyyy,mm,dd] to a JavaScript Date object.
* @private
* @param {Integer[]} dateFieldArray The date field array to convert to a JavaScript Date.
* @return JavaScript Date object representing the date field array
* @type Date
*/
YAHOO.widget.Calendar_Core.prototype._toDate = function(dateFieldArray) {
if (dateFieldArray instanceof Date)
{
return dateFieldArray;
} else
{
return new Date(dateFieldArray[0],dateFieldArray[1]-1,dateFieldArray[2]);
}
};
/************* END TYPE CONVERSION METHODS ******************************************************/
/************* BEGIN UTILITY METHODS ****************************************************/
/**
* Converts a date field array [yyyy,mm,dd] to a JavaScript Date object.
* @private
* @param {Integer[]} array1 The first date field array to compare
* @param {Integer[]} array2 The first date field array to compare
* @return The boolean that represents the equality of the two arrays
* @type Boolean
*/
YAHOO.widget.Calendar_Core.prototype._fieldArraysAreEqual = function(array1, array2) {
var match = false;
if (array1[0]==array2[0]&&array1[1]==array2[1]&&array1[2]==array2[2])
{
match=true;
}
return match;
};
/**
* Gets the index of a date field array [yyyy,mm,dd] in the current list of selected dates.
* @private
* @param {Integer[]} find The date field array to search for
* @return The index of the date field array within the collection of selected dates.
* -1 will be returned if the date is not found.
* @type Integer
*/
YAHOO.widget.Calendar_Core.prototype._indexOfSelectedFieldArray = function(find) {
var selected = -1;
for (var s=0;s<this.selectedDates.length;++s)
{
var sArray = this.selectedDates[s];
if (find[0]==sArray[0]&&find[1]==sArray[1]&&find[2]==sArray[2])
{
selected = s;
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -