📄 ig_calendar.js
字号:
/*
Infragistics Calendar Script
Version 5.1.20051.37
js-version 1.1.20042.1035
Copyright (c) 2003-2005 Infragistics, Inc. All Rights Reserved.
*/
if(typeof igcal_all!="object")
var igcal_all=new Object();
// public: Obtains the Calendar object using its id
function igcal_getCalendarById(id, e)
{
var o,i1=-2;
if(e!=null)
{
while(true)
{
if(e==null) return null;
try{if(e.getAttribute!=null)id=e.getAttribute("calID");}catch(ex){}
if(!ig_csom.isEmpty(id)) break;
if(++i1>1)return null;
e=e.parentNode;
}
var ids=id.split(",");
if(ig_csom.isEmpty(ids))return null;
id=ids[0];
i1=(ids.length>1)?parseInt(ids[1]):-1;
}
if((o=igcal_all[id])==null)
for(var i in igcal_all)if((o=igcal_all[i])!=null)
if(o.ID==id || o.ID_==id || o.uniqueId==id)break;
else o=null;
if(o!=null && i1>-2)o.elemID=i1;
return o;
}
//
// private: all below
function igcal_init(id,dates,prop,str)
{
var elem=ig_csom.getElementById("igcal"+id);
if(ig_csom._skipNew || elem==null || ig_csom.isEmpty(prop)) return;
var o=new igcal_new(elem,id,dates,prop,str);
igcal_all[id]=o;
id=o.Events.initializeCalendar;
if(!ig_csom.isEmpty(id))o.fireEvt(o,id,null,false);
}
//
function igcal_new(elem,id,dates,prop,str)
{
this.valI=function(o,i){o=(o==null || o.length<=i)?null:o[i];return (o==null)?"":o;}
this.intI=function(o,i){return ig_csom.isEmpty(o=this.valI(o,i))?-1:parseInt(o);}
// init flag
this.elemID=-10;
this.ID=id;
if(id.indexOf("x_")==0)this.ID_=id.substring(1);
this.element=elem;
this.elemViewState=ig_csom.getElementById(id);
elem.setAttribute("calID",id);
this.viewState=new ig_xmlNode();
var sep=",";
var i,prop0=dates.split(sep);
this.nd=function(y,m,d)
{
d=new Date(y,--m,d);
if(y<100 && d.setFullYear!=null)d.setFullYear(y);
return d;
}
//
this.df=function(d,i)
{
if(i==0)return d.getFullYear();
if(i==1)return d.getMonth()+1;
return (i==2)?d.getDate():d.getDay();
}
this.Days = new Array(42);
var o = new Date();
this.today = new Array(3);
this.today[0] = this.df(o, 0);
this.today[1] = this.df(o, 1);
this.today[2] = this.df(o, 2);
//
this.selDate = new Array(4);
this.selDate[0] = this.intI(prop0, 0);
this.selDate[1] = this.intI(prop0, 1);
this.selDate[2] = this.intI(prop0, 2);
this.selDate[3] = -1;
var year = this.intI(prop0, 3), month = this.intI(prop0, 4);
this.MinDate = this.nd(this.intI(prop0, 5), this.intI(prop0, 6), this.intI(prop0, 7));
this.MaxDate = this.nd(this.intI(prop0, 8), this.intI(prop0, 9), this.intI(prop0, 10));
//
this.setText = function(e, t)
{
var ii = (e.childNodes == null) ? 0 : e.childNodes.length;
for(var i = -1; i < ii; i++)
{
var ei = (i < 0) ? e : e.childNodes[i];
if(ei.nodeName == "#text")
{
if(t != null){ei.nodeValue = t; t = null;}
else ei.nodeValue = "";
}
}
if(t == null) return;
if(e.text != null){e.text = t; return;}
if(e.innerText != null){e.innerText = t; return;}
if(e.innerHTML != null) e.innerHTML = t;
}
this.getText = function(e)
{
var ii = (e.childNodes == null) ? 0 : e.childNodes.length;
var v = null;
for(var i = -1; i < ii; i++)
{
var ei = (i < 0) ? e : e.childNodes[i];
if(ei.nodeName == "#text")
v = (v == null) ? ei.nodeValue : v + " " + ei.nodeValue1;
}
if(v != null) return v;
if((v = e.text) != null) return v;
if((v = e.innerText) != null) return v;
if((v = e.innerHTML) != null) return v;
return "";
}
//
this.doPost = function(type)
{
if(!this.post) return;
this.postSel = this.postVis = this.post = false;
if(type > 0) this.update(type);
try{if(document.activeElement != null) document.activeElement.fireEvent("onblur"); else window.blur();}catch(ex){}
try{__doPostBack(this.uniqueId, "");}catch(ex){}
}
this.buf = new Object();
this.fireEvt = function(o, evtName, e, del, sel)
{
var evt = this.Event;
if(evt == null) evt = this.Event = new ig_EventObject();
evt.reset();
evt.needPostBack = this.post;
if(e == null) o = evt = null;
else if(sel == null) evt.event = e;
else
{
this.buf.year = o.year;
this.buf.month = o.month;
this.buf.day = o.day;
this.buf.index = o.index;
this.buf.dow = (this.dow + (o.index % 7)) % 7;
this.buf.element = o.element;
this.buf.text = "" + o.day;
this.buf.css = e;
o = this.buf;
o.selected = sel;
}
ig_fireEvent(this, evtName, o, evt);
if(evt == null) return false;
this.post = (evt.needPostBack && !evt.cancelPostBack);
return evt.cancel;
}
//
this.isSelected = function(year, month, day, i)
{
if(this.selDate[0] == year && this.selDate[1] == month && this.selDate[2] == day)
{if(i >= 0) this.selDate[3] = i; return true;}
return false;
}
this.isSel = function(i){return this.selDate[3] == i;}
// already checked for old sel
this.select = function(year, month, day, date, toggle, i, e, add)
{
if(toggle == null)
{
this.selDate[0] = year;
this.selDate[1] = month;
this.selDate[2] = day;
this.selDate[3] = -1;
return;
}
var id = this.Events.valueChanging;
var del = (!toggle && date == null);
if(!ig_csom.isEmpty(id))
{
if(this.fireEvt(del ? this.nd(year, month, day) : date, id, e, del))
return;
this.doPost(0);
}
// unselect
id = this.Events.renderDay;
var o, text = null, sel = this.selDate[3];
if(sel >= 0)
{
o = this.Days[sel];
sel = this.ID + o.css;
if(id.length > 0)
{
if(this.fireEvt(o, id, sel, false, false)) o = null;
else
{
text = this.buf.text;
sel = this.buf.css;
}
}
if(o != null)
{
o.element.className = sel;
if(text != null) this.setText(o.element, text);
}
}
if(toggle){month = year = day = -1;}
this.selDate[0] = year;
this.selDate[1] = month;
this.selDate[2] = day;
this.selDate[3] = -1;
// select
if(!toggle)
{
// flag to calculate i
if(i < -1)
{
if(year != this.Days[15].year || month != this.Days[15].month)
{if(i < -2) this.repaint(year, month, false, e);}
else for(i = 41; i >= 0; i--)
if(year == this.Days[i].year && month == this.Days[i].month && day == this.Days[i].day)
break;
}
if(i > -2) if((this.selDate[3] = i) >= 0)
{
o = this.Days[i];
sel = this.ID + this.getCss(1);
text = null;
if(id.length > 0)
{
if(this.fireEvt(o, id, sel, false, true)) o = null;
else
{
text = this.buf.text;
sel = this.buf.css;
}
}
if(o != null)
{
o.element.className = sel;
if(text != null) this.setText(o.element, text);
}
}
}
this.update();
if(this.onValueChanged != null) this.onValueChanged(this, del ? this.nd(year, month, day) : date);
this.post = this.postSel;
if(!ig_csom.isEmpty(id = this.Events.valueChanged))
this.fireEvt(del ? this.nd(year, month, day) : date, id, e, del);
this.doPost(1);
//this.setFirstDayOfWeek(3);
//this.update("BackColor", "Red", "DayStyle");
}
//
prop0 = prop.split(sep);
this.uniqueId = prop0[0];
this.enabled = !ig_csom.isEmpty(prop0[1]);
this.allowNull = !ig_csom.isEmpty(prop0[2]);
this.readOnly = !ig_csom.isEmpty(prop0[3]);
this.titleFormat = prop0[4].replace(";", ",");
this.dow = this.intI(prop0, 5);
this.nextFormat = this.intI(prop0, 6);
this.fixVis = !ig_csom.isEmpty(prop0[7]);
this.postSel = !ig_csom.isEmpty(prop0[8]);
this.postVis = !ig_csom.isEmpty(prop0[9]);
this.DayNameFormat = this.intI(prop0, 10);
this.VisibleDayNames = this.intI(prop0, 11);
for(i = 12; i < 18; i++) if(!ig_csom.isEmpty(o = prop0[i]))
{if(this.css == null) this.css = new Array(6); this.css[i - 12] = " " + o;}
// DK Added for keyboardsupport
this.tabIndex = this.intI(prop0, 18);
this.getCss = function(i){return "" + i + this.valI(this.css, i);}
//
prop0 = ig_csom.isEmpty(str) ? null : str.split(sep);
this.info = new Object();
var aa = new Array(12);
for(i = 0; i < 12; i++) aa[i] = this.valI(prop0, i);
this.info.MonthNames = aa;
o = new Object();
o.initializeCalendar = this.valI(prop0, i);
o.dateClicked = this.valI(prop0, ++i);
o.monthChanged = this.valI(prop0, ++i);
o.monthChanging = this.valI(prop0, ++i);
o.valueChanged = this.valI(prop0, ++i);
o.valueChanging = this.valI(prop0, ++i);
o.renderDay = this.valI(prop0, ++i);
this.Events = o;
if(this.nextFormat > 0)
{
aa = new Array(12);
for(o = 0; o < 12; o++)
{
if(this.nextFormat != 1) aa[o] = this.info.MonthNames[o];
else if(ig_csom.isEmpty(aa[o] = this.valI(prop0, ++i)))
aa[o] = this.info.MonthNames[o].substring(0, 3);
}
this.info.AbbreviatedMonthNames = aa;
}
//
this.addLsnr = function(e, s)
{
if(e == null) return;
ig_csom.addEventListener(e, "select", ig_cancelEvent, false);
ig_csom.addEventListener(e, "selectstart", ig_cancelEvent, false);
if(s) return;
ig_csom.addEventListener(e, "mousedown", ig_cancelEvent, false);
ig_csom.addEventListener(e, "click", igcal_event, false);
}
this.addLsnr(elem, true);
if(igcal_all.unload != true){ig_csom.addEventListener(window, "unload", igcal_event); igcal_all.unload = true;}
//
// 0=500 - prevMonth
// 1=502 - nextMonth
// 2=504 - MonthDrop
// 3=506 - YearDrop
// 4=508 - Footer
// 5=510 - Title
// 6=512 - Calendar
// 7=514 - Dow
this.elems = new Array(8);
for(i = 0; i < 8; i++)
{
if((elem = ig_csom.getElementById(id + "_" + (500 + i * 2))) != null)
{
this.elems[i] = elem;
elem.setAttribute("calID", id + "," + (500 + i * 2));
if(i > 4) continue;
if(i == 2 || i == 3) ig_csom.addEventListener(elem, "change", igcal_event, false);
else this.addLsnr(elem, false);
/* what happens if i just added the event listner on the client? */
if (i<=4) ig_csom.addEventListener(elem, "keydown", igcal_event, false);
}
}
this.getCellSpacing = function(){return this.elems[6].cellSpacing;}
this.setCellSpacing = function(v){this.update("CellSpacing", this.elems[6].cellSpacing = v);}
this.getCellPadding = function(){return this.elems[6].cellPadding;}
this.setCellPadding = function(v){this.update("CellPadding", this.elems[6].cellPadding = v);}
this.getGridLineColor = function(){return this.elems[6].borderColor;}
this.setGridLineColor = function(v){this.update("GridLineColor", this.elems[6].borderColor = v);}
this.getShowGridLines = function()
{
var s = this.elems[6].rules;
if(s == "cols") return 1;
else if(s == "rows") return 2;
else if(s == "all") return 3;
return 0;
}
this.setShowGridLines = function(v)
{
var s = "none";
if(v == 1) s = "cols";
else if(v == 2) s = "rows";
else if(v == 3) s = "all";
else v = 0;
this.elems[6].border = (v == 0) ? 0 : 1;
this.elems[6].rules = s;
this.update("ShowGridLines", v);
}
this.ShowNextPrevMonth = this.elems[0] != null;
this.ShowTitle = this.elems[5] != null;
//
this.minMax = function(y, m, d)
{
m = this.nd(y, m, d);
d = m.getTime();
if(d > this.MaxDate.getTime()) return this.MaxDate;
if(d < this.MinDate.getTime()) return this.MinDate;
return null;
}
this.repaint = function(year, month, check, e)
{
var id = (year == null);
if(id || year < 1) year = this.Days[15].year;
if(month == null) month = this.Days[15].month;
if(check == null) check = false;
if(month < 1){month = 12; year--;}
if(month > 12){month -= 12; year++;}
var i, o, d = this.minMax(year, month, 1);
if(d != null){year = this.df(d, 0); month = this.df(d, 1);}
//
if(e != null && !ig_csom.isEmpty(o = this.Events.monthChanging))
{
if(this.fireEvt((d == null) ? this.nd(year, month, 1) : d, o, e, true))
{
if((o = this.elems[2]) != null) o.selectedIndex = this.Days[15].month - 1;
if((o = this.elems[3]) != null) o.selectedIndex = this.Days[15].year - this.year0;
return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -