⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 calendar.js

📁 这是一个关于java的JSP页面中使用象Swing组件的一个库文件.
💻 JS
字号:
function uiUtil_Calendar(optJsDate) {  this._super();  this.__updateListeners = new Array();  this.__date = (optJsDate == null) ? new Date() : new Date(optJsDate);}uiUtil_Calendar = uiUtil_Object.declareClass(uiUtil_Calendar, uiUtil_Object);uiUtil_Calendar.NUM_DAYS_IN_A_WEEK = 7;uiUtil_Calendar.NUM_MONTHS_IN_A_YEAR = 12;uiUtil_Calendar.INDEX_SUNDAY = 0;uiUtil_Calendar.INDEX_MONDAY = 1;uiUtil_Calendar.INDEX_TUESDAY = 2;uiUtil_Calendar.INDEX_WEDNESDAY = 3;uiUtil_Calendar.INDEX_THURSDAY = 4;uiUtil_Calendar.INDEX_FRIDAY = 5;uiUtil_Calendar.INDEX_SATURDAY = 6;uiUtil_Calendar.INDEX_JANUARY = 0;uiUtil_Calendar.INDEX_FEBRUARY = 1;uiUtil_Calendar.INDEX_MARCH = 2;uiUtil_Calendar.INDEX_APRIL = 3;uiUtil_Calendar.INDEX_MAY = 4;uiUtil_Calendar.INDEX_JUNE = 5;uiUtil_Calendar.INDEX_JULY = 6;uiUtil_Calendar.INDEX_AUGUST = 7;uiUtil_Calendar.INDEX_SEPTEMBER = 8;uiUtil_Calendar.INDEX_OCTOBER = 9;uiUtil_Calendar.INDEX_NOVEMBER = 10;uiUtil_Calendar.INDEX_DECEMBER = 11;uiUtil_Calendar.CODE_YEAR = "y";uiUtil_Calendar.CODE_MONTH = "M";uiUtil_Calendar.CODE_DAY = "d";uiUtil_Calendar.__SPECIAL_CHARS =    uiUtil_Calendar.CODE_YEAR +    uiUtil_Calendar.CODE_MONTH +    uiUtil_Calendar.CODE_DAY;uiUtil_Calendar.prototype.addUpdateListener = function(listener) {  this.__updateListeners.push(listener);};uiUtil_Calendar.prototype.toDate = function() {  return new Date(this.__date);};uiUtil_Calendar.prototype.fromDate = function(jsDate) {  this.__date = new Date(jsDate);  this.__notifyListeners();};uiUtil_Calendar.prototype.update = function(newYear, newMonth, newDay) {  this.__date.setDate(1);  this.__date.setYear(newYear);  this.__date.setMonth(newMonth);  this.__date.setDate(newDay);  this.__notifyListeners();  return this;};uiUtil_Calendar.prototype.setDay = function(newDay) {  this.__date.setDate(newDay);  this.__notifyListeners();  return this;};uiUtil_Calendar.prototype.setMonth = function(newMonth) {  this.__date.setMonth(newMonth);  this.__notifyListeners();  return this;};uiUtil_Calendar.prototype.setYear = function(newYear) {  this.__date.setYear(newYear);  this.__notifyListeners();  return this;};uiUtil_Calendar.prototype.incrementDay = function() {  return this.setDay(this.getDay() + 1);};uiUtil_Calendar.prototype.decrementDay = function() {  return this.setDay(this.getDay() - 1);};uiUtil_Calendar.prototype.incrementMonth = function() {  return this.setMonth(this.getMonth() + 1);};uiUtil_Calendar.prototype.decrementMonth = function() {  return this.setMonth(this.getMonth() - 1);};uiUtil_Calendar.prototype.incrementYear = function() {  return this.setYear(this.getYear() + 1);};uiUtil_Calendar.prototype.decrementYear = function() {  return this.setYear(this.getYear() - 1);};uiUtil_Calendar.prototype.__notifyListeners = function() {  for (var i = 0; i < this.__updateListeners.length; ++i) {    this.__updateListeners[i].dateUpdated(this);  }};uiUtil_Calendar.prototype.getDay = function() {  return this.__date.getDate();};uiUtil_Calendar.prototype.getMonth = function() {  return this.__date.getMonth();};uiUtil_Calendar.prototype.getYear = function() {  return this.__date.getFullYear();};uiUtil_Calendar.prototype.getFirstDayInMonth = function() {  var firstInMonth = new Date(this.__date);  firstInMonth.setDate(1);  return firstInMonth.getDay();};uiUtil_Calendar.prototype.getNumDaysInMonth = function() {  var numDays = new Array(12);  numDays[0]  = 31;  numDays[1]  = this.__isLeapYear()? 29 : 28;  numDays[2]  = 31;  numDays[3]  = 30;  numDays[4]  = 31;  numDays[5]  = 30;  numDays[6]  = 31;  numDays[7]  = 31;  numDays[8]  = 30;  numDays[9]  = 31;  numDays[10] = 30;  numDays[11] = 31;  return numDays[this.__date.getMonth()];};uiUtil_Calendar.prototype.__isLeapYear = function() {  var year = this.__date.getFullYear();  if ((year % 4 == 0 && year % 100 != 0) ||      year % 400 == 0) {    return true;  }  return false;};uiUtil_Calendar.prototype.format = function(format) {  var specialChars = uiUtil_Calendar.__SPECIAL_CHARS;  var newString = format;  for (var i = 0; i < specialChars.length; ++i) {    var regex = new RegExp("(" + specialChars.charAt(i) + "+)");    if (regex.test(format)) {      var specialCode = RegExp.$1;      var codeHandler = uiUtil_Calendar.__formats[specialCode];      if (codeHandler != null) {        newString = newString.replace(            specialCode, codeHandler.call(this));      }    }  }  return newString;};uiUtil_Calendar.__formats = new Array();uiUtil_Calendar.__formats["yyyy"] = function() {  return this.getYear();};uiUtil_Calendar.__formats["yy"] = function() {  var yearString = new String(this.getYear());  return yearString.substring(2);};uiUtil_Calendar.__formats["MM"] = function() {  var month = this.getMonth() + 1;  return (month < 10) ? "0" + month : month;};uiUtil_Calendar.__formats["dd"] = function() {  var day = this.getDay();  return (day < 10) ? "0" + day : day;};uiUtil_Calendar.createFromString = function(string, format) {  var regex = new uiUtil_Calendar.DateRegExp(format);  if (regex.__test(string)) {    var year = regex.__getYear();    var month = regex.__getMonth();    var day = regex.__getDay();    var calendar = new uiUtil_Calendar(new Date(year, month, day));    if (calendar.getDay() != day ||        calendar.getMonth() != month ||        calendar.getYear() != year) {      throw new uiUtil_CreateException("Invalid date value '" + string +          "'. " + year + "-" + month + "-" + day + " converted to: " +          calendar.getYear() + "-" + calendar.getMonth() + "-" + calendar.getDay());    }    return calendar;  }  throw new uiUtil_CreateException("Invalid date '" + string +      "' according to the format: " + format);};function uiUtil_Calendar$UpdateListener() {  this._super();}uiUtil_Calendar.UpdateListener =    uiUtil_Object.declareClass(uiUtil_Calendar$UpdateListener, uiUtil_Object);uiUtil_Calendar.UpdateListener.prototype.dateUpdated = function(date) {  alert("Date updated " + date.format("dd/MM/yyyy"));};function uiUtil_Calendar$DateRegExp(format) {  this._super();  this.__yearIndex = 0;  this.__monthIndex = 0;  this.__dayIndex = 0;  this.__currentIndex = 1;  this.__results = null;  this.__regex = new RegExp(this.__getRegexPatternFrom(format));}uiUtil_Calendar.DateRegExp =    uiUtil_Object.declareClass(uiUtil_Calendar$DateRegExp, uiUtil_Object);uiUtil_Calendar.DateRegExp.prototype.__getRegexPatternFrom = function(format) {  var pattern = "";  var currentChar = "";  var currentCount;  for (var i = 0; i < format.length; ++i) {    if (format.charAt(i) == currentChar) {      ++currentCount;    }    else {      if (currentChar != "") {        pattern += this.__generateDigitPattern(currentCount);      }      if (this.__isSpecialChar(format.charAt(i))) {        currentChar = format.charAt(i);        currentCount = 1;      }      else {        pattern += format.charAt(i);        currentChar = "";      }    }  }  if (currentChar != "") {      pattern += this.__generateDigitPattern(currentCount);  }  return pattern;};uiUtil_Calendar.DateRegExp.prototype.__generateDigitPattern = function(count) {  return "(\\d{" + count + "})";};uiUtil_Calendar.DateRegExp.prototype.__isSpecialChar = function(currentChar) {  switch (currentChar) {    case uiUtil_Calendar.CODE_YEAR :        this.__yearIndex = this.__currentIndex;        ++this.__currentIndex;        return true;    case uiUtil_Calendar.CODE_MONTH :        this.__monthIndex = this.__currentIndex;        ++this.__currentIndex;        return true;    case uiUtil_Calendar.CODE_DAY :        this.__dayIndex = this.__currentIndex;        ++this.__currentIndex;        return true;  }  return false;};uiUtil_Calendar.DateRegExp.prototype.__test = function(string) {  this.__results = this.__regex.exec(string);  return this.__results != null;};uiUtil_Calendar.DateRegExp.prototype.__getDay = function() {  return this.__results[this.__dayIndex];};uiUtil_Calendar.DateRegExp.prototype.__getMonth = function() {  return this.__results[this.__monthIndex] - 1;};uiUtil_Calendar.DateRegExp.prototype.__getYear = function() {  return this.__results[this.__yearIndex];};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -