温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:IFNuke1.1.0版源码
当前文件:
IFnuke110/Website/js/PopupCalendar.js,打开代码结构图
IFnuke110/Website/js/PopupCalendar.js,打开代码结构图1// ******************** 2
// Begin Popup Calendar 3
// ******************** 4
var popCalDstFld; 5
var temp; 6
var popCalWin; 7
8
// ****************************** 9
// Expected params: 10
// [0] Window Name 11
// [1] Destination Field 12
// [2] Short Date Format 13
// [3] Month Names 14
// [4] Day Names 15
// [5] Localized Today string 16
// [6] Localized Close string 17
// [7] Window Title 18
// [8] First Day of Week 19
// ****************************** 20
function popupCal() 21
{ 22
//debugger; //remove slashes to activate debugging in Visual Studio 23
var tmpDate = new Date(); 24
var tmpString = ""; 25
var tmpNum = 0; 26
var popCalDateVal; 27
var dstWindowName = ""; 28
29
//Initialize the window to an empty object. 30
popCalWin = new Object(); 31
32
//Check for the right number of arguments 33
if (arguments.length < 2) 34
{ 35
alert("popupCal(): Wrong number of arguments."); 36
return void(0); 37
} 38
//Get the command line arguments -- Localization is optional 39
dstWindowName = popupCal.arguments[0]; 40
popCalDstFld = popupCal.arguments[1]; 41
temp = popupCal.arguments[1]; 42
popCalDstFmt = popupCal.arguments[2]; //Localized Short Date Format String 43
popCalMonths = popupCal.arguments[3]; //Localized Month Names String 44
popCalDays = popupCal.arguments[4]; //Localized Day Names String 45
popCalToday = popupCal.arguments[5]; //Localized Today string 46
popCalClose = popupCal.arguments[6]; //Localized Close string 47
popCalTitle = popupCal.arguments[7]; //Window Title 48
popCalFirstDayWeek = popupCal.arguments[8]; //First Day of Week 49
50
//check destination field name 51
if (popCalDstFld != "") 52
popCalDstFld = document.getElementById(popCalDstFld); 53
54
//default localized short date format if not provided 55
if (popCalDstFmt == "") 56
popCalDstFmt = "m/d/yyyy"; 57
58
//default localized months string if not provided 59
if (popCalMonths == "") 60
popCalMonths = "January,February,March,April,May,June,July,August,September,October,November,December"; 61
62
//default localized months string if not provided 63
if (popCalDays == "") 64
popCalDays = "Sun,Mon,Tue,Wed,Thu,Fri,Sat"; 65
66
//default localized today string if not provided 67
if (popCalToday == "" || typeof popCalToday == "undefined") 68
popCalToday = "Today"; 69
70
//default localized close string if not provided 71
if (popCalClose == "" || typeof popCalClose == "undefined") 72
popCalClose = "Close"; 73
74
//default window title if not provided 75
if (popCalTitle == "" || typeof popCalTitle == "undefined") 76
popCalTitle = "Calendar"; 77
78
tmpString = new String(popCalDstFld.value); 79
//If tmpString is empty (meaning that the field is empty) 80
//use todays date as the starting point 81
if(tmpString == "") 82
popCalDateVal = new Date() 83
else 84
{ 85
//Make sure the century is included, if it isn't, add this 86
//century to the value that was in the field 87
tmpNum = tmpString.lastIndexOf( "/" ); 88
if ( (tmpString.length - tmpNum) == 3 ) 89
{ 90
tmpString = tmpString.substring(0,tmpNum + 1)+"20"+tmpString.substr(tmpNum+1); 91
popCalDateVal = new Date(tmpString); 92
} 93
else 94
{ 95
//localized date support: 96
//If we got to this point, it means the field that was passed 97
//in has no slashes in it. Use an extra function to build the date 98
//according to supplied date formatstring. 99
popCalDateVal = getDateFromFormat(tmpString,popCalDstFmt); 100
} 101
} 102
103
//Make sure the date is a valid date. Set it to today if it is invalid 104
//"NaN" is the return value for an invalid date 105
if( popCalDateVal.toString() == "NaN" || popCalDateVal.toString() == "0") 106
{ 107
popCalDateVal = new Date(); 108
popCalDstFld.value = ""; 109
} 110
111
//Set the base date to midnight of the first day of the specified month, 112
//this makes things easier? 113
var dateString = String(popCalDateVal.getMonth()+1) + "/" + String(popCalDateVal.getDate()) + "/" + String(popCalDateVal.getFullYear()); 114
115
//Call the routine to draw the initial calendar 116
reloadCalPopup(dateString, dstWindowName); 117
118
return void(0); 119
} 120
121
function closeCalPopup() 122
{ 123
//Can't tell the child window to close itself, the parent window has to 124
//tell it to close. 125
popCalWin.close(); 126
return void(0); 127
} 128
129
function reloadCalPopup() //[0]dateString, [1]dstWindowName 130
{ 131
//Set the window's features here 132
133
var windowFeatures = "toolbar=no, location=no, status=no, menubar=no, scrollbars=no, resizable=no, height=270, width=270, top=" + ((screen.height - 270)/2).toString()+",left="+((screen.width - 270)/2).toString(); 134
var tmpDate = new Date( reloadCalPopup.arguments[0] ); 135
136
if (tmpDate.toString() == "Invalid Date") 137
tmpDate = new Date(); 138
139
tmpDate.setDate(1); 140
141
//Get the calendar data 142
var popCalData = calPopupSetData(tmpDate,reloadCalPopup.arguments[1]); 143
144
//Check to see if the window has been initialized, create it if it hasn't been 145
if( popCalWin.toString() == "[object Object]" ) 146
{ 147
popCalWin = window.open("",reloadCalPopup.arguments[1],windowFeatures); 148
popCalWin.opener = self; 149
// Window im Vordergrund 150
popCalWin.focus(); 151
} 152
else 153
{ 154
popCalWin.document.close(); 155
popCalWin.document.clear(); 156
} 157
158
//this is the line with the big problem 159
popCalWin.document.write(popCalData); 160
return void(1); 161
} 162
163
function calPopupSetData(firstDay,dstWindowName) 164
{ 165
var popCalData = ""; 166
var lastDate = 0; 167
var fnt = new Array( "<FONT SIZE=\"1\">", "<B><FONT SIZE=\"2\">", "<FONT SIZE=\"2\" COLOR=\"#EF741D\"><B>"); 168
var dtToday = new Date(); 169
var thisMonth = firstDay.getMonth(); 170
var thisYear = firstDay.getFullYear(); 171
var nPrevMonth = (thisMonth == 0 ) ? 11 : (thisMonth - 1); 172
var nNextMonth = (thisMonth == 11 ) ? 0 : (thisMonth + 1); 173
var nPrevMonthYear = (nPrevMonth == 11) ? (thisYear - 1): thisYear; 174
var nNextMonthYear = (nNextMonth == 0) ? (thisYear + 1): thisYear; 175
var sToday = String((dtToday.getMonth()+1) + "/01/" + dtToday.getFullYear()); 176
var sPrevMonth = String((nPrevMonth+1) + "/01/" + nPrevMonthYear); 177
var sNextMonth = String((nNextMonth+1) + "/01/" + nNextMonthYear); 178
var sPrevYear1 = String((thisMonth+1) + "/01/" + (thisYear - 1)); 179
var sNextYear1 = String((thisMonth+1) + "/01/" + (thisYear + 1)); 180
var tmpDate = new Date( sNextMonth ); 181
182
tmpDate = new Date( tmpDate.valueOf() - 1001 ); 183
lastDate = tmpDate.getDate(); 184
185
if (this.popCalMonths.split) // javascript 1.1 defensive code 186
{ 187
var monthNames = this.popCalMonths.split(","); 188
var dayNames = this.popCalDays.split(","); 189
} 190
else // Need to build a js 1.0 split algorithm, default English for now 191
{ 192
var monthNames = new Array("January","February","March","April","May","June","July","August","September","October","November","December"); 193
var dayNames = new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat") 194
} 195
196
var styles = "<style><!-- body{font-family:Arial,Helvetica,sans-serif;font-size:9pt}; td { font-family: Arial, Helvetica, sans-serif; font-size: 9pt; color: #666666}; A { text-decoration: none; };TD.day { border-bottom: solid black; border-width: 0px; }--></style>" 197
var cellAttribs = "align=\"center\" class=\"day\" BGCOLOR=\"#F1F1F1\"onMouseOver=\"temp=this.style.backgroundColor;this.style.backgroundColor='#CCCCCC';\" onMouseOut=\"this.style.backgroundColor=temp;\"" 198
var cellAttribs2 = "align=\"center\" BGCOLOR=\"#F1F1F1\" onMouseOver=\"temp=this.style.backgroundColor;this.style.backgroundColor='#CCCCCC';\" onMouseOut=\"this.style.backgroundColor=temp;\"" 199
var htmlHead = "<HTML><HEAD><TITLE>"+popCalTitle+"</TITLE>" + styles + "</HEAD><BODY BGCOLOR=\"#F1F1F1\" TEXT=\"#000000\" LINK=\"#364180\" ALINK=\"#FF8100\" VLINK=\"#424282\">"; 200
var htmlTail = "</BODY></HTML>"; 201
var closeAnchor = "<CENTER><input type=button value=\""+popCalClose+"\" onClick=\"javascript:window.opener.closeCalPopup()\"></CENTER>"; 202
var todayAnchor = "<A HREF=\"javascript:window.opener.reloadCalPopup('"+sToday+"','"+dstWindowName+"');\">"+popCalToday+"</A>"; 203
var prevMonthAnchor = "<A HREF=\"javascript:window.opener.reloadCalPopup('"+sPrevMonth+"','"+dstWindowName+"');\">" + monthNames[nPrevMonth] + "</A>"; 204
var nextMonthAnchor = "<A HREF=\"javascript:window.opener.reloadCalPopup('"+sNextMonth+"','"+dstWindowName+"');\">" + monthNames[nNextMonth] + "</A>"; 205
var prevYear1Anchor = "<A HREF=\"javascript:window.opener.reloadCalPopup('"+sPrevYear1+"','"+dstWindowName+"');\">"+(thisYear-1)+"</A>"; 206
var nextYear1Anchor = "<A HREF=\"javascript:window.opener.reloadCalPopup('"+sNextYear1+"','"+dstWindowName+"');\">"+(thisYear+1)+"</A>"; 207
208
popCalData += (htmlHead + fnt[1]); 209
popCalData += ("<DIV align=\"center\">"); 210
popCalData += ("<TABLE BORDER=\"0\" cellspacing=\"0\" callpadding=\"0\" width=\"250\"><TR><TD width=\"45\"> </TD>"); 211
popCalData += ("<TD width=\"45\" align=\"center\" " + cellAttribs2); 212
popCalData += (" >"); 213
popCalData += (fnt[0]+prevYear1Anchor+"</FONT></TD>"); 214
popCalData += ("<TD width=\"70\" align=\"center\" "+cellAttribs2); 215
popCalData += (" >"); 216
popCalData += (fnt[0]+todayAnchor+"</FONT></TD>"); 217
popCalData += ("<TD width=\"45\" align=\"center\" "+cellAttribs2); 218
popCalData += (" >"); 219
popCalData += (fnt[0]+nextYear1Anchor+"</FONT></TD><TD width=\"45\"> </TD>"); 220
popCalData += ("</TR></TABLE>"); 221
popCalData += ("<TABLE BORDER=\"0\" cellspacing=\"0\" callpadding=\"0\" width=\"250\">"); 222
popCalData += ("<TR><TD width=\"55\" align=\"center\" "+cellAttribs2); 223
popCalData += (" >"); 224
popCalData += (fnt[0] + prevMonthAnchor + "</FONT></TD>"); 225
popCalData += ("<TD width=\"140\" align=\"center\">"); 226
popCalData += (" "+fnt[1]+"<FONT COLOR=\"#000000\">" + monthNames[thisMonth] + ", " + thisYear + " </FONT></TD>"); 227
popCalData += ("<TD width=\"55\" align=\"center\" "+cellAttribs2); 228
popCalData += (" >"); 229
popCalData += (fnt[0]+nextMonthAnchor+"</FONT></TD></TR></TABLE><BR>"); 230
popCalData += ("<TABLE BORDER=\"0\" cellspacing=\"2\" cellpadding=\"1\" width=\"245\">" ); 231
popCalData += (""); 232
popCalData += ("<TR>"); 233
234
/* 235
popCalData += ("<TD width=\"35\" align=\"center\">"+fnt[1]+"<FONT COLOR=\"#000000\">"+dayNames[0]+"</FONT></TD>"); 236
popCalData += ("<TD width=\"35\" align=\"center\">"+fnt[1]+"<FONT COLOR=\"#000000\">"+dayNames[1]+"</FONT></TD>"); 237
popCalData += ("<TD width=\"35\" align=\"center\">"+fnt[1]+"<FONT COLOR=\"#000000\">"+dayNames[2]+"</FONT></TD>"); 238
popCalData += ("<TD width=\"35\" align=\"center\">"+fnt[1]+"<FONT COLOR=\"#000000\">"+dayNames[3]+"</FONT></TD>"); 239
popCalData += ("<TD width=\"35\" align=\"center\">"+fnt[1]+"<FONT COLOR=\"#000000\">"+dayNames[4]+"</FONT></TD>"); 240
popCalData += ("<TD width=\"35\" align=\"center\">"+fnt[1]+"<FONT COLOR=\"#000000\">"+dayNames[5]+"</FONT></TD>"); 241
popCalData += ("<TD width=\"35\" align=\"center\">"+fnt[1]+"<FONT COLOR=\"#000000\">"+dayNames[6]+"</FONT></TD>"); 242
*/ 243
var xday = 0; 244
for (xday = 0; xday < 7; xday++) 245
{ 246
popCalData += ("<TD width=\"35\" align=\"center\">"+fnt[1]+"<FONT COLOR=\"#000000\">"+dayNames[(xday+popCalFirstDayWeek)%7]+"</FONT></TD>"); 247
}; 248
popCalData += ("</TR>"); 249
250
var calDay = 0; 251
var monthDate = 1; 252
var weekDay = firstDay.getDay(); 253
do 254
{ 255
popCalData += ("<TR>"); 256
for (calDay = 0; calDay < 7; calDay++ ) 257
{ 258
if(((weekDay+7-popCalFirstDayWeek)%7 != calDay) || (monthDate > lastDate)) 259
{ 260
popCalData += ("<TD width=\"35\">"+fnt[1]+" </FONT></TD>"); 261
continue; 262
} 263
else





}
}