//---------------------------------------------------------------- // HTML Component : Calendar with date mark(带时间标注的日历控件) // // Version : 1.0 // // Request : Microsoft IE 5 or up // // Author : JoJo // // Last Realse : 5/9/2001 // // Copyright : Think Space Soft Tec // // Contact : thinkspace@163.net //----------------------------------------------------------------
var date = new Date(); var activeDate = new Date();
var marklist = new ActiveXObject("Scripting.Dictionary");
function WriteXMLToDictionary(xmldoc,dict,rewrite){ var xnodelist = xmldoc.documentElement.selectNodes("Mark"); if (rewrite) dict.RemoveAll(); for (var i=0;i<xnodelist.length;i++){ var xnode = xnodelist.item(i); var xdate = xnode.selectSingleNode("MarkDate"); var xnote = xnode.selectSingleNode("Note"); //alert(xdate.text + "," + xnote.text); if (xdate.text && xnote.text){ dict.item(xdate.text) = xnote.text; } } }
function postxml(xmldoc,url){ var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); xmlhttp.Open("POST",url,false); xmlhttp.Send(xmldoc); var xdoc = new ActiveXObject("Microsoft.XMLDom"); xdoc.async = false; xdoc.loadXML(xmlhttp.responseText); return !!xdoc.documentElement.text; }
function saveMark(url){ var xmldoc = new ActiveXObject("Microsoft.XMLDom"); WriteDictionaryToXML(marklist,xmldoc); if(postxml(xmldoc,url)){ refresh(); sendEvent(); return true; } return false; }
function WriteDictionaryToXML(dict,xmldoc){ xmldoc.loadXML("<MarkList/>"); var keys = (new VBArray(dict.Keys())).toArray(); for (var i=0;i<keys.length;i++){ try{ var d = new Date(keys[i]); }catch(e){ continue; } if (!dict.item(keys[i])) continue; var xmark = xmldoc.createElement("Mark"); var xmarkdate = xmldoc.createElement("MarkDate"); xmarkdate.text = dateToSortString(d); var xnote = xmldoc.createElement("Note"); xnote.text = dict.item(keys[i]); xmark.appendChild(xmarkdate); xmark.appendChild(xnote); xmldoc.documentElement.appendChild(xmark); } }
function loadMark(url,rewrite){ var xmldoc = new ActiveXObject("Microsoft.FreeThreadedXMLDOM"); xmldoc.async = false; xmldoc.load(url); //alert(xmldoc.xml); WriteXMLToDictionary(xmldoc,marklist,rewrite); refresh(); sendEvent(); }
function refresh(){ fillCalendar(date); }
function getCurrentMark(){ if(!getMark(activeDate)) return ""; return getMark(activeDate); }
function setCurrentMark(markvalue){ addMark(activeDate,markvalue); }
function getMark(adate){ if (marklist.Exists(dateToSortString(adate))) return marklist.Item(dateToSortString(adate)); }
function addMark(adate,note){ if (!note) return false; try{ var d = new Date(adate); marklist.item(dateToSortString(d)) = note; fillCalendar(date); return true; }catch(e){ return false; } }
function removeMark(adate){ try { marklist.Remove(dateToSortString(adate)); fillCalendar(date); }catch(e){ } }
function removeAllMark(){ marklist.RemoveAll(); fillCalendar(date); }
function sendEvent(){ var oevent = createEventObject(); vlcg.fire(oevent); }
function setValue(invalue){ try{ var tdate = new Date(invalue); activeDate.setFullYear(tdate.getFullYear(),tdate.getMonth(),tdate.getDate()); date.setFullYear(tdate.getFullYear(),tdate.getMonth(),tdate.getDate()); fillCalendar(date); sendEvent(); }catch(e){ return; } } function fillCalendar(adate){ ynm.innerText = adate.getFullYear() + "年" + (adate.getMonth() + 1) + "月"; var tempdate = new Date(); tempdate.setFullYear(adate.getFullYear(),adate.getMonth(),1); var first = true; for (var i=0;i<tblbd.rows.length;i++){ for (var j=0;j<tblbd.rows(i).cells.length;j++){ var cell = tblbd.rows(i).cells(j); cell.innerHTML = " "; cell.bgcolor = ""; cell.title = ""; cell.style.backgroundColor = "";
if (tempdate.getDay() == j){ if (!first) continue; cell.innerText = tempdate.getDate();
if (getMark(tempdate)){ cell.bgcolor = "wheat"; cell.style.backgroundColor = cell.bgcolor; var tt = getMark(tempdate); if (tt.length<20) cell.title = tt else cell.title = tt.substr(0,20) + "..."; }
if (tempdate.getDate() == activeDate.getDate()){ hightLightDate(cell); }
tempdate.setFullYear(tempdate.getFullYear(),tempdate.getMonth(),tempdate.getDate()+1); first = tempdate.getDate() > 1; } } } }
function hightLightDate(object){ var tds = tblbd.all.tags("TD"); for (var i=0;i<tds.length;i++){ if (tds(i) != object){ tds(i).style.backgroundColor = tds(i).bgcolor; tds(i).style.color = "" }else{ tds(i).style.backgroundColor = "navy"; tds(i).style.color = "white"; } } }
function selectDate(){ var i = parseInt(window.event.srcElement.innerText); if ((!isNaN(i)) && (i<3000)){ hightLightDate(window.event.srcElement); activeDate.setFullYear(date.getFullYear(),date.getMonth(),i); sendEvent(); } }
function moveDate(){ var k = window.event.keyCode; switch(k){ case 37: activeDate.setFullYear(activeDate.getFullYear(),activeDate.getMonth(),activeDate.getDate()-1); break; case 38: activeDate.setFullYear(activeDate.getFullYear(),activeDate.getMonth(),activeDate.getDate()-7); break; case 39: activeDate.setFullYear(activeDate.getFullYear(),activeDate.getMonth(),activeDate.getDate()+1); break; case 40: activeDate.setFullYear(activeDate.getFullYear(),activeDate.getMonth(),activeDate.getDate()+7); break; } date.setFullYear(activeDate.getFullYear(),activeDate.getMonth(),activeDate.getDate()); fillCalendar(date); sendEvent(); }
function setActiveDate(){ var i = activeDate.getDate(); activeDate.setFullYear(date.getFullYear(),date.getMonth(),i); while ((date.getMonth() != activeDate.getMonth()) || (date.getFullYear() != activeDate.getFullYear())){ activeDate.setFullYear(date.getFullYear(),date.getMonth(),i--); } sendEvent(); }
function goNextMonth(){ date.setMonth(date.getMonth()+1,1); setActiveDate(); fillCalendar(date); }
function goNextYear(){ date.setFullYear(date.getFullYear()+1,date.getMonth(),1); setActiveDate(); fillCalendar(date); }
function goPriorYear(){ date.setFullYear(date.getFullYear()-1,date.getMonth(),1); setActiveDate(); fillCalendar(date); }
function goPriorMonth(){ date.setMonth(date.getMonth()-1,1); setActiveDate(); fillCalendar(date); }
var tbl = window.document.createElement("<TABLE style=/"border:solid 1px;width:100%;height:100%;font-size:9pt/" cellspacing=0>"); var tblhd = window.document.createElement("THEAD"); var tblbd = window.document.createElement("TBODY");