控件名称:calendar with date mark
版 本:1.0
类 型:html component
运行需求:ie 5(推荐ie5.5或更高版本)、msxml、asp或asp.net(后台)
费 用:免费
支 持:不提供支持
源 代 码:xml scriptlet
------------------------------------------------------------------------
<public:attach event="oncontentready" onevent="init()"/>
<public:property name="value" get="getvalue" put="setvalue"/>
<public:property name="stringvalue" get="getstringvalue" />
<public:property name="mark" get="getcurrentmark" put="setcurrentmark" />
<public:property name="marklist" get="getmarklist" />
<public:method name="refresh" />
<public:method name="addmark" />
<public:method name="removemark" />
<public:method name="removeallmark" />
<public:method name="loadmark" />
<public:method name="savemark" />
<public:event name="onvaluechange" id="vlcg" />
<script language="jscript">
//----------------------------------------------------------------
// 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 : [email protected]
//----------------------------------------------------------------
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 getmarklist(){
return marklist;
}
function datetosortstring(adate){
return (adate.getmonth()+1) + "/" + adate.getdate() + "/" + adate.getfullyear();
}
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 getstringvalue(){
return activedate.getfullyear() + "年" + (activedate.getmonth() + 1) + "月" + activedate.getdate() + "日";
}
function getvalue(){
return activedate;
}
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");
var anchorprioryear = window.document.createelement("a");
anchorprioryear.style.fontfamily = "webdings";
anchorprioryear.style.cursor = "hand";
anchorprioryear.innertext = "7";
anchorprioryear.title = "上一年";
var anchorpriormonth = window.document.createelement("a");
anchorpriormonth.style.fontfamily = "webdings";
anchorpriormonth.style.cursor = "hand";
anchorpriormonth.innertext = "3";
anchorpriormonth.title = "上一月";
var anchornextmonth = window.document.createelement("a");
anchornextmonth.style.fontfamily = "webdings";
anchornextmonth.style.cursor = "hand";
anchornextmonth.innertext = "4";
anchornextmonth.title = "下一月";
var anchornextyear = window.document.createelement("a");
anchornextyear.style.fontfamily = "webdings";
anchornextyear.style.cursor = "hand";
anchornextyear.innertext = "8";
anchornextyear.title = "下一年";
var ynm = window.document.createelement("font");
ynm.style.width = "60%";
ynm.style.fontweight = "bold";
var cpt = window.document.createelement("caption");
tbl.appendchild(cpt);
tbl.appendchild(tblhd);
tbl.appendchild(tblbd);
function inithead(){
cpt.style.backgroundcolor = "navy";
cpt.style.color = "white";
cpt.style.textalign = "center";
cpt.style.cursor = "defalut";
cpt.appendchild(anchorprioryear);
cpt.appendchild(anchorpriormonth);
cpt.appendchild(ynm);
cpt.appendchild(anchornextmonth);
cpt.appendchild(anchornextyear);
var row = tblhd.insertrow();
row.align = "center";
var weekstr = new array("日","一","二","三","四","五","六");
for (var i=0;i<weekstr.length;i++){
var cell = row.insertcell();
cell.innertext = weekstr[i];
cell.style.borderbottom = "solid 1px";
cell.style.cursor = "default";
cell.align = "center";
}
}
function initbody(){
for (var i=0;i<6;i++){
var row = tblbd.insertrow();
for (var j=0;j<7;j++){
var cell = row.insertcell();
cell.innerhtml = " ";
cell.style.cursor = "default";
cell.align = "center";
}
}
}
function init(){
inithead();
initbody();
element.appendchild(tbl);
fillcalendar(date);
tblbd.attachevent("onclick",selectdate);
tblbd.attachevent("onkeydown",movedate);
anchorprioryear.attachevent("onclick",goprioryear);
anchorpriormonth.attachevent("onclick",gopriormonth);
anchornextmonth.attachevent("onclick",gonextmonth);
anchornextyear.attachevent("onclick",gonextyear);
sendevent();
}
</script>