📄 calendarbehavior.js
字号:
for (var i = 0; i < 7; i++) {
var dayCell = this._daysTableHeaderRow.cells[i].firstChild;
if (dayCell.firstChild) {
dayCell.removeChild(dayCell.firstChild);
}
dayCell.appendChild(document.createTextNode(dtf.ShortestDayNames[(i + firstDayOfWeek) % 7]));
}
for (var week = 0; week < 6; week ++) {
var weekRow = this._daysBody.rows[week];
for (var dayOfWeek = 0; dayOfWeek < 7; dayOfWeek++) {
var dayCell = weekRow.cells[dayOfWeek].firstChild;
if (dayCell.firstChild) {
dayCell.removeChild(dayCell.firstChild);
}
dayCell.appendChild(document.createTextNode(currentDate.getDate()));
dayCell.title = currentDate.localeFormat("D");
dayCell.date = currentDate;
$common.removeCssClasses(dayCell.parentNode, [ "ajax__calendar_other", "ajax__calendar_active" ]);
Sys.UI.DomElement.addCssClass(dayCell.parentNode, this._getCssClass(dayCell.date, 'd'));
currentDate = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate() + 1, this._hourOffsetForDst);
}
}
this._prevArrow.date = new Date(visibleDate.getFullYear(), visibleDate.getMonth() - 1, 1, this._hourOffsetForDst);
this._nextArrow.date = new Date(visibleDate.getFullYear(), visibleDate.getMonth() + 1, 1, this._hourOffsetForDst);
if (this._title.firstChild) {
this._title.removeChild(this._title.firstChild);
}
this._title.appendChild(document.createTextNode(visibleDate.localeFormat("MMMM, yyyy")));
this._title.date = visibleDate;
break;
case "months":
for (var i = 0; i < this._monthsBody.rows.length; i++) {
var row = this._monthsBody.rows[i];
for (var j = 0; j < row.cells.length; j++) {
var cell = row.cells[j].firstChild;
cell.date = new Date(visibleDate.getFullYear(), cell.month, 1, this._hourOffsetForDst);
cell.title = cell.date.localeFormat("Y");
$common.removeCssClasses(cell.parentNode, [ "ajax__calendar_other", "ajax__calendar_active" ]);
Sys.UI.DomElement.addCssClass(cell.parentNode, this._getCssClass(cell.date, 'M'));
}
}
if (this._title.firstChild) {
this._title.removeChild(this._title.firstChild);
}
this._title.appendChild(document.createTextNode(visibleDate.localeFormat("yyyy")));
this._title.date = visibleDate;
this._prevArrow.date = new Date(visibleDate.getFullYear() - 1, 0, 1, this._hourOffsetForDst);
this._nextArrow.date = new Date(visibleDate.getFullYear() + 1, 0, 1, this._hourOffsetForDst);
break;
case "years":
var minYear = (Math.floor(visibleDate.getFullYear() / 10) * 10);
for (var i = 0; i < this._yearsBody.rows.length; i++) {
var row = this._yearsBody.rows[i];
for (var j = 0; j < row.cells.length; j++) {
var cell = row.cells[j].firstChild;
cell.date = new Date(minYear + cell.year, 0, 1, this._hourOffsetForDst);
if (cell.firstChild) {
cell.removeChild(cell.lastChild);
} else {
cell.appendChild(document.createElement("br"));
}
cell.appendChild(document.createTextNode(minYear + cell.year));
$common.removeCssClasses(cell.parentNode, [ "ajax__calendar_other", "ajax__calendar_active" ]);
Sys.UI.DomElement.addCssClass(cell.parentNode, this._getCssClass(cell.date, 'y'));
}
}
if (this._title.firstChild) {
this._title.removeChild(this._title.firstChild);
}
this._title.appendChild(document.createTextNode(minYear.toString() + "-" + (minYear + 9).toString()));
this._title.date = visibleDate;
this._prevArrow.date = new Date(minYear - 10, 0, 1, this._hourOffsetForDst);
this._nextArrow.date = new Date(minYear + 10, 0, 1, this._hourOffsetForDst);
break;
}
if (this._today.firstChild) {
this._today.removeChild(this._today.firstChild);
}
this._today.appendChild(document.createTextNode(String.format(AjaxControlToolkit.Resources.Calendar_Today, todaysDate.localeFormat("MMMM d, yyyy"))));
this._today.date = todaysDate;
},
_ensureCalendar : function() {
if (!this._container) {
var elt = this.get_element();
this._buildCalendar();
this._buildHeader();
this._buildBody();
this._buildFooter();
this._popupBehavior = new $create(AjaxControlToolkit.PopupBehavior, { parentElement : elt }, {}, {}, this._popupDiv);
if (this._popupPosition == AjaxControlToolkit.CalendarPosition.TopLeft) {
this._popupBehavior.set_positioningMode(AjaxControlToolkit.PositioningMode.TopLeft);
} else if (this._popupPosition == AjaxControlToolkit.CalendarPosition.TopRight) {
this._popupBehavior.set_positioningMode(AjaxControlToolkit.PositioningMode.TopRight);
} else if (this._popupPosition == AjaxControlToolkit.CalendarPosition.BottomRight) {
this._popupBehavior.set_positioningMode(AjaxControlToolkit.PositioningMode.BottomRight);
} else if (this._popupPosition == AjaxControlToolkit.CalendarPosition.Right) {
this._popupBehavior.set_positioningMode(AjaxControlToolkit.PositioningMode.Right);
} else if (this._popupPosition == AjaxControlToolkit.CalendarPosition.Left) {
this._popupBehavior.set_positioningMode(AjaxControlToolkit.PositioningMode.Left);
} else {
this._popupBehavior.set_positioningMode(AjaxControlToolkit.PositioningMode.BottomLeft);
}
}
},
_fireChanged : function() {
/// <summary>
/// Attempts to fire the change event on the attached textbox
/// </summary>
var elt = this.get_element();
if (document.createEventObject) {
elt.fireEvent("onchange");
} else if (document.createEvent) {
var e = document.createEvent("HTMLEvents");
e.initEvent("change", true, true);
elt.dispatchEvent(e);
}
},
_switchMonth : function(date, dontAnimate) {
/// <summary>
/// Switches the visible month in the days view
/// </summary>
/// <param name="date" type="Date">The visible date to switch to</param>
/// <param name="dontAnimate" type="Boolean">Prevents animation from occuring if the control is animated</param>
// Check _isAnimating to make sure we don't animate horizontally and vertically at the same time
if (this._isAnimating) {
return;
}
var visibleDate = this._getEffectiveVisibleDate();
if ((date && date.getFullYear() == visibleDate.getFullYear() && date.getMonth() == visibleDate.getMonth())) {
dontAnimate = true;
}
if (this._animated && !dontAnimate) {
this._isAnimating = true;
var newElement = this._modes[this._mode];
var oldElement = newElement.cloneNode(true);
this._body.appendChild(oldElement);
if (visibleDate > date) {
// animating down
// the newIndex element is the top
// the oldIndex element is the bottom (visible)
// move in, fade in
$common.setLocation(newElement, {x:-162,y:0});
$common.setVisible(newElement, true);
this._modeChangeMoveTopOrLeftAnimation.set_propertyKey("left");
this._modeChangeMoveTopOrLeftAnimation.set_target(newElement);
this._modeChangeMoveTopOrLeftAnimation.set_startValue(-this._width);
this._modeChangeMoveTopOrLeftAnimation.set_endValue(0);
// move out, fade out
$common.setLocation(oldElement, {x:0,y:0});
$common.setVisible(oldElement, true);
this._modeChangeMoveBottomOrRightAnimation.set_propertyKey("left");
this._modeChangeMoveBottomOrRightAnimation.set_target(oldElement);
this._modeChangeMoveBottomOrRightAnimation.set_startValue(0);
this._modeChangeMoveBottomOrRightAnimation.set_endValue(this._width);
} else {
// animating up
// the oldIndex element is the top (visible)
// the newIndex element is the bottom
// move out, fade out
$common.setLocation(oldElement, {x:0,y:0});
$common.setVisible(oldElement, true);
this._modeChangeMoveTopOrLeftAnimation.set_propertyKey("left");
this._modeChangeMoveTopOrLeftAnimation.set_target(oldElement);
this._modeChangeMoveTopOrLeftAnimation.set_endValue(-this._width);
this._modeChangeMoveTopOrLeftAnimation.set_startValue(0);
// move in, fade in
$common.setLocation(newElement, {x:162,y:0});
$common.setVisible(newElement, true);
this._modeChangeMoveBottomOrRightAnimation.set_propertyKey("left");
this._modeChangeMoveBottomOrRightAnimation.set_target(newElement);
this._modeChangeMoveBottomOrRightAnimation.set_endValue(0);
this._modeChangeMoveBottomOrRightAnimation.set_startValue(this._width);
}
this._visibleDate = date;
this.invalidate();
var endHandler = Function.createDelegate(this, function() {
this._body.removeChild(oldElement);
oldElement = null;
this._isAnimating = false;
this._modeChangeAnimation.remove_ended(endHandler);
});
this._modeChangeAnimation.add_ended(endHandler);
this._modeChangeAnimation.play();
} else {
this._visibleDate = date;
this.invalidate();
}
},
_switchMode : function(mode, dontAnimate) {
/// <summary>
/// Switches the visible view from "days" to "months" to "years"
/// </summary>
/// <param name="mode" type="String">The view mode to switch to</param>
/// <param name="dontAnimate" type="Boolean">Prevents animation from occuring if the control is animated</param>
// Check _isAnimating to make sure we don't animate horizontally and vertically at the same time
if (this._isAnimating || (this._mode == mode)) {
return;
}
var moveDown = this._modeOrder[this._mode] < this._modeOrder[mode];
var oldElement = this._modes[this._mode];
var newElement = this._modes[mode];
this._mode = mode;
if (this._animated && !dontAnimate) {
this._isAnimating = true;
this.invalidate();
if (moveDown) {
// animating down
// the newIndex element is the top
// the oldIndex element is the bottom (visible)
// move in, fade in
$common.setLocation(newElement, {x:0,y:-this._height});
$common.setVisible(newElement, true);
this._modeChangeMoveTopOrLeftAnimation.set_propertyKey("top");
this._modeChangeMoveTopOrLeftAnimation.set_target(newElement);
this._modeChangeMoveTopOrLeftAnimation.set_startValue(-this._height);
this._modeChangeMoveTopOrLeftAnimation.set_endValue(0);
// move out, fade out
$common.setLocation(oldElement, {x:0,y:0});
$common.setVisible(oldElement, true);
this._modeChangeMoveBottomOrRightAnimation.set_propertyKey("top");
this._modeChangeMoveBottomOrRightAnimation.set_target(oldElement);
this._modeChangeMoveBottomOrRightAnimation.set_startValue(0);
this._modeChangeMoveBottomOrRightAnimation.set_endValue(this._height);
} else {
// animating up
// the oldIndex element is the top (visible)
// the newIndex element is the bottom
// move out, fade out
$common.setLocation(oldElement, {x:0,y:0});
$common.setVisible(oldElement, true);
this._modeChangeMoveTopOrLeftAnimation.set_propertyKey("top");
this._modeChangeMoveTopOrLeftAnimation.set_target(oldElement);
this._modeChangeMoveTopOrLeftAnimation.set_endValue(-this._height);
this._modeChangeMoveTopOrLeftAnimation.set_startValue(0);
// move in, fade in
$common.setLocation(newElement, {x:0,y:139});
$common.setVisible(newElement, true);
this._modeChangeMoveBottomOrRightAnimation.set_propertyKey("top");
this._modeChangeMoveBottomOrRightAnimation.set_target(newElement);
this._modeChangeMoveBottomOrRightAnimation.set_endValue(0);
this._modeChangeMoveBottomOrRightAnimation.set_startValue(this._height);
}
var endHandler = Function.createDelegate(this, function() {
this._isAnimating = false;
this._modeChangeAnimation.remove_ended(endHandler);
});
this._modeChangeAnimation.add_ended(endHandler);
this._modeChangeAnimation.play();
} else {
this._mode = mode;
$common.setVisible(oldElement, false);
this.invalidate();
$common.setVisible(newElement, true);
$common.setLocation(newElement, {x:0,y:0});
}
},
_isSelected : function(date, part) {
/// <summary>
/// Gets whether the supplied date is the currently selected date
/// </summary>
/// <param name="date" type="Date">The date to match</param>
/// <param name="part" type="String">The most significant part of the date to test</param>
/// <returns type="Boolean" />
var value = this.get_selectedDate();
if (!value) return false;
switch (part) {
case 'd':
if (date.getDate() != value.getDate()) return false;
// goto case 'M';
case 'M':
if (date.getMonth() != value.getMonth()) return false;
// goto case 'y';
case 'y':
if (date.getFullYear() != value.getFullYear()) return false;
break;
}
return true;
},
_isOther : function(date, part) {
/// <summary>
/// Gets whether the supplied date is in a different view from the current visible month
/// </summary>
/// <param name="date" type="Date">The date to match</param>
/// <param name="part" type="String">The most significant part of the date to test</param>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -