📄 calendar.lib.js
字号:
var curDate = new Date();
Y = typeof Y == 'undefined' ? curDate.getFullYear() : Y;
M = typeof M == 'undefined' ? curDate.getMonth() : M;
this.SetShowDate(Y, M);
this.ChangeWeekTitle(Y, M);
this.CreateWeekContent(Y, M);
//oNode.AddNode(this.container);
return this.container;
};
// change week title
Calendar.prototype.ChangeWeekTitle = function (Y, M) {
var curDate = new Date();
Y = parseInt(Y);
M = parseInt(M);
if (Y == 0)
Y = curDate.getFullYear();
if (M < 0 || M > 11)
M = curDate.getMonth();
var days = Calendar.Days;
if (M == 1) {
if ((Y % 400 == 0) || ((Y % 4 == 0) && (Y % 100 != 0)))
days[1] = 29;
else
days[1] = 28;
}
var navYearPrev = Y - 1;
var navYearNext = Y + 1;
var navMonthPrev = M - 1;
var navMonthPrevYear = 0;
if (navMonthPrev == -1) {
navMonthPrev = 11;
navMonthPrevYear = Y - 1;
}
else {
//navMonthPrev--;
navMonthPrevYear = Y;
}
var navMonthNext = M + 1;
var navMonthNextYear = 0;
if (navMonthNext == 12) {
navMonthNext = 0;
navMonthNextYear = Y + 1;
}
else {
//navMonthNext++;
navMonthNextYear = Y;
}
this.current.title = '当前日期:' + curDate.getFullYear() + '年' + (curDate.getMonth() + 1) + '月' + curDate.getDate() + '日';
this.current.innerHTML = Y + '年' + (M + 1) + '月';
if (!!this.isControl) {
this.upper.Y = navYearPrev;
this.upper.M = M;
this.up.Y = navMonthPrevYear;
this.up.M = navMonthPrev;
this.down.Y = navMonthNextYear;
this.down.M = navMonthNext;
this.downer.Y = navYearNext;
this.downer.M = M;
navMonthPrev++;
navMonthNext++;
this.upper.title = navYearPrev + '年';
this.up.title = (navMonthPrev == 12 ? navYearPrev + '年' + navMonthPrev : navMonthPrev) + '月';
this.down.title = (navMonthNext == 1 ? navYearNext + '年' + navMonthNext : navMonthNext) + '月';
this.downer.title = navYearNext + '年';
}
};
// change week content
Calendar.prototype.ChangeWeekContent = function (Y, M) {
this.CreateWeekContent(Y, M);
};
// create shortcut menu
Calendar.prototype.CreatShortCut = function () {
var self = this;
var c = this.shortCutContent;
if (! c) {
c = this.shortCutContent = oNode.CreateNode('div');
CSS.AddClass(c, this.css.shortcut);
c.style.position = 'absolute';
c.style.left = this.container.offsetWidth + 'px';
c.style.top = 0;
Events.AttachEvent(c, 'mouseover', function () {
clearTimeout(self.shortCut.timer);
self.SetVisible(true);
//CSS.SetDisplay(c, true);
});
Events.AttachEvent(c, 'mouseout', function () {
self.shortCut.timer = setTimeout(function(){
self.SetVisible(false);
//CSS.SetDisplay(c, false);
}, 1000);
});
this.CreateShortCutContent();
//
oNode.AddNode(c, this.shortCut);
PopUp.AddMask(c);
}
//this.shortCut.childNodes.length > 0 || oNode.AddNode(c, this.shortCut);
return c;
};
// 创建快捷选项内容
Calendar.prototype.CreateShortCutContent = function () {
var self = this;
var c = oNode.CreateNode('ul');
oNode.AddNode(c, this.shortCutContent);
CSS.AddClass(c, this.css.shortcut_title);
// year
var yc = oNode.CreateNode('li');
oNode.AddNode(yc, c);
var ycBut = oNode.CreateNode('a');
oNode.AddNode(ycBut, yc);
oNode.AddNode(oNode.CreateTextNode('年'), ycBut);
CSS.AddClass(ycBut, this.css.selected);
ycBut.href = '#';
Events.AttachEvent(ycBut, 'click', function (e, th) {
th = th || this;
CSS.RemoveClass(mcBut, self.css.selected);
CSS.ReplaceClass(th, self.css.unselected, self.css.selected);
CSS.SetDisplay(yCon, true);
CSS.SetDisplay(mCon, false);
Events.CancelEvent(e);
// resize
PopUp.ResetSize(self.shortCutContent);
});
// month
var mc = oNode.CreateNode('li');
oNode.AddNode(mc, c);
var mcBut = oNode.CreateNode('a');
oNode.AddNode(mcBut, mc);
oNode.AddNode(oNode.CreateTextNode('月'), mcBut);
CSS.AddClass(mcBut, this.css.unselected);
mcBut.href = '#';
Events.AttachEvent(mcBut, 'click', function (e, th) {
th = th || this;
CSS.RemoveClass(ycBut, self.css.selected);
CSS.ReplaceClass(th, self.css.unselected, self.css.selected);
CSS.SetDisplay(mCon, true);
CSS.SetDisplay(yCon, false);
Events.CancelEvent(e);
// resize
PopUp.ResetSize(self.shortCutContent);
});
// ie5.5 及下版本
var css_ie5 = Browser.IsIE5 ? this.css.shortcut_content_ie5 : '';
// year content
var yCon = this.yearContent = oNode.CreateNode('ul');
oNode.AddNode(yCon, this.shortCutContent);
CSS.AddClass(yCon, this.css.shortcut_content, css_ie5);
yCon.style.clear = 'both';
for (var i = 0; i < 100; i++) {
var li = oNode.CreateNode('li');
oNode.AddNode(li, yCon);
var a = oNode.CreateNode('a');
oNode.AddNode(a, li);
oNode.AddNode(oNode.CreateTextNode(i + this.yearStep), a);
a.href = '#';
Events.AttachEvent(a, 'click', function (e, th) {
th = th || this;
self.ChangeShortCutYear(th.innerHTML);
self.Create(th.innerHTML);
Events.CancelEvent(e);
});
if (self.selectedDate.getFullYear() == i + this.yearStep) {
CSS.AddClass(a, this.css.content_selected);
}
}
// month content
var mCon = this.monthContent = oNode.CreateNode('ul');
oNode.AddNode(mCon, this.shortCutContent);
CSS.AddClass(mCon, this.css.shortcut_content, css_ie5);
mCon.style.clear = 'both';
mCon.style.display = 'none';
for (var i = 1; i < 13; i++) {
var li = oNode.CreateNode('li');
oNode.AddNode(li, mCon);
var a = oNode.CreateNode('a');
oNode.AddNode(a, li);
oNode.AddNode(oNode.CreateTextNode(i + '月'), a);
a.M = i - 1;
a.href = '#';
Events.AttachEvent(a, 'click', function (e, th) {
th = th || this;
self.ChangeShortCutMonth(th.M);
self.Create(self.selectedDate.getFullYear(), th.M);
Events.CancelEvent(e);
});
if (self.selectedDate.getMonth() + 1 == i) {
CSS.AddClass(a, this.css.content_selected);
}
}
// clear float
var clear = oNode.CreateNode('div');
oNode.AddNode(clear, this.shortCutContent);
clear.style.clear = 'both';
};
// 改变快捷状态
Calendar.prototype.ChangeShortCutState = function (Y, M) {
this.ChangeShortCutYear(Y);
this.ChangeShortCutMonth(M);
};
// 改变年选择状态
Calendar.prototype.ChangeShortCutYear = function (selectedYear /* :Number */) {
try {
// selecte year
CSS.ReplaceClass(
this.yearContent.getElementsByTagName('li')[this.shortcutYear - this.yearStep].getElementsByTagName('a')[0],
this.css.content_selected,
this.css.content_unselected
);
}
catch (e) {}
try {
this.shortcutYear = selectedYear || this.selectedDate.getFullYear();
CSS.ReplaceClass(
this.yearContent.getElementsByTagName('li')[this.shortcutYear - this.yearStep].getElementsByTagName('a')[0],
this.css.content_unselected,
this.css.content_selected
);
}
catch (e) {}
};
// 改变月选择状态
Calendar.prototype.ChangeShortCutMonth = function (selectedMonth /* :Number */) {
try {
// selecte month
CSS.ReplaceClass(
this.monthContent.getElementsByTagName('li')[this.shortcutMonth].getElementsByTagName('a')[0],
this.css.content_selected,
this.css.content_unselected
);
this.shortcutMonth = typeof selectedMonth != 'undefined' ? selectedMonth : this.selectedDate.getMonth();
CSS.ReplaceClass(
this.monthContent.getElementsByTagName('li')[this.shortcutMonth].getElementsByTagName('a')[0],
this.css.content_unselected,
this.css.content_selected
);
}
catch (e) {}
};
// 隐藏快捷内容
Calendar.prototype.SetVisible = function (visible) {
this.shortCutContent
&& (this.shortCutContent.$BG ? PopUp.SetVisible(this.shortCutContent, visible)
: CSS.SetDisplay(this.shortCutContent, visible));
}
// 设置日历显示的年月
Calendar.prototype.SetShowDate = function (Y, M) {
this.showYear = Y;
this.showMonth = M;
};
// 设置样式
// style :
// 'calendar'|'control'|'upper'|'up'|'current'|'down'|
// 'downer'|'week'|'week_ie5'|'week_title'|'week_content'|
// 'current_day'|'over'|'out'
Calendar.prototype.SetStyle = function (style /* :String */, css /* :String */) {
if (typeof css != 'string') return;
this.css[style] = css;
};
// 显示日期内容改变
Calendar.prototype._ContentChange = function () {
this.ContentChange();
};
// 显示日期内容改变
Calendar.prototype.ContentChange = function () {
//PopUp.ResetSize
};
// 日期改变时执行
Calendar.prototype._Change = function (date /* :Date */) {
this.selectedDate = date;
this.Change(date);
};
// 日期改变时执行(为特定定义的特定的方法)
Calendar.prototype.Change = function (date /* :Date */) {
// 此方法由特定对象替换
alert(date);
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -