📄 ig_calendar.js
字号:
}
this.doPost(0);
}
//
if((o = this.elems[2]) != null) o.selectedIndex = month - 1;
if((o = this.elems[3]) != null) if(this.year0 == null) if((d = o.options) != null)
if((d = d[0]) != null) try{this.year0 = parseInt(this.getText(d));}catch(ex){}
if(this.year0 != null)
{
i = o.options.length;
var y = year - (i >> 1);
d = this.df(this.MinDate, 0);
if(y < d) y = d;
else if(y + i > (d = this.df(this.MaxDate, 0))) y = d - i + 1;
if(this.year0 != y)
{
while(i-- > 0)
{
d = (y + i > 999) ? "" : ((y + i > 99) ? "0" : "00");
this.setText(o.options[i], d + (y + i));
}
o.selectedIndex = -1;
}
o.selectedIndex = year - (this.year0 = y);
}
//
if((o = this.Days[15]) != null)
{
if(o.year == year && o.month == month){if(check) return;}
else check = true;
}
else check = false;
//
var numDays = (month == 2) ? 28 : 30;
d = this.nd(year, month, numDays + 1);
if(this.df(d, 1) == month) numDays++;
d = this.nd(year, month, 1);
i = this.df(d, 3) - this.dow;
var day1 = (i < 0) ? i + 7 : i;
// after init
if(this.elemID > -10)
{
if(this.nextFormat > 0)
{
o = this.info.AbbreviatedMonthNames;
this.setText(this.elems[1], o[(month + 12) % 12]);
this.setText(this.elems[0], o[(month + 10) % 12]);
}
if(this.elems[5] != null && (id || this.Days[15].month != month || this.Days[15].year != year))
{
d = (year < 1000) ? ((year < 100) ? "00" : "0") : "";
o = this.titleFormat.replace("#", d + year).replace("%%", this.info.MonthNames[month - 1]).replace("%", "" + month);
this.setText(this.elems[5], o);
}
}
id = this.Events.renderDay;
d = this.nd(year, month, 0);
var day0 = this.df(d, 2) - day1 + 1;
this.selDate[3] = -1;
var sun = (7 - this.dow) % 7;
for(i = 0; i < 42; i++)
{
// init
if(this.elemID == -10)
{
var elem = null;
if((elem = ig_csom.getElementById(this.ID + "_d" + i)) == null) continue;
elem.setAttribute("calID", this.ID + "," + i);
this.addLsnr(elem, false);
o = this.Days[i] = new Object();
o.element = elem;
o.calendar = this;
o.index = i;
}
else o = this.Days[i];
o.year = year;
o.month = month;
if(i < day1)
{
o.day = day0 + i;
if(--o.month < 1){o.month = 12; o.year--;}
o.css = this.getCss((i % 7 == sun || i % 7 == (sun + 6) % 7) ? 3 : 2);
}
else if(i < day1 + numDays)
{
o.day = i - day1 + 1;
o.css = this.getCss((i % 7 == sun || i % 7 == (sun + 6) % 7) ? 4 : 0);
}
else
{
o.day = i + 1 - (day1 + numDays);
if(++o.month > 12){o.month = 1; o.year++;}
o.css = this.getCss((i % 7 == sun || i % 7 == (sun + 6) % 7) ? 3 : 2);
}
if(o.day == this.today[2] && o.month == this.today[1] && o.year == this.today[0])
o.css = this.getCss(5);
var text = o.day, sel = this.isSelected(o.year, o.month, o.day, i);
d = this.ID + (sel ? this.getCss(1) : o.css);
if(id.length > 0)
{
if(this.fireEvt(o, id, d, false, sel)) continue;
o = this.buf;
d = this.buf.css;
text = this.buf.text;
}
// init
else if(this.elemID == -10) continue;
o.element.className = d;
this.setText(o.element, text);
/* try using calendar repainting to clear any lingering tabIndex*/
if (this.tabIndex>-1) o.element.tabIndex = sel ? this.tabIndex : -1;
}
if(this.elemID != -10) this.update();
if(!check || e == null) return;
this.post = this.postVis;
if(!ig_csom.isEmpty(o = this.Events.monthChanged))
this.fireEvt(this.nd(year, month, 1), o, e, true);
this.doPost(2);
}
this.repaint(year, month);
this.keydownHandler=function(e)
{
/* sanity checks*/
if (!e) return;
var o = e.srcElement;
if(o == null) if((o = e.target) == null) o = this;
/*determine if it comes from one of the buttons*/
o = igcal_getCalendarById(null, o);
if (32==e.keyCode && (this.elemID==500||this.elemID==502||this.elemID==504||this.elemID==506||this.elemID==508))
if(o != null) o.click(e);
}
this.click = function(e)
{
if(this.element.disabled) return;
var o = this.Days[15];
var y = o.year, m = o.month;
var id = this.elemID;
// drop
if(id == 504 || id == 506)
{
if(id == 504) m = this.elems[2].selectedIndex + 1;
else
{
if((y = this.year0) == null) return;
y += this.elems[3].selectedIndex;
}
this.repaint(y, m, true, e);
return;
}
// cal
if(id < 0) return;
// prev/next
if(id >= 500 && id <= 502) this.repaint(y, m + id - 501, true, e);
if(this.readOnly) return;
// -3 - request to scroll vis month
var d, i = -3, toggle = e.ctrlKey;
// today
if(id == 508){y = this.today[0]; m = this.today[1]; d = this.today[2]; toggle = false;}
else
{
if(id >= 42) return;
// days
o = this.Days[id];
id = this.Events.dateClicked;
y = o.year; m = o.month; d = o.day;
if(!ig_csom.isEmpty(id)) this.fireEvt(this.nd(y, m, d), id, e, true);
this.doPost(0);
if(this.isSel(o.index)){if(!toggle && this.ID.indexOf("_DrpPnl_Calendar1") < 2) return;}
else toggle = false;
if(!this.fixVis || this.Days[15].month == m) i = o.index;
}
if(this.minMax(y, m, d) != null) return;
this.select(y, m, d, null, this.allowNull && toggle, i, e, false);
}
// end init
this.elemID = -1;
// public: all methods below
this.getVisibleMonth = function(){return this.nd(this.Days[15].year, this.Days[15].month, 1);}
this.setVisibleMonth = function(d){if(d != null) this.repaint(this.df(d, 0), this.df(d, 1), true);}
this.getSelectedDate = function()
{return (this.selDate[2] < 0) ? null : this.nd(this.selDate[0], this.selDate[1], this.selDate[2]);}
this.setSelectedDate = function(date)
{
var y = -1, m = -1, d = -1;
if(date != null){y = this.df(date, 0); m = this.df(date, 1); d = this.df(date, 2);}
else if(!this.allowNull){y = this.today[0]; m = this.today[1]; d = this.today[2];}
if(this.isSelected(y, m, d, -1)) return;
if(d > 0) date = this.minMax(y, m, d);
if(date != null)
{
if(date != null){y = this.df(date, 0); m = this.df(date, 1); d = this.df(date, 2);}
if(this.isSelected(y, m, d, -1)) return;
}
this.select(y, m, d, date, d < 1, -3, null, false);
// this.select(y, m, d, date, false, show ? -3 : -2, null, false);
}
this.getFirstDayOfWeek = function(){return this.dow;}
this.setFirstDayOfWeek = function(v)
{
if(v == null) return;
v = (v + 7) % 7;
if(v == this.dow || v < 0) return;
var i = -1, x = (v + 7 - this.dow) % 7, old = new Array(7);
while(++i < 7) old[i] = this.getText(this.elems[7].cells[i]);
while(--i >= 0) this.setText(this.elems[7].cells[i], old[(i + x) % 7]);
this.dow = v;
this.repaint();
this.update("FirstDayOfWeek", v);
}
this.update = function(p, v, p0)
{
if(this.elemViewState == null) return "";
var n = this.viewState.addNode("x", true);
if(p == null || p.length == null)
{
v = this.Days[15].year + "x" + this.Days[15].month + "x" + this.selDate[0] + "x" + this.selDate[1] + "x" + this.selDate[2];
if(p != null) v += "x" + p;
p = "PostData";
}
else
{
n = n.addNode("LAYOUT", true);
if(p0 != null) n = n.addNode(p0);
}
n.setPropertyValue(p, v);
return this.elemViewState.value = this.viewState.getText();
}
// prviate
this.balanceTabIndex = function(e, oldItem, newItem, bFocus)
{
if (!e && !oldItem && !newItem) return true;
if(newItem)
{
if (this.IsTabableObject(newItem))
{
newItem.tabIndex = this.tabIndex;
if(bFocus)
try
{
newItem.focus();
}
catch(e)
{}
}
else return false;
}
if (oldItem)
{
oldItem.tabIndex = -1;
}
return true;
}
this.getDateInfo = function(){return this.info;}
//
this.rect = function(o, s)
{
if(s == 0)//w
{
if((s = o.offsetWidth) != null) return s;
return ((s = o.style.pixelWidth) != null) ? s : -10000;
}
if(s == 1)//h
{
if((s = o.offsetHeight) != null) return s;
return ((s = o.style.pixelHeight) != null) ? s : -10000;
}
if(s == 2)//x
{
if((s = o.offsetLeft) != null) return s;
return ((s = o.style.pixelLeft) != null) ? s : -10000;
}
if(s == 3)//y
{
if((s = o.offsetTop) != null) return s;
return ((s = o.style.pixelTop) != null) ? s : -10000;
}
}
// private
// scans through currently existing cells to determine if the date you are looking for is
// available in the current collection
this.getDateCellObject = function(dateValue)
{
if(!dateValue) return;
var iDay = dateValue.getDate();
var iMonth = dateValue.getMonth()+1;
var iYear = dateValue.getYear();
var iDateClean = new Date(iYear,iMonth,iDay);
var iCalVisMinDate = new Date(this.Days[0].year,this.Days[0].month,this.Days[0].day);
var iCalVisMaxDate = new Date(this.Days[41].year,this.Days[41].month,this.Days[41].day);
if (!(iDateClean>=iCalVisMinDate && iDateClean<=iCalVisMaxDate)) return null;
var oDay = null;
for (var i = this.Days.length - 1 ; i>=0 ; i--)
{
oDay=this.Days[i];
if (iDay==oDay.day && iMonth==oDay.month && iYear==oDay.year) return oDay.element;
}
return null;
}
this.IsTabableObject=function(elem){return true;}
// private
this.setDefaultTabableDateCell = function(focus)
{
if (this.tabIndex<0) return;
var initalDate = this.getSelectedDate();
var oCalElm = this.getDateCellObject(initalDate);
if (!oCalElm || !this.balanceTabIndex(null, null,oCalElm,focus))
{
oCalElm = this.getDateCellObject(new Date());
if (!oCalElm || !this.balanceTabIndex(null, null,oCalElm,focus))
for (var i=0;i<this.Days.length;i++)
if (this.balanceTabIndex(null, null,this.Days[i].Element,focus))
break;
}
}
if (this.tabIndex>-1) this.setDefaultTabableDateCell(false);
}
//
function igcal_event(e)
{
if(e == null) if((e = window.event) == null) return;
var o = e.srcElement;
if(o == null) if((o = e.target) == null) o = this;
// added for keyboard support
var k = e.type == "keydown";
if(!k) if(e.type != "change") if(e.button > 1 || e.shiftKey || e.altKey) return;
if(e.type == "unload") ig_dispose(igcal_all);
if((o = igcal_getCalendarById(null, o)) != null)
if(o.click != null)
if(k) o.keydownHandler(e);
else o.click(e);
}
function igcal_kbKD(e)
{
var oWC = igcal_getCalendarById(null,e.srcElement);
if (!oWC) return;
var oldId = e.srcElement.id;
var y = oWC.Days[oWC.elemID].year;
var m = oWC.Days[oWC.elemID].month;
var d = oWC.Days[oWC.elemID].day;
switch(e.keyCode)
{
case 40:// arrow down
if (oWC.elemID<35)
oWC.balanceTabIndex(e,e.srcElement, ig_csom.getElementById(oWC.ID + "_d" + (oWC.elemID+7)),true);
break;
case 39:// arrow right
if (oWC.elemID<41)
oWC.balanceTabIndex(e,e.srcElement, ig_csom.getElementById(oWC.ID + "_d" + (oWC.elemID+1)),true);
else
{
if(oWC.minMax(y, m, d+1) != null) return;
oWC.repaint(y, m, true, e);
oWC.balanceTabIndex(e,e.srcElement,ig_csom.getElementById(oWC.ID + "_d0"),true);
}
break;
case 38:// arrow up
if (oWC.elemID>6)
oWC.balanceTabIndex(e,e.srcElement, ig_csom.getElementById(oWC.ID + "_d" + (oWC.elemID-7)),true);
break;
case 37:// arrow left
if (oWC.elemID>0)
oWC.balanceTabIndex(e,e.srcElement, ig_csom.getElementById(oWC.ID + "_d" + (oWC.elemID-1)),true);
else
{
if(oWC.minMax(y, m, d-1) != null) return;
oWC.repaint(y, m, true, e);
oWC.balanceTabIndex(e,e.srcElement,ig_csom.getElementById(oWC.ID + "_d41"),true);
}
break;
case 32:
var oDate = new Date(oWC.Days[oWC.elemID].year,oWC.Days[oWC.elemID].month-1, oWC.Days[oWC.elemID].day);
oWC.balanceTabIndex(e,e.srcElement,null,false);
oWC.setSelectedDate(oDate);
oDate = oWC.getDateCellObject(oWC.getSelectedDate());
oWC.balanceTabIndex(e,null,oDate,true);
break;
default:
break;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -