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

📄 calendar.js

📁 原名JSPackager
💻 JS
📖 第 1 页 / 共 3 页
字号:
YAHOO.widget.DateMath = new function () {this.DAY = "D";this.WEEK = "W";this.YEAR = "Y";this.MONTH = "M";this.ONE_DAY_MS = 1000 * 60 * 60 * 24;this.add = function (date, field, amount) {var d = new Date(date.getTime());switch (field) {case this.MONTH:var newMonth = date.getMonth() + amount;var years = 0;if (newMonth < 0) {while (newMonth < 0) {newMonth += 12;years -= 1;}} else {if (newMonth > 11) {while (newMonth > 11) {newMonth -= 12;years += 1;}}}d.setMonth(newMonth);d.setFullYear(date.getFullYear() + years);break;case this.DAY:d.setDate(date.getDate() + amount);break;case this.YEAR:d.setFullYear(date.getFullYear() + amount);break;case this.WEEK:d.setDate(date.getDate() + (amount * 7));break;}return d;};this.subtract = function (date, field, amount) {return this.add(date, field, (amount * -1));};this.before = function (date, compareTo) {var ms = compareTo.getTime();if (date.getTime() < ms) {return true;} else {return false;}};this.after = function (date, compareTo) {var ms = compareTo.getTime();if (date.getTime() > ms) {return true;} else {return false;}};this.between = function (date, dateBegin, dateEnd) {if (this.after(date, dateBegin) && this.before(date, dateEnd)) {return true;} else {return false;}};this.getJan1 = function (calendarYear) {return new Date(calendarYear, 0, 1);};this.getDayOffset = function (date, calendarYear) {var beginYear = this.getJan1(calendarYear);var dayOffset = Math.ceil((date.getTime() - beginYear.getTime()) / this.ONE_DAY_MS);return dayOffset;};this.getWeekNumber = function (date, calendarYear, weekStartsOn) {date.setHours(12, 0, 0, 0);if (!weekStartsOn) {weekStartsOn = 0;}if (!calendarYear) {calendarYear = date.getFullYear();}var weekNum = -1;var jan1 = this.getJan1(calendarYear);var jan1Offset = jan1.getDay() - weekStartsOn;var jan1DayOfWeek = (jan1Offset >= 0 ? jan1Offset : (7 + jan1Offset));var endOfWeek1 = this.add(jan1, this.DAY, (6 - jan1DayOfWeek));endOfWeek1.setHours(23, 59, 59, 999);var month = date.getMonth();var day = date.getDate();var year = date.getFullYear();var dayOffset = this.getDayOffset(date, calendarYear);if (dayOffset < 0 || this.before(date, endOfWeek1)) {weekNum = 1;} else {weekNum = 2;var weekBegin = new Date(endOfWeek1.getTime() + 1);var weekEnd = this.add(weekBegin, this.WEEK, 1);while (!this.between(date, weekBegin, weekEnd)) {weekBegin = this.add(weekBegin, this.WEEK, 1);weekEnd = this.add(weekEnd, this.WEEK, 1);weekNum += 1;}}return weekNum;};this.isYearOverlapWeek = function (weekBeginDate) {var overlaps = false;var nextWeek = this.add(weekBeginDate, this.DAY, 6);if (nextWeek.getFullYear() != weekBeginDate.getFullYear()) {overlaps = true;}return overlaps;};this.isMonthOverlapWeek = function (weekBeginDate) {var overlaps = false;var nextWeek = this.add(weekBeginDate, this.DAY, 6);if (nextWeek.getMonth() != weekBeginDate.getMonth()) {overlaps = true;}return overlaps;};this.findMonthStart = function (date) {var start = new Date(date.getFullYear(), date.getMonth(), 1);return start;};this.findMonthEnd = function (date) {var start = this.findMonthStart(date);var nextMonth = this.add(start, this.MONTH, 1);var end = this.subtract(nextMonth, this.DAY, 1);return end;};this.clearTime = function (date) {date.setHours(0, 0, 0, 0);return date;};};YAHOO.widget.Calendar_Core = function (id, containerId, monthyear, selected) {if (arguments.length > 0) {this.init(id, containerId, monthyear, selected);}};YAHOO.widget.Calendar_Core.IMG_ROOT = (window.location.href.toLowerCase().indexOf("https") == 0 ? "https://a248.e.akamai.net/sec.yimg.com/i/" : "http://us.i1.yimg.com/us.yimg.com/i/");YAHOO.widget.Calendar_Core.DATE = "D";YAHOO.widget.Calendar_Core.MONTH_DAY = "MD";YAHOO.widget.Calendar_Core.WEEKDAY = "WD";YAHOO.widget.Calendar_Core.RANGE = "R";YAHOO.widget.Calendar_Core.MONTH = "M";YAHOO.widget.Calendar_Core.DISPLAY_DAYS = 42;YAHOO.widget.Calendar_Core.STOP_RENDER = "S";YAHOO.widget.Calendar_Core.prototype = {Config:null, parent:null, index:-1, cells:null, weekHeaderCells:null, weekFooterCells:null, cellDates:null, id:null, oDomContainer:null, today:null, renderStack:null, _renderStack:null, pageDate:null, _pageDate:null, minDate:null, maxDate:null, selectedDates:null, _selectedDates:null, shellRendered:false, table:null, headerCell:null};YAHOO.widget.Calendar_Core.prototype.init = function (id, containerId, monthyear, selected) {this.setupConfig();this.id = id;this.cellDates = new Array();this.cells = new Array();this.renderStack = new Array();this._renderStack = new Array();this.oDomContainer = document.getElementById(containerId);this.today = new Date();YAHOO.widget.DateMath.clearTime(this.today);var month;var year;if (monthyear) {var aMonthYear = monthyear.split(this.Locale.DATE_FIELD_DELIMITER);month = parseInt(aMonthYear[this.Locale.MY_MONTH_POSITION - 1]);year = parseInt(aMonthYear[this.Locale.MY_YEAR_POSITION - 1]);} else {month = this.today.getMonth() + 1;year = this.today.getFullYear();}this.pageDate = new Date(year, month - 1, 1);this._pageDate = new Date(this.pageDate.getTime());if (selected) {this.selectedDates = this._parseDates(selected);this._selectedDates = this.selectedDates.concat();} else {this.selectedDates = new Array();this._selectedDates = new Array();}this.wireDefaultEvents();this.wireCustomEvents();};YAHOO.widget.Calendar_Core.prototype.wireDefaultEvents = function () {this.doSelectCell = function (e, cal) {var cell = this;var index = cell.index;var d = cal.cellDates[index];var date = new Date(d[0], d[1] - 1, d[2]);if (!cal.isDateOOM(date) && !YAHOO.util.Dom.hasClass(cell, cal.Style.CSS_CELL_RESTRICTED) && !YAHOO.util.Dom.hasClass(cell, cal.Style.CSS_CELL_OOB)) {if (cal.Options.MULTI_SELECT) {var link = cell.getElementsByTagName("A")[0];link.blur();var cellDate = cal.cellDates[index];var cellDateIndex = cal._indexOfSelectedFieldArray(cellDate);if (cellDateIndex > -1) {cal.deselectCell(index);} else {cal.selectCell(index);}} else {var link = cell.getElementsByTagName("A")[0];link.blur();cal.selectCell(index);}}};this.doCellMouseOver = function (e, cal) {var cell = this;var index = cell.index;var d = cal.cellDates[index];var date = new Date(d[0], d[1] - 1, d[2]);if (!cal.isDateOOM(date) && !YAHOO.util.Dom.hasClass(cell, cal.Style.CSS_CELL_RESTRICTED) && !YAHOO.util.Dom.hasClass(cell, cal.Style.CSS_CELL_OOB)) {YAHOO.util.Dom.addClass(cell, cal.Style.CSS_CELL_HOVER);}};this.doCellMouseOut = function (e, cal) {YAHOO.util.Dom.removeClass(this, cal.Style.CSS_CELL_HOVER);};this.doNextMonth = function (e, cal) {cal.nextMonth();};this.doPreviousMonth = function (e, cal) {cal.previousMonth();};};YAHOO.widget.Calendar_Core.prototype.wireCustomEvents = function () {};YAHOO.widget.Calendar_Core.prototype.setupConfig = function () {this.Config = new Object();this.Config.Style = {CSS_ROW_HEADER:"calrowhead", CSS_ROW_FOOTER:"calrowfoot", CSS_CELL:"calcell", CSS_CELL_SELECTED:"selected", CSS_CELL_RESTRICTED:"restricted", CSS_CELL_TODAY:"today", CSS_CELL_OOM:"oom", CSS_CELL_OOB:"previous", CSS_HEADER:"calheader", CSS_HEADER_TEXT:"calhead", CSS_WEEKDAY_CELL:"calweekdaycell", CSS_WEEKDAY_ROW:"calweekdayrow", CSS_FOOTER:"calfoot", CSS_CALENDAR:"yui-calendar", CSS_CONTAINER:"yui-calcontainer", CSS_2UPWRAPPER:"yui-cal2upwrapper", CSS_NAV_LEFT:"calnavleft", CSS_NAV_RIGHT:"calnavright", CSS_CELL_TOP:"calcelltop", CSS_CELL_LEFT:"calcellleft", CSS_CELL_RIGHT:"calcellright", CSS_CELL_BOTTOM:"calcellbottom", CSS_CELL_HOVER:"calcellhover", CSS_CELL_HIGHLIGHT1:"highlight1", CSS_CELL_HIGHLIGHT2:"highlight2", CSS_CELL_HIGHLIGHT3:"highlight3", CSS_CELL_HIGHLIGHT4:"highlight4"};this.Style = this.Config.Style;this.Config.Locale = {MONTHS_SHORT:["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], MONTHS_LONG:["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"], WEEKDAYS_1CHAR:["S", "M", "T", "W", "T", "F", "S"], WEEKDAYS_SHORT:["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"], WEEKDAYS_MEDIUM:["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], WEEKDAYS_LONG:["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"], DATE_DELIMITER:",", DATE_FIELD_DELIMITER:"/", DATE_RANGE_DELIMITER:"-", MY_MONTH_POSITION:1, MY_YEAR_POSITION:2, MD_MONTH_POSITION:1, MD_DAY_POSITION:2, MDY_MONTH_POSITION:1, MDY_DAY_POSITION:2, MDY_YEAR_POSITION:3};this.Locale = this.Config.Locale;this.Config.Options = {MULTI_SELECT:false, SHOW_WEEKDAYS:true, START_WEEKDAY:0, SHOW_WEEK_HEADER:false, SHOW_WEEK_FOOTER:false, HIDE_BLANK_WEEKS:false, NAV_ARROW_LEFT:YAHOO.widget.Calendar_Core.IMG_ROOT + "us/tr/callt.gif", NAV_ARROW_RIGHT:YAHOO.widget.Calendar_Core.IMG_ROOT + "us/tr/calrt.gif"};this.Options = this.Config.Options;this.customConfig();if (!this.Options.LOCALE_MONTHS) {this.Options.LOCALE_MONTHS = this.Locale.MONTHS_LONG;}if (!this.Options.LOCALE_WEEKDAYS) {this.Options.LOCALE_WEEKDAYS = this.Locale.WEEKDAYS_SHORT;}if (this.Options.START_WEEKDAY > 0) {for (var w = 0; w < this.Options.START_WEEKDAY; ++w) {this.Locale.WEEKDAYS_SHORT.push(this.Locale.WEEKDAYS_SHORT.shift());this.Locale.WEEKDAYS_MEDIUM.push(this.Locale.WEEKDAYS_MEDIUM.shift());this.Locale.WEEKDAYS_LONG.push(this.Locale.WEEKDAYS_LONG.shift());}}};YAHOO.widget.Calendar_Core.prototype.customConfig = function () {};YAHOO.widget.Calendar_Core.prototype.buildMonthLabel = function () {var text = this.Options.LOCALE_MONTHS[this.pageDate.getMonth()] + " " + this.pageDate.getFullYear();return text;};YAHOO.widget.Calendar_Core.prototype.buildDayLabel = function (workingDate) {var day = workingDate.getDate();return day;};YAHOO.widget.Calendar_Core.prototype.buildShell = function () {this.table = document.createElement("TABLE");this.table.cellSpacing = 0;YAHOO.widget.Calendar_Core.setCssClasses(this.table, [this.Style.CSS_CALENDAR]);this.table.id = this.id;this.buildShellHeader();this.buildShellBody();this.buildShellFooter();YAHOO.util.Event.addListener(window, "unload", this._unload, this);};YAHOO.widget.Calendar_Core.prototype.buildShellHeader = function () {var head = document.createElement("THEAD");var headRow = document.createElement("TR");var headerCell = document.createElement("TH");var colSpan = 7;if (this.Config.Options.SHOW_WEEK_HEADER) {this.weekHeaderCells = new Array();colSpan += 1;}if (this.Config.Options.SHOW_WEEK_FOOTER) {this.weekFooterCells = new Array();colSpan += 1;}headerCell.colSpan = colSpan;YAHOO.widget.Calendar_Core.setCssClasses(headerCell, [this.Style.CSS_HEADER_TEXT]);this.headerCell = headerCell;headRow.appendChild(headerCell);head.appendChild(headRow);if (this.Options.SHOW_WEEKDAYS) {var row = document.createElement("TR");var fillerCell;YAHOO.widget.Calendar_Core.setCssClasses(row, [this.Style.CSS_WEEKDAY_ROW]);if (this.Config.Options.SHOW_WEEK_HEADER) {fillerCell = document.createElement("TH");YAHOO.widget.Calendar_Core.setCssClasses(fillerCell, [this.Style.CSS_WEEKDAY_CELL]);row.appendChild(fillerCell);}for (var i = 0; i < this.Options.LOCALE_WEEKDAYS.length; ++i) {var cell = document.createElement("TH");YAHOO.widget.Calendar_Core.setCssClasses(cell, [this.Style.CSS_WEEKDAY_CELL]);cell.innerHTML = this.Options.LOCALE_WEEKDAYS[i];row.appendChild(cell);}if (this.Config.Options.SHOW_WEEK_FOOTER) {fillerCell = document.createElement("TH");YAHOO.widget.Calendar_Core.setCssClasses(fillerCell, [this.Style.CSS_WEEKDAY_CELL]);row.appendChild(fillerCell);}head.appendChild(row);}this.table.appendChild(head);};YAHOO.widget.Calendar_Core.prototype.buildShellBody = function () {this.tbody = document.createElement("TBODY");for (var r = 0; r < 6; ++r) {var row = document.createElement("TR");for (var c = 0; c < this.headerCell.colSpan; ++c) {var cell;if (this.Config.Options.SHOW_WEEK_HEADER && c === 0) {cell = document.createElement("TH");this.weekHeaderCells[this.weekHeaderCells.length] = cell;} else {if (this.Config.Options.SHOW_WEEK_FOOTER && c == (this.headerCell.colSpan - 1)) {cell = document.createElement("TH");this.weekFooterCells[this.weekFooterCells.length] = cell;} else {cell = document.createElement("TD");this.cells[this.cells.length] = cell;YAHOO.widget.Calendar_Core.setCssClasses(cell, [this.Style.CSS_CELL]);YAHOO.util.Event.addListener(cell, "click", this.doSelectCell, this);YAHOO.util.Event.addListener(cell, "mouseover", this.doCellMouseOver, this);YAHOO.util.Event.addListener(cell, "mouseout", this.doCellMouseOut, this);}}row.appendChild(cell);}this.tbody.appendChild(row);}this.table.appendChild(this.tbody);};YAHOO.widget.Calendar_Core.prototype.buildShellFooter = function () {};YAHOO.widget.Calendar_Core.prototype.renderShell = function () {this.oDomContainer.appendChild(this.table);this.shellRendered = true;};YAHOO.widget.Calendar_Core.prototype.render = function () {if (!this.shellRendered) {this.buildShell();this.renderShell();}this.resetRenderers();this.cellDates.length = 0;var workingDate = YAHOO.widget.DateMath.findMonthStart(this.pageDate);this.renderHeader();this.renderBody(workingDate);this.renderFooter();this.onRender();};YAHOO.widget.Calendar_Core.prototype.renderHeader = function () {this.headerCell.innerHTML = "";var headerContainer = document.createElement("DIV");headerContainer.className = this.Style.CSS_HEADER;headerContainer.appendChild(document.createTextNode(this.buildMonthLabel()));this.headerCell.appendChild(headerContainer);};YAHOO.widget.Calendar_Core.prototype.renderBody = function (workingDate) {this.preMonthDays = workingDate.getDay();if (this.Options.START_WEEKDAY > 0) {this.preMonthDays -= this.Options.START_WEEKDAY;}if (this.preMonthDays < 0) {this.preMonthDays += 7;}this.monthDays = YAHOO.widget.DateMath.findMonthEnd(workingDate).getDate();this.postMonthDays = YAHOO.widget.Calendar_Core.DISPLAY_DAYS - this.preMonthDays - this.monthDays;workingDate = YAHOO.widget.DateMath.subtract(workingDate, YAHOO.widget.DateMath.DAY, this.preMonthDays);var weekRowIndex = 0;for (var c = 0; c < this.cells.length; ++c) {var cellRenderers = new Array();var cell = this.cells[c];this.clearElement(cell);cell.index = c;cell.id = this.id + "_cell" + c;this.cellDates[this.cellDates.length] = [workingDate.getFullYear(), workingDate.getMonth() + 1, workingDate.getDate()];if (workingDate.getDay() == this.Options.START_WEEKDAY) {var rowHeaderCell = null;var rowFooterCell = null;if (this.Options.SHOW_WEEK_HEADER) {rowHeaderCell = this.weekHeaderCells[weekRowIndex];this.clearElement(rowHeaderCell);}if (this.Options.SHOW_WEEK_FOOTER) {rowFooterCell = this.weekFooterCells[weekRowIndex];this.clearElement(rowFooterCell);}if (this.Options.HIDE_BLANK_WEEKS && this.isDateOOM(workingDate) && !YAHOO.widget.DateMath.isMonthOverlapWeek(workingDate)) {continue;} else {if (rowHeaderCell) {this.renderRowHeader(workingDate, rowHeaderCell);}if (rowFooterCell) {this.renderRowFooter(workingDate, rowFooterCell);}}}var renderer = null;if (workingDate.getFullYear() == this.today.getFullYear() && workingDate.getMonth() == this.today.getMonth() && workingDate.getDate() == this.today.getDate()) {cellRenderers[cellRenderers.length] = this.renderCellStyleToday;}if (this.isDateOOM(workingDate)) {cellRenderers[cellRenderers.length] = this.renderCellNotThisMonth;} else {for (var r = 0; r < this.renderStack.length; ++r) {var rArray = this.renderStack[r];var type = rArray[0];var month;var day;var year;switch (type) {case YAHOO.widget.Calendar_Core.DATE:month = rArray[1][1];day = rArray[1][2];year = rArray[1][0];if (workingDate.getMonth() + 1 == month && workingDate.getDate() == day && workingDate.getFullYear() == year) {renderer = rArray[2];this.renderStack.splice(r, 1);}break;case YAHOO.widget.Calendar_Core.MONTH_DAY:month = rArray[1][0];day = rArray[1][1];

⌨️ 快捷键说明

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