📄 spiffycal_v2_1.js
字号:
strTemp=' onFocus="'+this.varName+'.show();" ';
}
if (!(this.useDateRange)) {
strTemp+=' onChange="calMgr.validateDate(document.'+this.formName+'.'+this.textBoxName+','+this.varName+'.required);" onBlur="calMgr.formatDate(document.'+this.formName+'.'+this.textBoxName+','+this.varName+'.dateFormat);" ';
}
else {
strTempMinDate=this.minDate.getDate()+'-'+msNames[this.minDate.getMonth()]+'-'+this.minDate.getFullYear();
strTempMaxDate=this.maxDate.getDate()+'-'+msNames[this.maxDate.getMonth()]+'-'+this.maxDate.getFullYear();
strTemp+=' onChange="calMgr.validateDate('+'document.'+this.formName+'.'+this.textBoxName+','+this.varName+'.required,'+this.varName+'.minDate,'+this.varName+'.maxDate);" onBlur="calMgr.formatDate(document.'+this.formName+'.'+this.textBoxName+','+this.varName+'.dateFormat);" ';
}
strHold='<input class="cal-TextBox" type="text" name="' + this.textBoxName + '"' + strTemp + 'size="12" value="' + this.getSelectedDate() + '">';
if (!scIE) {
strTemp=' href="javascript:calClick();return false;" ';
}
else {
strTemp='';
}
if ((this.focusClick==false) || (this.focusClick==true && this.hideButton==false)) {
strHold+='<a class="so-BtnLink"'+strTemp;
strHold+=' onmouseover="calMgr.swapImg(' + this.varName + ',\'.imgOver\',false);" ';
strHold+='onmouseout="calMgr.swapImg(' + this.varName + ',\'.imgUp\',false);" ';
strHold+='onclick="calMgr.swapImg(' + this.varName + ',\'.imgDown\',true);';
// strHold+=this.varName+'.show();return false;">';
strHold+=this.varName+'.show();">';
strHold+='<img align="absmiddle" border="0" name="' + this.btnName + '" src="' + strBtnImg +'" width="'+ strBtnW +'" height="'+ strBtnH +'"></a>';
}
document.write(strHold);
}
this.writeControl=writeControl;
// show -------------------------------------
//
function show() {
var strCurSelDate = calMgr.lastSelectedDate;
if (!this.enabled) { return }
calMgr.hideAllCalendars(this);
if (this.visible) {
this.hide();
}
else {
// put these next 2 lines in when the tiny cal btns seem to randomly disappear
if (document.images['calbtn1']!=null ) document.images['calbtn1'].src=img_Del.src;
if (document.images['calbtn2']!=null ) document.images['calbtn2'].src=img_Close.src;
if (this.focusClick==true && this.hideButton==true) {
//if no dropdown button then use user-provided location for it
scX=this.x;
scY=this.y;
}
else {
// get correct position of date btn
if ( scIE ) {
if (this.displayLeft) {
scX = getOffsetLeft(document.images[this.btnName])-192+ document.images[this.btnName].width ;
}
else {
scX = getOffsetLeft(document.images[this.btnName]);
}
if (this.displayTop) {
scY = getOffsetTop(document.images[this.btnName]) -138 ;
}
else {
scY = getOffsetTop(document.images[this.btnName]) + document.images[this.btnName].height + 2;
}
}
else if (scNN){
if (this.displayLeft) {
scX = document.images[this.btnName].x - 192+ document.images[this.btnName].width;
}
else {
scX = document.images[this.btnName].x;
}
if (this.displayTop) {
scY = document.images[this.btnName].y -134;
}
else {
scY = document.images[this.btnName].y + document.images[this.btnName].height + 2;
}
}
}
// hide all combos underneath it
if (this.hideCombos) {toggleCombos('hidden');}
// pop calendar up to the correct month and year if there's a date there
// otherwise pop it up using today's month and year
if (this.getSelectedDate()==''){
if (!(dteCur)) {
domlay('spiffycalendar',1,scX,scY,this.makeCalendar(dteToday.getMonth(),dteToday.getFullYear()));
}
else {
domlay('spiffycalendar',1,scX,scY,this.makeCalendar(dteCur.getMonth(),dteCur.getFullYear()));
}
}
else {
if (calMgr.isDate(quote(this.getSelectedDate()),quote(this.dateFormat))) {
dteCur = calMgr.getDateFromFormat(quote(this.getSelectedDate()),quote(this.dateFormat));
dteCur.setHours(0);dteCur.setMinutes(0);dteCur.setSeconds(0);dteCur.setMilliseconds(0);
}
else {
dteCur=calMgr.lastSelectedDate;
}
domlay('spiffycalendar',1,scX,scY,this.makeCalendar(dteCur.getMonth(),dteCur.getFullYear()));
}
this.visible=true;
}
}
this.show=show;
// hide -------------------------------------
//
function hide() {
domlay('spiffycalendar',0,scX,scY);
this.visible = false;
calMgr.swapImg(this,'.imgUp',false);
if (this.hideCombos) {toggleCombos('visible');}
}
this.hide=hide;
// clearDay -------------------------------------
//
function clearDay() {
eval('document.' + this.formName + '.' + this.textBoxName + '.value = \'\'');
this.hide();
if (this.JStoRunOnClear!=null)
eval(unescape(this.JStoRunOnClear));
eval('document.'+this.formName+'.'+this.textBoxName).className = "cal-TextBox";
if (this.required) {
eval('document.'+this.formName+'.'+this.textBoxName).className = "cal-TextBoxInvalid";
}
}
this.clearDay=clearDay;
// changeDay -------------------------------------
//
function changeDay(intWhatDay) {
dteCur.setDate(intWhatDay);
dteCur.setHours(0);dteCur.setMinutes(0);dteCur.setSeconds(0);dteCur.setMilliseconds(0);
this.textBox().value=calMgr.scFormatDate(dteCur,this.dateFormat);
this.hide();
if (this.JStoRunOnSelect!=null)
eval(unescape(this.JStoRunOnSelect));
eval('document.'+this.formName+'.'+this.textBoxName).className = "cal-TextBox";
}
this.changeDay=changeDay;
// scrollMonth -------------------------------------
//
function scrollMonth(intAmount) {
var intMonthCheck;
var intYearCheck;
if (scIE) {
intMonthCheck = document.forms["spiffyCal"].cboMonth.selectedIndex + intAmount;
}
else if (scNN) {
intMonthCheck = document.spiffycalendar.document.forms["spiffyCal"].cboMonth.selectedIndex + intAmount;
}
if (intMonthCheck < 0) {
intYearCheck = dteCur.getFullYear() - 1;
if ( intYearCheck < this.minYearChoice ) {
intYearCheck = this.minYearChoice;
intMonthCheck = 0;
}
else {
intMonthCheck = 11;
}
dteCur.setFullYear(intYearCheck);
}
else if (intMonthCheck >11) {
intYearCheck = dteCur.getFullYear() + 1;
if ( intYearCheck > this.maxYearChoice-1 ) {
intYearCheck = this.maxYearChoice-1;
intMonthCheck = 11;
}
else {
intMonthCheck = 0;
}
dteCur.setFullYear(intYearCheck);
}
if (scIE) {
dteCur.setMonth(document.forms["spiffyCal"].cboMonth.options[intMonthCheck].value);
}
else if (scNN) {
dteCur.setMonth(document.spiffycalendar.document.forms["spiffyCal"].cboMonth.options[intMonthCheck].value );
}
domlay('spiffycalendar',1,scX,scY,this.makeCalendar(dteCur.getMonth(),dteCur.getFullYear()));
}
this.scrollMonth=scrollMonth;
// changeMonth -------------------------------------
//
function changeMonth() {
if (scIE) {
dteCur.setMonth(document.forms["spiffyCal"].cboMonth.options[document.forms["spiffyCal"].cboMonth.selectedIndex].value);
domlay('spiffycalendar',1,scX,scY,this.makeCalendar(dteCur.getMonth(),dteCur.getFullYear()));
}
else if (scNN) {
dteCur.setMonth(document.spiffycalendar.document.forms["spiffyCal"].cboMonth.options[document.spiffycalendar.document.forms["spiffyCal"].cboMonth.selectedIndex].value);
domlay('spiffycalendar',1,scX,scY,this.makeCalendar(dteCur.getMonth(),dteCur.getFullYear()));
}
}
this.changeMonth=changeMonth;
// changeYear -------------------------------------
//
function changeYear() {
if (scIE) {
dteCur.setFullYear(document.forms["spiffyCal"].cboYear.options[document.forms["spiffyCal"].cboYear.selectedIndex].value);
domlay('spiffycalendar',1,scX,scY,this.makeCalendar(dteCur.getMonth(),dteCur.getFullYear()));
}
else if (scNN) {
dteCur.setFullYear(document.spiffycalendar.document.forms["spiffyCal"].cboYear.options[document.spiffycalendar.document.forms["spiffyCal"].cboYear.selectedIndex].value);
domlay('spiffycalendar',1,scX,scY,this.makeCalendar(dteCur.getMonth(),dteCur.getFullYear()));
}
}
this.changeYear=changeYear;
function getDayLink(blnIsGreyDate,intLinkDay,intLinkMonth,intLinkYear,bViewOnly,isWE) {
var templink; var tempLinkClass='calDay-Link';
var tempClass='cal-DayCell';
var tempDt=''; var isHol=-1; var holTxt='';
if (isWE==true && this.showWeekends==true) {tempClass='cal-WeekendCell';}
tempDt=msNames[intLinkMonth]+'-'+intLinkDay;
if (this.showHolidays) {isHol=calMgr.isHoliday(tempDt); if (isHol!=-1) {holTxt=' title="'+calMgr.HolidaysDesc[isHol]+'"'; tempClass='cal-HolidayCell';}}
if (!(this.useDateRange)) {
if (blnIsGreyDate) {
templink='<td align="center" class="cal-GreyDate">' + intLinkDay + '<\/td>';
}
else {
if (isDayToday(intLinkDay)) {
if (!(bViewOnly)) {
templink='<td align="center" class="'+tempClass+'">' + '<a class="cal-TodayLink" '+holTxt+' onmouseover="self.status=\' \';return true" href="javascript:'+this.varName+'.changeDay(' + intLinkDay + ');">' + intLinkDay + '<\/a><\/td>';
}
else {
templink='<td align="center" class="'+tempClass+'"><span class="cal-Today">' + intLinkDay +'<\/span><\/td>';
}
}
else {
if (!(bViewOnly)) {
templink='<td align="center" class="'+tempClass+'">' + '<a class="cal-DayLink" '+holTxt+' onmouseover="self.status=\' \';return true" href="javascript:'+this.varName+'.changeDay(' + intLinkDay + ');">' + intLinkDay + '<\/a>' +'<\/td>';
}
else {
templink='<td align="center" class="'+tempClass+'"><span class="cal-Day">' + intLinkDay + '<\/span><\/td>';
}
}
}
}
else {
if (this.isDayValid(intLinkDay,intLinkMonth,intLinkYear)) {
if (blnIsGreyDate){
templink='<td align="center" class="cal-GreyDate">' + intLinkDay + '<\/td>';
}
else {
if (isDayToday(intLinkDay)) {
if (!(bViewOnly)) {
templink='<td align="center" class="'+tempClass+'">' + '<a class="cal-TodayLink" '+holTxt+' onmouseover="self.status=\' \';return true" href="javascript:'+this.varName+'.changeDay(' + intLinkDay + ');">' + intLinkDay + '<\/a>' +'<\/td>';
}
else {
templink='<td align="center" class="'+tempClass+'"><span class="cal-Today">' + intLinkDay + '<\/span><\/td>';
}
}
else {
if (!(bViewOnly)) {
templink='<td align="center" class="'+tempClass+'">' + '<a class="cal-DayLink" '+holTxt+' onmouseover="self.status=\' \';return true" href="javascript:'+this.varName+'.changeDay(' + intLinkDay + ');">' + intLinkDay + '<\/a>' +'<\/td>';
}
else {
templink='<td align="center" class="'+tempClass+'"><span class="cal-Day">' + intLinkDay +'<\/span><\/td>';
}
}
}
}
else {
templink='<td align="center" class="cal-GreyInvalidDate">'+ intLinkDay + '<\/td>';
}
}
return templink;
}
this.getDayLink=getDayLink;
// EXTRA Private FUNCTIONS ===============================================================
function toggleCombos(showHow){
var i; var j;
var cboX; var cboY;
for (i=0;i<document.forms.length;i++) {
for (j=0;j<document.forms[i].elements.length;j++) {
if (document.forms[i].elements[j].tagName == "SELECT") {
if (document.forms[i].name != "spiffyCal") {
cboX = getOffsetLeft(document.forms[i].elements[j]);
cboY = getOffsetTop(document.forms[i].elements[j]);
if ( ((cboX>=scX-15) && (cboX<=scX+200)) && ((cboY>=scY-15) && (cboY<=scY+145)) )
document.forms[i].elements[j].style.visibility=showHow;
//Check for right hand side overlapping.
cboX = cboX + parseInt(document.forms[i].elements[j].style.width);
cboY=cboY+15;//cbo height (default)
if ( ((cboX>=scX+15) && (cboX<=scX+200)) && ((cboY>=scY-15) && (cboY<=scY+145)) )
document.forms[i].elements[j].style.visibility=showHow;
}
}
}
}
}
function isDayToday(intWhatDay) {
if ((dteCur.getFullYear() == dteToday.getFullYear()) && (dteCur.getMonth() == dteToday.getMonth()) && (intWhatDay == dteToday.getDate())) {
return true;
}
else {
return false;
}
}
function isDayValid(intWhatDay, intWhatMonth, intWhatYear){
dteCur.setDate(intWhatDay);
dteCur.setMonth(intWhatMonth);
dteCur.setFullYear(intWhatYear);
dteCur.setHours(0);dteCur.setMinutes(0);dteCur.setSeconds(0);dteCur.setMilliseconds(0);
if ((dteCur>=this.minDate) && (dteCur<=this.maxDate)) {
return true;
}
else {
return false;
}
}
this.isDayValid=isDayValid;
calMgr.addCalendar(this);
blnInConstructor=false;
}
// Utility functions----------------------------------
function quote(sWhat) {
return '\''+sWhat+'\'';
}
function getOffsetLeft (el) {
var ol = el.offsetLeft;
while ((el = el.offsetParent) != null)
ol += el.offsetLeft;
return ol;
}
function getOffsetTop (el) {
var ot = el.offsetTop;
while((el = el.offsetParent) != null)
ot += el.offsetTop;
return ot;
}
function calClick() {
window.focus();
}
function domlay(id,trigger,lax,lay,content) {
/*
* Cross browser Layer visibility / Placement Routine
* Done by Chris Heilmann (mail@ichwill.net)
* http://www.ichwill.net/mom/domlay/
* Feel free to use with these lines included!
* Created with help from Scott Andrews.
* The marked part of the content change routine is taken
* from a script by Reyn posted in the DHTML
* Forum at Website Attraction and changed to work with
* any layername. Cheers to that!
* Welcome DOM-1, about time you got included... :)
*/
// Layer visible
if (trigger=="1"){
if (document.layers) document.layers[''+id+''].visibility = "show"
else if (document.all) document.all[''+id+''].style.visibility = "visible"
else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "visible"
}
// Layer hidden
else if (trigger=="0"){
if (document.layers) document.layers[''+id+''].visibility = "hide"
else if (document.all) document.all[''+id+''].style.visibility = "hidden"
else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "hidden"
}
// Set horizontal position
if (lax){
if (document.layers){document.layers[''+id+''].left = lax}
else if (document.all){document.all[''+id+''].style.left=lax}
else if (document.getElementById){document.getElementById(''+id+'').style.left=lax+"px"}
}
// Set vertical position
if (lay){
if (document.layers){document.layers[''+id+''].top = lay}
else if (document.all){document.all[''+id+''].style.top=lay}
else if (document.getElementById){document.getElementById(''+id+'').style.top=lay+"px"}
}
// change content
if (content){
if (document.layers){
sprite=document.layers[''+id+''].document;
// add father layers if needed! document.layers[''+father+'']...
sprite.open();
sprite.write(content);
sprite.close();
}
else if (document.all) document.all[''+id+''].innerHTML = content;
else if (document.getElementById){
//Thanx Reyn!
rng = document.createRange();
el = document.getElementById(''+id+'');
rng.setStartBefore(el);
htmlFrag = rng.createContextualFragment(content)
while(el.hasChildNodes()) el.removeChild(el.lastChild);
el.appendChild(htmlFrag);
// end of Reyn ;)
}
}
}
function makeArray0() {
for (i = 0; i<makeArray0.arguments.length; i++)
this[i] = makeArray0.arguments[i];
}
//---------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -