📄 calendar.js
字号:
Config : null,
/**
* The parent CalendarGroup, only to be set explicitly by the parent group
* @type CalendarGroup
*/
parent : null,
/**
* The index of this item in the parent group
* @type Integer
*/
index : -1,
/**
* The collection of calendar table cells
* @type HTMLTableCellElement[]
*/
cells : null,
/**
* The collection of calendar week header cells
* @type HTMLTableCellElement[]
*/
weekHeaderCells : null,
/**
* The collection of calendar week footer cells
* @type HTMLTableCellElement[]
*/
weekFooterCells : null,
/**
* The collection of calendar cell dates that is parallel to the cells collection. The array contains dates field arrays in the format of [YYYY, M, D].
* @type Array[](Integer[])
*/
cellDates : null,
/**
* The id that uniquely identifies this calendar. This id should match the id of the placeholder element on the page.
* @type String
*/
id : null,
/**
* The DOM element reference that points to this calendar's container element. The calendar will be inserted into this element when the shell is rendered.
* @type HTMLElement
*/
oDomContainer : null,
/**
* A Date object representing today's date.
* @type Date
*/
today : null,
/**
* The list of render functions, along with required parameters, used to render cells.
* @type Array[]
*/
renderStack : null,
/**
* A copy of the initial render functions created before rendering.
* @type Array
* @private
*/
_renderStack : null,
/**
* A Date object representing the month/year that the calendar is currently set to
* @type Date
*/
pageDate : null,
/**
* A Date object representing the month/year that the calendar is initially set to
* @type Date
* @private
*/
_pageDate : null,
/**
* A Date object representing the minimum selectable date
* @type Date
*/
minDate : null,
/**
* A Date object representing the maximum selectable date
* @type Date
*/
maxDate : null,
/**
* The list of currently selected dates. The data format for this local collection is
* an array of date field arrays, e.g:
* [
* [2004,5,25],
* [2004,5,26]
* ]
* @type Array[](Integer[])
*/
selectedDates : null,
/**
* The private list of initially selected dates.
* @type Array
* @private
*/
_selectedDates : null,
/**
* A boolean indicating whether the shell of the calendar has already been rendered to the page
* @type Boolean
*/
shellRendered : false,
/**
* The HTML table element that represents this calendar
* @type HTMLTableElement
*/
table : null,
/**
* The HTML cell element that represents the main header cell TH used in the calendar table
* @type HTMLTableCellElement
*/
headerCell : null
};
/**
* Initializes the calendar widget. This method must be called by all subclass constructors.
* @param {String} id The id of the table element that will represent the calendar widget
* @param {String} containerId The id of the container element that will contain the calendar table
* @param {String} monthyear The month/year string used to set the current calendar page
* @param {String} selected A string of date values formatted using the date parser. The built-in
default date format is MM/DD/YYYY. Ranges are defined using
MM/DD/YYYY-MM/DD/YYYY. Month/day combinations are defined using MM/DD.
Any combination of these can be combined by delimiting the string with
commas. Example: "12/24/2005,12/25,1/18/2006-1/21/2006"
*/
YAHOO.widget.Calendar_Core.prototype.init = function(id, containerId, monthyear, selected) {
this.setupConfig();
this.id = id;
this.cellDates = new Array();
this.cells = new Array();
this.renderStack = new Array();
this._renderStack = new Array();
this.oDomContainer = document.getElementById(containerId);
this.today = new Date();
YAHOO.widget.DateMath.clearTime(this.today);
var month;
var year;
if (monthyear) {
var aMonthYear = monthyear.split(this.Locale.DATE_FIELD_DELIMITER);
month = parseInt(aMonthYear[this.Locale.MY_MONTH_POSITION-1]);
year = parseInt(aMonthYear[this.Locale.MY_YEAR_POSITION-1]);
} else {
month = this.today.getMonth()+1;
year = this.today.getFullYear();
}
this.pageDate = new Date(year, month-1, 1);
this._pageDate = new Date(this.pageDate.getTime());
if (selected) {
this.selectedDates = this._parseDates(selected);
this._selectedDates = this.selectedDates.concat();
} else {
this.selectedDates = new Array();
this._selectedDates = new Array();
}
this.wireDefaultEvents();
this.wireCustomEvents();
};
/**
* Wires the local DOM events for the Calendar, including cell selection, hover, and
* default navigation that is used for moving back and forth between calendar pages.
*/
YAHOO.widget.Calendar_Core.prototype.wireDefaultEvents = function() {
/**
* The default event function that is attached to a date link within a calendar cell
* when the calendar is rendered.
* @param e The event
* @param cal A reference to the calendar passed by the Event utility
*/
this.doSelectCell = function(e, cal) {
var cell = this;
var index = cell.index;
var d = cal.cellDates[index];
var date = new Date(d[0],d[1]-1,d[2]);
if (! cal.isDateOOM(date) && ! YAHOO.util.Dom.hasClass(cell, cal.Style.CSS_CELL_RESTRICTED) && ! YAHOO.util.Dom.hasClass(cell, cal.Style.CSS_CELL_OOB)) {
if (cal.Options.MULTI_SELECT) {
var link = cell.getElementsByTagName("A")[0];
link.blur();
var cellDate = cal.cellDates[index];
var cellDateIndex = cal._indexOfSelectedFieldArray(cellDate);
if (cellDateIndex > -1) {
cal.deselectCell(index);
} else {
cal.selectCell(index);
}
} else {
var link = cell.getElementsByTagName("A")[0];
link.blur()
cal.selectCell(index);
}
}
}
/**
* The event that is executed when the user hovers over a cell
* @param e The event
* @param cal A reference to the calendar passed by the Event utility
* @private
*/
this.doCellMouseOver = function(e, cal) {
var cell = this;
var index = cell.index;
var d = cal.cellDates[index];
var date = new Date(d[0],d[1]-1,d[2]);
if (! cal.isDateOOM(date) && ! YAHOO.util.Dom.hasClass(cell, cal.Style.CSS_CELL_RESTRICTED) && ! YAHOO.util.Dom.hasClass(cell, cal.Style.CSS_CELL_OOB)) {
YAHOO.util.Dom.addClass(cell, cal.Style.CSS_CELL_HOVER);
}
}
/**
* The event that is executed when the user moves the mouse out of a cell
* @param e The event
* @param cal A reference to the calendar passed by the Event utility
* @private
*/
this.doCellMouseOut = function(e, cal) {
YAHOO.util.Dom.removeClass(this, cal.Style.CSS_CELL_HOVER);
}
/**
* A wrapper event that executes the nextMonth method through a DOM event
* @param e The event
* @param cal A reference to the calendar passed by the Event utility
* @private
*/
this.doNextMonth = function(e, cal) {
cal.nextMonth();
}
/**
* A wrapper event that executes the previousMonth method through a DOM event
* @param e The event
* @param cal A reference to the calendar passed by the Event utility
* @private
*/
this.doPreviousMonth = function(e, cal) {
cal.previousMonth();
}
}
/**
* This function can be extended by subclasses to attach additional DOM events to
* the calendar. By default, this method is unimplemented.
*/
YAHOO.widget.Calendar_Core.prototype.wireCustomEvents = function() { }
/**
This method is called to initialize the widget configuration variables, including
style, localization, and other display and behavioral options.
<p>Config: Container for the CSS style configuration variables.</p>
<p><strong>Config.Style</strong> - Defines the CSS classes used for different calendar elements</p>
<blockquote>
<div><em>CSS_CALENDAR</em> : Container table</div>
<div><em>CSS_HEADER</em> : </div>
<div><em>CSS_HEADER_TEXT</em> : Calendar header</div>
<div><em>CSS_FOOTER</em> : Calendar footer</div>
<div><em>CSS_CELL</em> : Calendar day cell</div>
<div><em>CSS_CELL_OOM</em> : Calendar OOM (out of month) cell</div>
<div><em>CSS_CELL_SELECTED</em> : Calendar selected cell</div>
<div><em>CSS_CELL_RESTRICTED</em> : Calendar restricted cell</div>
<div><em>CSS_CELL_TODAY</em> : Calendar cell for today's date</div>
<div><em>CSS_ROW_HEADER</em> : The cell preceding a row (used for week number by default)</div>
<div><em>CSS_ROW_FOOTER</em> : The cell following a row (not implemented by default)</div>
<div><em>CSS_WEEKDAY_CELL</em> : The cells used for labeling weekdays</div>
<div><em>CSS_WEEKDAY_ROW</em> : The row containing the weekday label cells</div>
<div><em>CSS_CONTAINER</em> : The border style used for the default UED rendering</div>
<div><em>CSS_2UPWRAPPER</em> : Special container class used to properly adjust the sizing and float</div>
<div><em>CSS_NAV_LEFT</em> : Left navigation arrow</div>
<div><em>CSS_NAV_RIGHT</em> : Right navigation arrow</div>
<div><em>CSS_CELL_TOP</em> : Outlying cell along the top row</div>
<div><em>CSS_CELL_LEFT</em> : Outlying cell along the left row</div>
<div><em>CSS_CELL_RIGHT</em> : Outlying cell along the right row</div>
<div><em>CSS_CELL_BOTTOM</em> : Outlying cell along the bottom row</div>
<div><em>CSS_CELL_HOVER</em> : Cell hover style</div>
<div><em>CSS_CELL_HIGHLIGHT1</em> : Highlight color 1 for styling cells</div>
<div><em>CSS_CELL_HIGHLIGHT2</em> : Highlight color 2 for styling cells</div>
<div><em>CSS_CELL_HIGHLIGHT3</em> : Highlight color 3 for styling cells</div>
<div><em>CSS_CELL_HIGHLIGHT4</em> : Highlight color 4 for styling cells</div>
</blockquote>
<p><strong>Config.Locale</strong> - Defines the locale string arrays used for localization</p>
<blockquote>
<div><em>MONTHS_SHORT</em> : Array of 12 months in short format ("Jan", "Feb", etc.)</div>
<div><em>MONTHS_LONG</em> : Array of 12 months in short format ("Jan", "Feb", etc.)</div>
<div><em>WEEKDAYS_1CHAR</em> : Array of 7 days in 1-character format ("S", "M", etc.)</div>
<div><em>WEEKDAYS_SHORT</em> : Array of 7 days in short format ("Su", "Mo", etc.)</div>
<div><em>WEEKDAYS_MEDIUM</em> : Array of 7 days in medium format ("Sun", "Mon", etc.)</div>
<div><em>WEEKDAYS_LONG</em> : Array of 7 days in long format ("Sunday", "Monday", etc.)</div>
<div><em>DATE_DELIMITER</em> : The value used to delimit series of multiple dates (Default: ",")</div>
<div><em>DATE_FIELD_DELIMITER</em> : The value used to delimit date fields (Default: "/")</div>
<div><em>DATE_RANGE_DELIMITER</em> : The value used to delimit date fields (Default: "-")</div>
<div><em>MY_MONTH_POSITION</em> : The value used to determine the position of the month in a month/year combo (e.g. 12/2005) (Default: 1)</div>
<div><em>MY_YEAR_POSITION</em> : The value used to determine the position of the year in a month/year combo (e.g. 12/2005) (Default: 2)</div>
<div><em>MD_MONTH_POSITION</em> : The value used to determine the position of the month in a month/day combo (e.g. 12/25) (Default: 1)</div>
<div><em>MD_DAY_POSITION</em> : The value used to determine the position of the day in a month/day combo (e.g. 12/25) (Default: 2)</div>
<div><em>MDY_MONTH_POSITION</em> : The value used to determine the position of the month in a month/day/year combo (e.g. 12/25/2005) (Default: 1)</div>
<div><em>MDY_DAY_POSITION</em> : The value used to determine the position of the day in a month/day/year combo (e.g. 12/25/2005) (Default: 2)</div>
<div><em>MDY_YEAR_POSITION</em> : The value used to determine the position of the year in a month/day/year combo (e.g. 12/25/2005) (Default: 3)</div>
</blockquote>
<p><strong>Config.Options</strong> - Defines other configurable calendar widget options</p>
<blockquote>
<div><em>SHOW_WEEKDAYS</em> : Boolean, determines whether to display the weekday headers (defaults to true)</div>
<div><em>LOCALE_MONTHS</em> : Array, points to the desired Config.Locale array (defaults to Config.Locale.MONTHS_LONG)</div>
<div><em>LOCALE_WEEKDAYS</em> : Array, points to the desired Config.Locale array (defaults to Config.Locale.WEEKDAYS_SHORT)</div>
<div><em>START_WEEKDAY</em> : Integer, 0-6, representing the day that a week begins on</div>
<div><em>SHOW_WEEK_HEADER</em> : Boolean, determines whether to display row headers</div>
<div><em>SHOW_WEEK_FOOTER</em> : Boolean, determines whether to display row footers</div>
<div><em>HIDE_BLANK_WEEKS</em> : Boolean, determines whether to hide extra weeks that are completely OOM</div>
<div><em>NAV_ARROW_LEFT</em> : String, the image path used for the left navigation arrow</div>
<div><em>NAV_ARROW_RIGHT</em> : String, the image path used for the right navigation arrow</div>
</blockquote>
*/
YAHOO.widget.Calendar_Core.prototype.setupConfig = function() {
/**
* Container for the CSS style configuration variables.
*/
this.Config = new Object();
this.Config.Style = {
// Style variables
CSS_ROW_HEADER: "calrowhead",
CSS_ROW_FOOTER: "calrowfoot",
CSS_CELL : "calcell",
CSS_CELL_SELECTED : "selected",
CSS_CELL_RESTRICTED : "restricted",
CSS_CELL_TODAY : "today",
CSS_CELL_OOM : "oom",
CSS_CELL_OOB : "previous",
CSS_HEADER : "calheader",
CSS_HEADER_TEXT : "calhead",
CSS_WEEKDAY_CELL : "calweekdaycell",
CSS_WEEKDAY_ROW : "calweekdayrow",
CSS_FOOTER : "calfoot",
CSS_CALENDAR : "yui-calendar",
CSS_CONTAINER : "yui-calcontainer",
CSS_2UPWRAPPER : "yui-cal2upwrapper",
CSS_NAV_LEFT : "calnavleft",
CSS_NAV_RIGHT : "calnavright",
CSS_CELL_TOP : "calcelltop",
CSS_CELL_LEFT : "calcellleft",
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -