📄 calendar_core.js
字号:
}
}
return selected;
};
/**
* Determines whether a given date is OOM (out of month).
* @param {Date} date The JavaScript Date object for which to check the OOM status
* @return {Boolean} true if the date is OOM
*/
YAHOO.widget.Calendar_Core.prototype.isDateOOM = function(date) {
var isOOM = false;
if (date.getMonth() != this.pageDate.getMonth()) {
isOOM = true;
}
return isOOM;
};
/************* END UTILITY METHODS *******************************************************/
/************* BEGIN EVENT HANDLERS ******************************************************/
/**
* Event executed before a date is selected in the calendar widget.
*/
YAHOO.widget.Calendar_Core.prototype.onBeforeSelect = function() {
if (! this.Options.MULTI_SELECT) {
this.clearAllBodyCellStyles(this.Style.CSS_CELL_SELECTED);
this.deselectAll();
}
};
/**
* Event executed when a date is selected in the calendar widget.
*/
YAHOO.widget.Calendar_Core.prototype.onSelect = function() { };
/**
* Event executed before a date is deselected in the calendar widget.
*/
YAHOO.widget.Calendar_Core.prototype.onBeforeDeselect = function() { };
/**
* Event executed when a date is deselected in the calendar widget.
*/
YAHOO.widget.Calendar_Core.prototype.onDeselect = function() { };
/**
* Event executed when the user navigates to a different calendar page.
*/
YAHOO.widget.Calendar_Core.prototype.onChangePage = function() { this.render(); };
/**
* Event executed when the calendar widget is rendered.
*/
YAHOO.widget.Calendar_Core.prototype.onRender = function() { };
/**
* Event executed when the calendar widget is reset to its original state.
*/
YAHOO.widget.Calendar_Core.prototype.onReset = function() { this.render(); };
/**
* Event executed when the calendar widget is completely cleared to the current month with no selections.
*/
YAHOO.widget.Calendar_Core.prototype.onClear = function() { this.render(); };
/**
* Validates the calendar widget. This method has no default implementation
* and must be extended by subclassing the widget.
* @return Should return true if the widget validates, and false if
* it doesn't.
* @type Boolean
*/
YAHOO.widget.Calendar_Core.prototype.validate = function() { return true; };
/************* END EVENT HANDLERS *********************************************************/
/************* BEGIN DATE PARSE METHODS ***************************************************/
/**
* Converts a date string to a date field array
* @private
* @param {String} sDate Date string. Valid formats are mm/dd and mm/dd/yyyy.
* @return A date field array representing the string passed to the method
* @type Array[](Integer[])
*/
YAHOO.widget.Calendar_Core.prototype._parseDate = function(sDate) {
var aDate = sDate.split(this.Locale.DATE_FIELD_DELIMITER);
var rArray;
if (aDate.length == 2)
{
rArray = [aDate[this.Locale.MD_MONTH_POSITION-1],aDate[this.Locale.MD_DAY_POSITION-1]];
rArray.type = YAHOO.widget.Calendar_Core.MONTH_DAY;
} else {
rArray = [aDate[this.Locale.MDY_YEAR_POSITION-1],aDate[this.Locale.MDY_MONTH_POSITION-1],aDate[this.Locale.MDY_DAY_POSITION-1]];
rArray.type = YAHOO.widget.Calendar_Core.DATE;
}
return rArray;
};
/**
* Converts a multi or single-date string to an array of date field arrays
* @private
* @param {String} sDates Date string with one or more comma-delimited dates. Valid formats are mm/dd, mm/dd/yyyy, mm/dd/yyyy-mm/dd/yyyy
* @return An array of date field arrays
* @type Array[](Integer[])
*/
YAHOO.widget.Calendar_Core.prototype._parseDates = function(sDates) {
var aReturn = new Array();
var aDates = sDates.split(this.Locale.DATE_DELIMITER);
for (var d=0;d<aDates.length;++d)
{
var sDate = aDates[d];
if (sDate.indexOf(this.Locale.DATE_RANGE_DELIMITER) != -1) {
// This is a range
var aRange = sDate.split(this.Locale.DATE_RANGE_DELIMITER);
var dateStart = this._parseDate(aRange[0]);
var dateEnd = this._parseDate(aRange[1]);
var fullRange = this._parseRange(dateStart, dateEnd);
aReturn = aReturn.concat(fullRange);
} else {
// This is not a range
var aDate = this._parseDate(sDate);
aReturn.push(aDate);
}
}
return aReturn;
};
/**
* Converts a date range to the full list of included dates
* @private
* @param {Integer[]} startDate Date field array representing the first date in the range
* @param {Integer[]} endDate Date field array representing the last date in the range
* @return An array of date field arrays
* @type Array[](Integer[])
*/
YAHOO.widget.Calendar_Core.prototype._parseRange = function(startDate, endDate) {
var dStart = new Date(startDate[0],startDate[1]-1,startDate[2]);
var dCurrent = YAHOO.widget.DateMath.add(new Date(startDate[0],startDate[1]-1,startDate[2]),YAHOO.widget.DateMath.DAY,1);
var dEnd = new Date(endDate[0], endDate[1]-1, endDate[2]);
var results = new Array();
results.push(startDate);
while (dCurrent.getTime() <= dEnd.getTime())
{
results.push([dCurrent.getFullYear(),dCurrent.getMonth()+1,dCurrent.getDate()]);
dCurrent = YAHOO.widget.DateMath.add(dCurrent,YAHOO.widget.DateMath.DAY,1);
}
return results;
};
/************* END DATE PARSE METHODS *****************************************************/
/************* BEGIN RENDERER METHODS *****************************************************/
/**
* Resets the render stack of the current calendar to its original pre-render value.
*/
YAHOO.widget.Calendar_Core.prototype.resetRenderers = function() {
this.renderStack = this._renderStack.concat();
};
/**
* Clears the inner HTML, CSS class and style information from the specified cell.
* @param {HTMLTableCellElement} The cell to clear
*/
YAHOO.widget.Calendar_Core.prototype.clearElement = function(cell) {
cell.innerHTML = " ";
cell.className="";
};
/**
* Adds a renderer to the render stack. The function reference passed to this method will be executed
* when a date cell matches the conditions specified in the date string for this renderer.
* @param {String} sDates A date string to associate with the specified renderer. Valid formats
* include date (12/24/2005), month/day (12/24), and range (12/1/2004-1/1/2005)
* @param {Function} fnRender The function executed to render cells that match the render rules for this renderer.
*/
YAHOO.widget.Calendar_Core.prototype.addRenderer = function(sDates, fnRender) {
var aDates = this._parseDates(sDates);
for (var i=0;i<aDates.length;++i)
{
var aDate = aDates[i];
if (aDate.length == 2) // this is either a range or a month/day combo
{
if (aDate[0] instanceof Array) // this is a range
{
this._addRenderer(YAHOO.widget.Calendar_Core.RANGE,aDate,fnRender);
} else { // this is a month/day combo
this._addRenderer(YAHOO.widget.Calendar_Core.MONTH_DAY,aDate,fnRender);
}
} else if (aDate.length == 3)
{
this._addRenderer(YAHOO.widget.Calendar_Core.DATE,aDate,fnRender);
}
}
};
/**
* The private method used for adding cell renderers to the local render stack.
* This method is called by other methods that set the renderer type prior to the method call.
* @private
* @param {String} type The type string that indicates the type of date renderer being added.
* Values are YAHOO.widget.Calendar_Core.DATE, YAHOO.widget.Calendar_Core.MONTH_DAY, YAHOO.widget.Calendar_Core.WEEKDAY,
* YAHOO.widget.Calendar_Core.RANGE, YAHOO.widget.Calendar_Core.MONTH
* @param {Array} aDates An array of dates used to construct the renderer. The format varies based
* on the renderer type
* @param {Function} fnRender The function executed to render cells that match the render rules for this renderer.
*/
YAHOO.widget.Calendar_Core.prototype._addRenderer = function(type, aDates, fnRender) {
var add = [type,aDates,fnRender];
this.renderStack.unshift(add);
this._renderStack = this.renderStack.concat();
};
/**
* Adds a month to the render stack. The function reference passed to this method will be executed
* when a date cell matches the month passed to this method.
* @param {Integer} month The month (1-12) to associate with this renderer
* @param {Function} fnRender The function executed to render cells that match the render rules for this renderer.
*/
YAHOO.widget.Calendar_Core.prototype.addMonthRenderer = function(month, fnRender) {
this._addRenderer(YAHOO.widget.Calendar_Core.MONTH,[month],fnRender);
};
/**
* Adds a weekday to the render stack. The function reference passed to this method will be executed
* when a date cell matches the weekday passed to this method.
* @param {Integer} weekay The weekday (1-7) to associate with this renderer
* @param {Function} fnRender The function executed to render cells that match the render rules for this renderer.
*/
YAHOO.widget.Calendar_Core.prototype.addWeekdayRenderer = function(weekday, fnRender) {
this._addRenderer(YAHOO.widget.Calendar_Core.WEEKDAY,[weekday],fnRender);
};
/************* END RENDERER METHODS *******************************************************/
/***************** BEGIN CSS METHODS *******************************************/
/**
* Adds the specified CSS class to the element passed to this method.
* @param {HTMLElement} element The element to which the CSS class should be applied
* @param {String} style The CSS class name to add to the referenced element
*/
YAHOO.widget.Calendar_Core.addCssClass = function(element, style) {
if (element.className.length === 0)
{
element.className += style;
} else {
element.className += " " + style;
}
};
YAHOO.widget.Calendar_Core.prependCssClass = function(element, style) {
element.className = style + " " + element.className;
}
/**
* Removed the specified CSS class from the element passed to this method.
* @param {HTMLElement} element The element from which the CSS class should be removed
* @param {String} style The CSS class name to remove from the referenced element
*/
YAHOO.widget.Calendar_Core.removeCssClass = function(element, style) {
var aStyles = element.className.split(" ");
for (var s=0;s<aStyles.length;++s)
{
if (aStyles[s] == style)
{
aStyles.splice(s,1);
break;
}
}
YAHOO.widget.Calendar_Core.setCssClasses(element, aStyles);
};
/**
* Sets the specified array of CSS classes into the referenced element
* @param {HTMLElement} element The element to set the CSS classes into
* @param {String[]} aStyles An array of CSS class names
*/
YAHOO.widget.Calendar_Core.setCssClasses = function(element, aStyles) {
element.className = "";
var className = aStyles.join(" ");
element.className = className;
};
/**
* Removes all styles from all body cells in the current calendar table.
* @param {style} The CSS class name to remove from all calendar body cells
*/
YAHOO.widget.Calendar_Core.prototype.clearAllBodyCellStyles = function(style) {
for (var c=0;c<this.cells.length;++c)
{
YAHOO.widget.Calendar_Core.removeCssClass(this.cells[c],style);
}
};
/***************** END CSS METHODS *********************************************/
/***************** BEGIN GETTER/SETTER METHODS *********************************/
/**
* Sets the calendar's month explicitly.
* @param {Integer} month The numeric month, from 1 (January) to 12 (December)
*/
YAHOO.widget.Calendar_Core.prototype.setMonth = function(month) {
this.pageDate.setMonth(month);
};
/**
* Sets the calendar's year explicitly.
* @param {Integer} year The numeric 4-digit year
*/
YAHOO.widget.Calendar_Core.prototype.setYear = function(year) {
this.pageDate.setFullYear(year);
};
/**
* Gets the list of currently selected dates from the calendar.
* @return An array of currently selected JavaScript Date objects.
* @type Date[]
*/
YAHOO.widget.Calendar_Core.prototype.getSelectedDates = function() {
var returnDates = new Array();
for (var d=0;d<this.selectedDates.length;++d)
{
var dateArray = this.selectedDates[d];
var date = new Date(dateArray[0],dateArray[1]-1,dateArray[2]);
returnDates.push(date);
}
returnDates.sort();
return returnDates;
};
/***************** END GETTER/SETTER METHODS *********************************/
YAHOO.widget.Calendar_Core._getBrowser = function()
{
/**
* UserAgent
* @private
* @type String
*/
var ua = navigator.userAgent.toLowerCase();
if (ua.indexOf('opera')!=-1) // Opera (check first in case of spoof)
return 'opera';
else if (ua.indexOf('msie')!=-1) // IE
return 'ie';
else if (ua.indexOf('safari')!=-1) // Safari (check before Gecko because it includes "like Gecko")
return 'safari';
else if (ua.indexOf('gecko') != -1) // Gecko
return 'gecko';
else
return false;
}
YAHOO.widget.Cal_Core = YAHOO.widget.Calendar_Core;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -