📄 scw.js
字号:
// Set up some shortcutsfunction scwID(id) { return document.getElementById(id);}// Use a global variable for the return value from the next action// IE fails to pass the function through if the target element is in// a form and scwNextAction is not defined.var scwNextActionReturn, scwNextAction;// ****************************************************************************// Start of Function Library//// Exposed functions://// scwShow Entry point for display of calendar,// called in main page.// showCal Legacy name of scwShow:// Passes only legacy arguments,// not the optional day disabling arguments.//// scwShowMonth Displays a month on the calendar,// Called when a month is set or changed.//// scwBeginDrag Controls calendar dragging.//// scwCancel Called when the calendar background is clicked:// Calls scwStopPropagation and may call scwHide.// scwHide Hides the calendar, called on various events.// scwStopPropagation Stops the propagation of an event.//// ****************************************************************************function showCal(scwEle, scwSourceEle) { scwShow(scwEle, scwSourceEle);}function scwShow(scwEle, scwSourceEle){ scwTriggerEle = scwSourceEle; // Take any parameters that there might be from the third onwards as // day numbers to be disabled 0 = Sunday through to 6 = Saturday. scwParmActiveToday = true; for (var i = 0; i < 7; i++) { scwPassEnabledDay[(i + 7 - scwWeekStart) % 7] = true; for (var j = 2; j < arguments.length; j++) { if (arguments[j] == i) { scwPassEnabledDay[(i + 7 - scwWeekStart) % 7] = false; if (scwDateNow.getDay() == i) scwParmActiveToday = false; } } } // If no value is preset then the seed date is // Today (when today is in range) OR // The middle of the date range. scwSeedDate = scwDateNow; // Find the date and Strip space characters from start and // end of date input. if (typeof scwEle.value == 'undefined') { var scwChildNodes = scwEle.childNodes; for (var i = 0; i < scwChildNodes.length; i++) if (scwChildNodes[i].nodeType == 3) { var scwDateValue = scwChildNodes[i].nodeValue.replace(/^\s+/, '').replace(/\s+$/, ''); if (scwDateValue.length > 0) { scwTriggerEle.scwTextNode = scwChildNodes[i]; scwTriggerEle.scwLength = scwChildNodes[i].nodeValue.length; break; } } } else { var scwDateValue = scwEle.value.replace(/^\s+/, '').replace(/\s+$/, ''); } // Set the language-dependent elements scwSetDefaultLanguage(); scwID('scwDragText').innerHTML = scwDrag; scwID('scwMonths').options.length = 0; for (var i = 0; i < scwArrMonthNames.length; i++) scwID('scwMonths').options[i] = new Option(scwArrMonthNames[i], scwArrMonthNames[i]); scwID('scwYears').options.length = 0; for (var i = 0; i < scwDropDownYears; i++) scwID('scwYears').options[i] = new Option((scwBaseYear + i), (scwBaseYear + i)); for (var i = 0; i < scwArrWeekInits.length; i++) scwID('scwWeekInit' + i).innerHTML = scwArrWeekInits[(i + scwWeekStart) % scwArrWeekInits.length]; if (scwID('scwFoot')) scwID('scwFoot').innerHTML = scwToday + ' ' + scwDateNow.scwFormat(scwDateDisplayFormat); if (scwDateValue.length == 0) {// If no value is entered and today is within the range, // use today's date, otherwise use the middle of the valid range. scwBlnFullInputDate = false; if ((new Date(scwBaseYear + scwDropDownYears, 0, 0)) < scwSeedDate || (new Date(scwBaseYear, 0, 1)) > scwSeedDate ) { scwSeedDate = new Date(scwBaseYear + Math.floor(scwDropDownYears / 2), 5, 1); } } else { function scwInputFormat() { var scwArrSeed = new Array(), scwArrInput = scwDateValue. split(new RegExp('[\\' + scwArrDelimiters. join('\\') + ']+', 'g')); // "Escape" all the user defined date delimiters above - // several delimiters will need it and it does no harm for // the others. // Strip any empty array elements (caused by delimiters) // from the beginning or end of the array. They will // still appear in the output string if in the output // format. if (scwArrInput[0] != null) { if (scwArrInput[0].length == 0) scwArrInput.splice(0, 1); if (scwArrInput[scwArrInput.length - 1].length == 0) scwArrInput.splice(scwArrInput.length - 1, 1); } scwBlnFullInputDate = false; switch (scwArrInput.length) {case 1: {// Year only entry scwArrSeed[0] = parseInt(scwArrInput[0], 10); // Year scwArrSeed[1] = '6'; // Month scwArrSeed[2] = 1; // Day break; } case 2: {// Year and Month entry scwArrSeed[0] = parseInt(scwArrInput[scwDateInputSequence. replace(/D/i, ''). search(/Y/i)], 10); // Year scwArrSeed[1] = scwArrInput[scwDateInputSequence. replace(/D/i, ''). search(/M/i)]; // Month scwArrSeed[2] = 1; // Day break; } case 3: {// Day Month and Year entry scwArrSeed[0] = parseInt(scwArrInput[scwDateInputSequence. search(/Y/i)], 10); // Year scwArrSeed[1] = scwArrInput[scwDateInputSequence. search(/M/i)]; // Month scwArrSeed[2] = parseInt(scwArrInput[scwDateInputSequence. search(/D/i)], 10); // Day scwBlnFullInputDate = true; break; } default: {// A stuff-up has led to more than three elements in // the date. scwArrSeed[0] = 0; // Year scwArrSeed[1] = 0; // Month scwArrSeed[2] = 0; // Day } } // These regular expressions validate the input date format // to the following rules; // Day 1-31 (optional zero on single digits) // Month 1-12 (optional zero on single digits) // or case insensitive name // Year One, Two or four digits // Months names are as set in the language-dependent // definitions and delimiters are set just below there var scwExpValDay = /^(0?[1-9]|[1-2]\d|3[0-1])$/, scwExpValMonth = new RegExp('^(0?[1-9]|1[0-2]|' + scwArrMonthNames.join('|') + ')$', 'i'), scwExpValYear = /^(\d{1,2}|\d{4})$/; // Apply validation and report failures if (scwExpValYear.exec(scwArrSeed[0]) == null || scwExpValMonth.exec(scwArrSeed[1]) == null || scwExpValDay.exec(scwArrSeed[2]) == null ) { if (scwShowInvalidDateMsg) alert(scwInvalidDateMsg + scwInvalidAlert[0] + scwDateValue + scwInvalidAlert[1]); scwBlnFullInputDate = false; scwArrSeed[0] = scwBaseYear + Math.floor(scwDropDownYears / 2); // Year scwArrSeed[1] = '6'; // Month scwArrSeed[2] = 1; // Day } // Return the Year in scwArrSeed[0] // Month in scwArrSeed[1] // Day in scwArrSeed[2] return scwArrSeed; } // Parse the string into an array using the allowed delimiters scwArrSeedDate = scwInputFormat(); // So now we have the Year, Month and Day in an array. // If the year is one or two digits then the routine assumes a // year belongs in the 21st Century unless it is less than 50 // in which case it assumes the 20th Century is intended. if (scwArrSeedDate[0] < 100) scwArrSeedDate[0] += (scwArrSeedDate[0] > 50) ? 1900 : 2000; // Check whether the month is in digits or an abbreviation if (scwArrSeedDate[1].search(/\d+/) != 0) { month = scwArrMonthNames.join('|').toUpperCase(). search(scwArrSeedDate[1].substr(0, 3). toUpperCase()); scwArrSeedDate[1] = Math.floor(month / 4) + 1; } scwSeedDate = new Date(scwArrSeedDate[0], scwArrSeedDate[1] - 1, scwArrSeedDate[2]); } // Test that we have arrived at a valid date if (isNaN(scwSeedDate)) { if (scwShowInvalidDateMsg) alert(scwInvalidDateMsg + scwInvalidAlert[0] + scwDateValue + scwInvalidAlert[1]); scwSeedDate = new Date(scwBaseYear + Math.floor(scwDropDownYears / 2), 5, 1); scwBlnFullInputDate = false; } else {// Test that the date is within range, // if not then set date to a sensible date in range. if ((new Date(scwBaseYear, 0, 1)) > scwSeedDate) { if (scwBlnStrict && scwShowOutOfRangeMsg) alert(scwOutOfRangeMsg); scwSeedDate = new Date(scwBaseYear, 0, 1); scwBlnFullInputDate = false; } else { if ((new Date(scwBaseYear + scwDropDownYears, 0, 0)) < scwSeedDate) { if (scwBlnStrict && scwShowOutOfRangeMsg) alert(scwOutOfRangeMsg); scwSeedDate = new Date(scwBaseYear + Math.floor(scwDropDownYears) - 1, 11, 1); scwBlnFullInputDate = false; } else { if (scwBlnStrict && scwBlnFullInputDate && (scwSeedDate.getDate() != scwArrSeedDate[2] || (scwSeedDate.getMonth() + 1) != scwArrSeedDate[1] || scwSeedDate.getFullYear() != scwArrSeedDate[0] ) ) { if (scwShowDoesNotExistMsg) alert(scwDoesNotExistMsg); scwSeedDate = new Date(scwSeedDate.getFullYear(), scwSeedDate.getMonth() - 1, 1); scwBlnFullInputDate = false; } } } } // Test the disabled dates for validity // Give error message if not valid. for (var i = 0; i < scwDisabledDates.length; i++) { if (!((typeof scwDisabledDates[i] == 'object') && (scwDisabledDates[i].constructor == Date))) { if ((typeof scwDisabledDates[i] == 'object') && (scwDisabledDates[i].constructor == Array)) { var scwPass = true;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -