首頁 > 後端開發 > php教程 > PHP+Javascript php+javascript的日曆控件

PHP+Javascript php+javascript的日曆控件

WBOY
發布: 2016-07-29 08:41:13
原創
898 人瀏覽過

複製程式碼 程式碼如下:




js 日曆

/* 版權所有Mihai Bazon,2002- 2005 | www.bazon.net/mishoo
* ------------------------------------- ----- --------------------
*
* DHTML 行事曆,版本1.0 「它再發生」
*
* 詳細資訊和最新版本位於:
* www.dynarch.com/projects/calendar
*
* 該腳本由Dynarch.com 開發。請造訪我們的網站 www.dynarch.com。
*
* 腳本根據 GNU Lesser General Public License 分發。
* 在此閱讀完整的授權文字:http://www.gnu.org/licenses/lgpl.html
*/
// $Id: calendar.js,v 1.51 2005/ 03/07 16:44:31 mishoo Exp $
/**Calendar 物件建構函數。*/
Calendar = function (firstDayOfWeek, dateStr, onSelected, onClose) {
//成員變數
. activeDiv = null ;
this.currentDateEl = null;
this.getDateStatus = null;
this.getDateToolTip = null;
this.getDateText = null;
ip = null;
this.getDateText = null;
this.time. 🎜>this.onSelected = onSelected ||無效的;
this.onClose = onClose ||無效的;
this.dragging = false;
this.hidden = false;
this.minminY. 1970;
this.maxYear = 2050;
this.dateFormat = Calendar._TT["DEF_DATE_FORMAT"];
this.ttDateFormat = Calendar._TT["TT_DATE_FORMAT"]; true;
this.weekNumbers = true;
this.firstDayOfWeek = typeof firstDayOfWeek == "number" ? FirstDayOfWeek : 日曆._FD; // 0 表示週日,1 表示週一,等等
this. showsOtherMonths = false;
this.dateStr = dateStr;
this.ar_days = null;
this.showsTime = false;
this.time24 = true;
this.yearStep = 2; 🎜>this.hiliteToday = true;
this.multiple = null;
// HTML 元素
this.table = null;
this.element = null;
this.tbody = null;
this.element = null;
this.tbody = null ;
this.firstdayname = null;
// 組合框
this.monthsCombo = null;
this.yearsCombo = null;
this.hilitedMonth = null;
this.Month = null;
this.hilitedYear = null;
this.activeYear = null;
// 訊息
this.dateClicked = false;
// 一次初始化
if (typeClicked = false;
// 一次初始化
if (type Calendar._SDN == "undefined") {
// 短日名稱表
if (typeof Calendar._SDN_len == "undefined")
日曆._SDN_len = 3;
var ar = new Array();
for (var i = 8; i > 0;) {
ar[--i] = Calendar._DN[i].substr(0, Calendar._SDN_len);
}
日曆._SDN = ar;
// 短月份名稱表
if (typeof Calendar._SMN_len == "undefined")
Calendar._SMN_len = 3;
ar = new Array( );
for (var i = 12; i > 0;) {
ar[--i] = Calendar._MN[i].substr(0, Calendar._SMN_len);
}
日曆._SMN = ar;
}
};
// ** 常數
/// “靜態”,事件處理程序所需。
日曆._C = null;
/// 偵測「網頁瀏覽器」的特殊情況
Calendar.is_ie = ( /msie/i.test(navigator.userAgent) &&
!/opera /i.test(navigator.userAgent) );
Calendar.is_ie5 = ( Calendar.is_ie && /msie 5.0/i.test(navigator.userAgent) );
/// 偵測Opera 瀏覽器
Calendar.is_opera = /opera/i.test(navigator.userAgent);
/// 偵測基於KHTML 的瀏覽器
Calendar.is_khtml = /Konqueror|Safari|KHTML/i.test(navigator.userAgent) ;
// 開始:實用函數;請注意,在某些時候這些可能會被移到單獨的
// 函式庫中。
Calendar.getAbsolutePos = function(el) {
var SL = 0, ST = 0;
var is_div = /^div$/i.test(el.tagName);
if (is_div && el.scrollLeft)
SL = el.scrollLeft;
if (is_div && el.scrollTop)
ST = el.scrollTop;
var r = { x: el.offsetLeft - SL, yft - SL : el.offsetTop - ST };
if (el.offsetParent) {
var tmp = this.getAbsolutePos(el.offsetParent);
r.x += tmp.x;
r.y += tmpr.y += tmpr.y += tmpr.y += tmpr.y += tmpr.y += tmpr.y += tmpr.y += tmpr.y += tmpr.y += .y;
}
回傳r;
};
Calendar.isRelated = function (el, evt) {
var related = evt.latedTarget;
if (!lated) {
var type = evt.type;
if (type == "mouseover") {
相關= evt.fromElement;
} else if (type == "mouseout") {
相關= evt.toElement;
}
}
while (相關) {
if (相關== el) {
回傳true;
}
相關=相關.parentNode;
}
回傳false;
};
Calendar.removeClass = function(el, className) {
if (!(el && el.className)) {
return;
}
var cls = el.className.split(" ");
var ar = new Array();
for (var i = cls.length; i > 0;) {
if (cls[--i] != className) {
ar[ar.length] = cls[i];
}
}
el.className = ar.join (" ");
};
Calendar.addClass = function(el, className) {
Calendar.removeClass(el, className);
el.className += " " + className;
};
// FIXME:以下兩個功能完全糟糕,沒用,應該立即更換。
Calendar.getElement = function(ev) {
var f = Calendar.is_ie ? window.event.srcElement : ev.currentTarget;
while (f.nodeType != 1 || /^div$/ i.test(f.tagName)) f = f.parentNode; 返回f; };
Calendar.getTargetElement = function(ev) {
var f = Calendar.is_ie ? window.event.srcElement : ev.target;
while (f.nodeType != 1)
f = f.parentNode;
返回f;
};
Calendar.stopEvent = function(ev) {
ev || (ev = 視窗.事件);
if (Calendar.is_ie) {
ev.cancelBubble = true;
ev.returnValue = false;
} else {
ev.preventDefault();
ev.stopPropagation();
}
回傳 false;
};
Calendar.addEvent = function(el, evname, func) {
if (el.attachEvent) { // IE
el.attachEvent (“on”+evname,func);
} else if (el.addEventListener) { // Gecko / W3C
el.addEventListener(evname, func, true);
} else {
el["on" + evname] = func;
}
};
Calendar.removeEvent = function(el, evname, func) {
if (el.detachEvent) { // IE
el.detachEvent("on" + evname, func);
} else if (el.removeEventListener) { // Gecko / W3C
el.removeEventListener(evname, func, true);
} else {
el["on" + evname] = null;
}
};
Calendar.createElement = function(type, Parent) {
var el = null;
if (document.createElementNS) {
// 使用命名空間; 🎜>el = document.createElementNS(" http://www.w3.org/1999/xhtml", type);
} else {
el = document.createElement(type);
}
if (typeof Parent != "undefined") {
parent.appendChild(el);
}
回傳 el;
};
// 結束:實用函數
// 開始:日曆靜態函數
/**內部-新增一組事件以使某些元素表現得像按鈕。*/
addEvent(el, "mouseover", dayMouseOver);
addEvent(el, "mousedown", dayMouseDown);
addEvent(el, "mouseout", dayMouseOut);
if (is_ie) {
addEvent(el, "dblclick", dayMouseDblClick);
el.setAttribute("不可選擇", true);
}
}
};
Calendar.findMonth = function(el) {
if (typeof el.month != "undefined") {
return el;
} else if (typeof el.parentNode.month != "undefined") {
return el.parentNode;
}
回空;
};
Calendar.findYear = function(el) {
if (typeof el.year != "undefined") {
return el;
} else if (typeof el.parentNode.year != "undefined") {
return el.parentNode;
}
回空:
};
Calendar.showMonthsCombo = function () {
var cal = Calendar._C;
if (!cal) {
回傳 false;
}
var image = image;
var cd = cal.activeDiv;
var mc = cal.monthsCombo;
if (cal.hilitedMonth) {
Calendar.removeClass(cal.hilitedMonth, "hilite");
}
if (cal.activeMonth) {
Calendar.removeClass(cal.activeMonth, "active");
}
var mon = cal.monthsCombo.getElementsByTagName("div")[cal.date.getMonth()];
Calendar.addClass(myself, "active");
cal.activeMonth = 週一;
var s = mc.style;
s.display = "block";
if (cd.navtype s.left = cd.offsetLeft + "px";
else {
var mcw = mc.offsetWidth;
if (typeof mcw == "undefined")
// Konqueror 腦死技術
mcw = 50;
s.left = (cd.offsetLeft + cd.offsetWidth - mcw) + "px";
}
s.top = (cd.offsetTop + cd.offsetHeight) + "px";
};
Calendar.showYearsCombo = function (fwd) {
var image = Calendar._C;
if (!cal) {
回傳 false;
}
var image = image;
var cd = cal.activeDiv;
var yc = cal.yearsCombo;
if (cal.hilitedYear) {
Calendar.removeClass(cal.hilitedYear, "hilite");
}
if (cal.activeYear) {
Calendar.removeClass(cal.activeYear, "active");
}
cal.activeYear = null;
var Y = cal.date.getFullYear() + (fwd ? 1 : -1);
var yr = yc.firstChild;
var show = false;
for (var i = 12; i > 0; --i) {
if (Y >= cal.minYear && Y yr.innerHTML = Y ;
yr.year = Y;
yr.style.display = "block";
顯示=真;
} else {
yr.style.display = "none";
}
yr = yr.nextSibling;
Y += 轉發 ? image.yearStep : -image.yearStep;
}
if (show) {
var s = yc.style;
s.display = "block";
if (cd.navtype s.left = cd.offsetLeft + "px";
else {
var ycw = yc.offsetWidth;
if (typeof ycw == "undefined")
// Konqueror 腦死技術
ycw = 50;
s.left = (cd.offsetLeft + cd.offsetWidth - ycw) + "px";
}
s.top = (cd.offsetTop + cd.offsetHeight) + "px";
}
};
// 事件處理程序
Calendar.tableMouseUp = function(ev) {
var cal = Calendar._C;
if (!cal) {
回傳 false;
}
if (cal.timeout) {
clearTimeout(cal.timeout);
}
var el = cal.activeDiv;
if (!el) {
回傳 false;
}
var target = Calendar.getTargetElement(home);
首頁|| (ev = 視窗.事件);
Calendar.removeClass(el, "active");
if (target == el || target.parentNode == el) {
Calendar.cellClick(el, home);
}
var mon = Calendar.findMonth(target);
var 日期 = null;
if (mon) {
date = new Date(cal.date);
if (mon.month != date.getMonth()) {
date.setMonth(mon.month);
cal.setDate(日期);
cal.dateClicked = false;
cal.callHandler();
}
} else {
varyear = Calendar.findYear(target);
if (年份) {
date = new Date(cal.date);
if (year.year != date.getFullYear()) {
date.setFullYear(year.year);
cal.setDate(日期);
cal.dateClicked = false;
cal.callHandler();
}
}
}
with (日曆) {
removeEvent(document, "mouseup", tableMouseUp);
removeEvent(document, "mouseover", tableMouseOver);
removeEvent(document, "mousemove", tableMouseOver);
cal._hideCombos();
_C = null;
返回stopEvent(ev);
}
};
Calendar.tableMouseOver = function (ev) {
var cal = Calendar._C;
if (!cal) {
回傳;
}
var el = cal.activeDiv;
var target = Calendar.getTargetElement(ev);
if (target == el || target.parentNode == el) {
Calendar.addClass(el, "hilite active");
Calendar.addClass(el.parentNode, "rowhilite");
} else {
if (typeof el.navtype == "未定義" || (el.navtype != 50 && (el.navtype == 0 || Math.abs(el.navtype) > 2 ) )))
Calendar.removeClass(el, "active");
Calendar.removeClass(el, "hilite");
Calendar.removeClass(el.parentNode, "rowhilite");
}
ev || (ev = 視窗事件);
if (el.navtype == 50 && target != el) {
var pos = Calendar.getAbsolutePos(el);
var w = el.offsetWidth;
var x = ev.clientX;
var dx;
var 減少 = true;
if (x > pos.x + w) {
dx = x - pos.x - w;
減少=假;
} else
dx = pos.x - x;
如果 (dx var range = el._range;
var current = el._current;
var count = Math.floor(dx / 10) % range.length;
for (var i = range.length; --i >= 0;)
if (range[i] == current)
break;
while (count-- > 0)
if (減少) {
if (--i i = range.length - 1;
} else if ( ++i >= range.length )
i = 0;
var newval = range[i];
el.innerHTML = newval;
cal.onUpdateTime();
}
var mon = Calendar.findMonth(target);
if (mon) {
if (mon.month != cal.date.getMonth()) {
if (cal.hilitedMonth) {
Calendar.removeClass(cal.hilitedMonth, "hilite 」);
}
Calendar.addClass(mon, "hilite");
cal.hilitedMonth = 週一;
} else if (cal.hilitedMonth) {
Calendar.removeClass(cal .hilitedMonth, "hilite");
}
} else {
if (cal.hilitedMonth) {
Calendar.removeClass(cal.hilitedMonth, "hilite"); >varyear = Calendar.findYear (target);
if (year) {
if (year.year != cal.date.getFullYear()) {
if (cal.hilitedYear) {
Calendar.removeClass(cal. hilitedYear, "hilite 」);
}
Calendar.addClass(year, "hilite");
cal.hilitedYear = 年;
} else if (cal.hilitedYear ) {
Calendararararcal. .removeClass(cal.hilitedYear, "hilite");
}
} else if (cal.hilitedYear) {
Calendar.removeClass(cal.hilitedYear, "hilite");
}
}
>}
return Calendar.stopEvent(ev)
};
Calendar.tableMouseDown = function (ev) {
if (Calendar.getTargetElement(ev) == Calendar); .getElement(ev) ) {
return Calendar.stopEvent(ev);
}
};
Calendar.calDragIt = function (ev) {
var cal = Calendar._C;
if (!(cal && cal.dragging)) {
回傳 false;
}
var posX;
var posY;
if (Calendar.is_ie) {
posY = window.event.clientY + document.body.scrollTop;
posX = window.event.clientX + document.body.scrollLeft;
} else {
posX = ev.pageX;
posY = ev.pageY;
}
cal.hideShowCovered();
var st = cal.element.style;
st.left = (posX - cal.xOffs) + "px";
st.top = (posY - cal.yOffs) + "px";
return Calendar.stopEvent(ev);
};
Calendar.calDragEnd = function (ev) {
var cal = Calendar._C;
if (!cal) {
回傳 false;
}
cal.dragging = false;
with (Calendar) {
removeEvent(document, "mousemove", calDragIt);
removeEvent(document, "mouseup", calDragEnd);
tableMouseUp(ev);
}
cal.hideShowCovered();
};
Calendar.dayMouseDown = function(ev) {
var el = Calendar.getElement(ev);
if (el.disabled) {
回傳 false;
}
var cal = el.calendar;
cal.activeDiv = el;
日曆._C = cal;
if (el.navtype != 300) with (日曆) {
if (el.navtype == 50) {
el._current = el.innerHTML;
addEvent(document, "mousemove", tableMouseOver);
} else
addEvent(document, Calendar.is_ie5 ? "mousemove" : "mouseover", tableMouseOver);
addClass(el, "hilite active");
addEvent(document, "mouseup", tableMouseUp);
} else if (cal.isPopup) {
cal._dragStart(ev);
}
if (el.navtype == -1 || el.navtype == 1) {
if (cal.timeout)clearTimeout(cal.timeout);
cal.timeout = setTimeout("Calendar.showMonthsCombo()", 250);
}else if (el.navtype == -2 || el.navtype == 2) {
if (cal.timeout)clearTimeout(cal.timeout);
cal.timeout = setTimeout((el.navtype > 0) ? "Calendar.showYearsCombo(true)" : "Calendar.showYearsCombo(false)", 250);
} else {
cal.timeout = null;
}
return Calendar.stopEvent(ev);
};
Calendar.dayMouseDblClick = function(ev) {
Calendar.cellClick(Calendar.getElement(ev), ev || window.event);
if (Calendar.is_ie) {
document.selection.empty();
}
};
Calendar.dayMouseOver = function(ev) {
var el = Calendar.getElement(ev);
if (Calendar.isRelated(el, ev) || Calendar._C || el.disabled) {
回傳 false;
}
if (el.ttip) {
if (el.ttip.substr(0, 1) == "_") {
el.ttip = el.caldate.print(el .calendar.ttDateFormat) + el.ttip.substr(1);
}
el.calendar.tooltips.innerHTML = el.ttip;
}
if (el.navtype != 300) {
Calendar.addClass(el, "hilite");
if (el.caldate) {
Calendar.addClass(el.parentNode, "rowhilite");
}
}
return Calendar.stopEvent(ev);
};
Calendar.dayMouseOut = function(ev) {
with (Calendar) {
var el = getElement(ev);
if (isRelated(el, ev) || _C || el.disabled)
回傳 false;
removeClass(el, "hilite");
if (el.caldate)
removeClass(el.parentNode, "rowhilite");
if (el.calendar)
el.calendar.tooltips.innerHTML = _TT["SEL_DATE"];
返回stopEvent(ev);
}
};
/**
* 通用的「點擊」處理程序 :) 處理此
* 日曆中定義的所有類型的按鈕。
*/
Calendar.cellClick = function(el, ev) {
var cal = el.calendar;
var 關閉 = false;
var newdate = false;
var 日期 = null;
if (typeof el.navtype == "undefined") {
if (cal.currentDateEl) {
Calendar.removeClass(cal.currentDateEl, "selected");
Calendar.addClass(el, "已選擇");
結束 = (cal.currentDateEl == el);
if (! opening) {
cal.currentDateEl = el;
}
}
cal.date.setDateOnly(el.caldate);
日期 = cal.date;
var other_month = !(cal.dateClicked = !el.otherMonth);
if (!other_month && !cal.currentDateEl)
cal._toggleMultipleDate(new Date(date));
其他
newdate = !el.disabled;
// 點擊了日期
if (other_month)
cal._init(cal.firstDayOfWeek, date);
} else {
if (el.navtype == 200) {
Calendar.removeClass(el, "hilite");
cal.callCloseHandler();
回傳;
}
date = new Date(cal.date);
if (el.navtype == 0)
date.setDateOnly(new Date()); // 今天
// 取消單擊“今天”,否則我們假設沒有單擊任何日期,因此
// 在單擊模式下
// 知道時,選定的處理程序將不會關閉日曆。
cal.dateClicked = false;
var 年 = date.getFullYear();
var mon = date.getMonth();
function setMonth(m) {
var day = date.getDate();
var max = date.getMonthDays(m);
if (day > max) {
date.setDate(max);
}
date.setMonth(m);
};
switch (el.navtype) {
case 400:
Calendar.removeClass(el, "hilite");
var text = Calendar._TT["關於"];
if (typeof text != "undefined") {
text += cal.showsTime ?日曆._TT["ABOUT_TIME"] : "";
} else {
// FIXME:這應該在lang文件更新後立即刪除!了解這種語言並且您很扁,請更新" +
"“lang”子目錄中的相應文件匹配calendar-en.jsn" +
" 將其發送回以將其納入分發版;-)nn" +
"謝謝! ;
返回;
情況-2:
if (year > cal.minYear) {
date.setFullYear(year - 1);
}
休息;
情況-1:
if (mon > 0) {
setMonth(mon - 1);
} else if (year--> cal.minYear) {
date.setFullYear(year);
setMonth(11);
}
休息;
情況1:
if (mon setMonth(mon + 1);
} else if (year date.setFullYear(year + 1);
setMonth(0);
}
休息;
情況2:
if (year date.setFullYear(year + 1);
}
休息;
案例100:
cal.setFirstDayOfWeek(el.fdow);
回傳;
案例 50:
var range = el._range;
var current = el.innerHTML;
for (var i = range.length; --i >= 0;)
if (range[i] == current)
break;
if (ev && ev.shiftKey) {
if (--i i = range.length - 1;
} else if ( ++i >= range.length )
i = 0;
var newval = range[i];
el.innerHTML = newval;
cal.onUpdateTime();
回傳;
案例0:
//今天將帶我們到這裡
if ((typeof cal.getDateStatus == "function") &&
cal.getDateStatus(date, date ) .getFullYear(), date. getMonth(), date.getDate())) {
回傳 false;
}
休息;
}
if (!date.equalsTo(cal.date)) {
cal.setDate(date);
newdate = true;
} else if (el.navtype == 0)
newdate = closing = true;
}
if (newdate) {
ev && cal.callHandler();
}
if (closing) {
Calendar.removeClass(el, "hilite");
ev && cal.callCloseHandler();
}
};
// END: CALENDAR STATIC FUNCTIONS
// BEGIN: CALENDAR OBJECT FUNCTIONS
/**
* This function creates the calendar inside the given parent. If _par is
* null than it creates a popup calendar inside the BODY element. If _par is
* an element, be it BODY, then it creates a non-popup calendar (still
* hidden). Some properties need to be set before calling this function.
*/
Calendar.prototype.create = function (_par) {
var parent = null;
if (! _par) {
// default parent is the document body, in which case we create
// a popup calendar.
parent = document.getElementsByTagName("body")[0];
this.isPopup = true;
} else {
parent = _par;
this.isPopup = false;
}
this.date = this.dateStr ? new Date(this.dateStr) : new Date();
var table = Calendar.createElement("table");
this.table = table;
table.cellSpacing = 0;
table.cellPadding = 0;
table.calendar = this;
Calendar.addEvent(table, "mousedown", Calendar.tableMouseDown);
var div = Calendar.createElement("div");
this.element = div;
div.className = "calendar";
if (this.isPopup) {
div.style.position = "absolute";
div.style.display = "none";
}
div.appendChild(table);
var thead = Calendar.createElement("thead", table);
var cell = null;
var row = null;
var cal = this;
var hh = function (text, cs, navtype) {
cell = Calendar.createElement("td", row);
cell.colSpan = cs;
cell.className = "button";
if (navtype != 0 && Math.abs(navtype) <= 2)
cell.className += " nav";
Calendar._add_evs(cell);
cell.calendar = cal;
cell.navtype = navtype;
cell.innerHTML = "
" + text + "
";
傳回儲存格;
};
row = Calendar.createElement("tr", thead);
var title_length = 6;
(this.isPopup) && -- title_length ;
(this.weekNumbers) && ++title_length
hh("?", 1, 400).ttip = Calendar._TT["INFO"];
this.title = hh("" , title_length, 300);
this.title.className = "title"
if (this.isPopup) {
this.title.ttip = Calendar._TT["DRAG_TO_MOVE"]; style.cursor = style.cursor = "移動";
hh("×", 1, 200).ttip = Calendar._TT["CLOSE"];
}
row = Calendar.createElement( "tr", thead);
row.className = "headrow";
this._nav_py = hh("«", 1, -2);
this._nav_py.ttip = 日曆._TT[ "PREV_YEAR"] ;
this._nav_pm = hh("‹", 1, -1);
this._nav_pm.ttip = 日曆._TT["PREV_MONTH"];
this._nav_now = hh (日曆._TT ["TODAY" ], this.weekNumbers ? 4 : 3, 0);
this._nav_now.ttip = Calendar._TT["GO_TODAY"];
this._nav_nm = hh("› ", 1, 1);
this._nav_nm.ttip = 日曆._TT["NEXT_MONTH"];
this._nav_ny = hh("»", 1, 2);
this._nav_ny. _TT["NEXT_YEAR"];
this._nav_ny. _TT["NEXT_YEAR"];
// 日期名稱
row = Calendar.createElement("tr", thead);
row.className = "daynames";
if (this.weekNumbers) {
cell = Calendar.createElement("td", row);
cell.className = "name wn";
cell.innerHTML = Calendar._TT["WK"];
}
for (var i = 7; i > 0; --i) {
cell = Calendar.createElement("td", row);
if (!i) {
cell.navtype = 100;
cell.calendar = this;
日曆._add_evs(儲存格);
}
}
this.firstdayname = (this.weekNumbers) ? row.firstChild.nextSibling : row.firstChild;
this._displayWeekdays();
var tbody = Calendar.createElement("tbody", table);
this.tbody = tbody;
for (i = 6; i > 0; --i) {
row = Calendar.createElement("tr", tbody);
if (this.weekNumbers) {
cell = Calendar.createElement("td", row);
}
for (var j = 7; j > 0; --j) {
cell = Calendar.createElement("td", row);
cell.calendar = this;
日曆._add_evs(儲存格);
}
}
if (this.showsTime) {
row = Calendar.createElement("tr", tbody);
row.className = "時間";
cell = Calendar.createElement("td", row);
cell.className = "時間";
cell.colSpan = 2;
cell.innerHTML = Calendar._TT["TIME"] || 「 」;
cell = Calendar.createElement("td", row);
cell.className = "時間";
cell.colSpan = this.weekNumbers ? 4:3;
(function(){
function makeTimePart(className, init, range_start, range_end) {
var part = Calendar.createElement("span", cell);
part.className = className;
part.innerHTML = init;
part.ttip = Calendar._TT["TIME_PART"];
part.navtype = 50; >if (typeof range_start != "number")
part._range = range_start;
else {
for (var i = range_start; i var txt ;
if (i = 10) txt = '0' + i;
else txt = '' + i;
part._range[part _range.length] = txt;
}
}
日曆._add_evs (part)
回傳部分;
var hrs = cal.date.getHours();
var mins = cal.date.getMinutes( )
var t12 = !cal.time24;
var pm = (hrs > 12);if (t12 && pm) hrs -= 12;
var H = makeTimePart("小時", hrs, t12; ? 1 : 0, t12 ? 12 : 23);
var span = Calendar.createElement("span", cell); .innerHTML = ":";
span.className = "冒號"
var M = makeTimePart("分鐘", 分鐘, 0, 59) ;
var AP = null;
cell = Calendar.createElement("td", row);
cell.className = "時間";
cell.colSpan = 2;
if (t12)
AP = makeTimePart("ampm", pm ? "pm" : "am", ["am", "pm"]);
否則
cell.innerHTML = " ";
cal.onSetTime = function() {
var pm, hrs = this.date.getHours(),
mins = this.date.getMinutes();
if (t12) {
pm = (hrs >= 12);
如果(下午)小時 -= 12;
if (hrs == 0) hrs = 12;
AP.innerHTML = pm ? 「下午」:「上午」;
}
H.innerHTML = (小時 M.innerHTML =(分鐘};
cal.onUpdateTime = function() {
var date = this.date;
var h = parseInt(H.innerHTML, 10);
if (t12) {
if (/pm/i.test(AP.innerHTML) && h h += 12;
else if (/am/i.test(AP.innerHTML) && h == 12)
h = 0;
}
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
date.setHours(h);
date.setMinutes(parseInt(M.innerHTML, 10));
date.setFullYear(y);
date.setMonth(m);
date.setDate(d);
this.dateClicked = false;
this.callHandler();
};
})();
} else {
this.onSetTime = this.onUpdateTime = function() {};
}
var tfoot = Calendar.createElement("tfoot", table);
row = Calendar.createElement("tr", tfoot);
row.className = "footrow";
cell = hh(Calendar._TT["SEL_DATE"], this.weekNumbers ? 8 : 7, 300);
cell.className = "ttip";
if (this.isPopup) {
cell.ttip = Calendar._TT["DRAG_TO_MOVE"];
cell.style.cursor = "移動";
}
this.tooltips = 儲存格;
div = Calendar.createElement("div", this.element);
this.monthsCombo = div;
div.className = "combo";
for (i = 0; i var mn = Calendar.createElement("div");
mn.className = Calendar.is_ie ? "label-IEfix" : "標籤";
mn.month = i;
mn.innerHTML = Calendar._SMN[i];
div.appendChild(mn);
}
div = Calendar.createElement("div", this.element);
this.yearsCombo = div;
div.className = "combo";
for (i = 12; i > 0; --i) {
var yr = Calendar.createElement("div");
yr.className = Calendar.is_ie ? "label-IEfix" : "標籤";
div.appendChild(yr);
}
this._init(this.firstDayOfWeek, this.date);
parent.appendChild(this.element);
};
/**鍵盤導航,僅適用於彈出式日曆*/
Calendar._keyEvent = function(ev) {
var cal = window._dynarch_popupCalendar;
if (!cal || cal.multiple)
回傳 false;
(Calendar.is_ie) && (ev = window.event);
var act = (Calendar.is_ie || ev.type == "keypress"),
K = ev.keyCode;
if (ev.ctrlKey) {
switch (K) {
case 37: // KEY left
act && Calendar.cellClick(cal._nav_pm);
休息;
案例 38: // KEY up
act && Calendar.cellClick(cal._nav_py);
休息;
案例 39: // 右鍵
act && Calendar.cellClick(cal._nav_nm);
休息;
案例 40: // 按下按鍵
act && Calendar.cellClick(cal._nav_ny);
休息;
預設:
回傳 false;
}
} else switch (K) {
case 32: // KEY 空格 (現在)
Calendar.cellC(lick cal._nav_now);
休息;
案例27: // KEY esc
act && cal.callCloseHandler();
休息;
case 37: // 按鍵向左
case 38: // 按鍵向上
case 39: // 按鍵向右
case 40: // 按鍵相鄰
if (act) {
var prev, x, y, ne, el,步驟;
上一頁= K == 37 || K==38;
步數 = (K == 37 || K == 39) ? 1:7;
function setVars() {
el = cal.currentDateEl;
var p = el.pos;
x = p & 15;
y = p>> 4;
ne = cal.ar_days[y][x];
};setVars();
function prevMonth() {
var date = new Date(cal.date);
date.setDate(date.getDate() -步驟);
cal.setDate(日期);
};
function nextMonth() {
var date = new Date(cal.date);
date.setDate(date.getDate() +步驟);
cal.setDate(日期);
};
while (1) {
switch (K) {
case 37: // KEY left
if (--x >= 0)
ne = cal. ar_days[y] [x];
其他{
x = 6;
K = 38;
繼續;
}
休息;
case 38: // KEY up
if (--y >= 0)
ne = cal. ar_days[y][x];
else {
prevMonth();
setVars();
}
休息;
case 39: // KEY right
if (++x ne = cal.ar_days[y][x];
其他{
x = 0;
K = 40;
繼續;
}
休息;
case 40: // KEY down
if (++y ne = cal.ar_days[y][x];
else {
nextMonth();
setVars();
}
休息;
}
休息;
}
if (ne) {
if (!ne.disabled)
Calendar.cellClick(ne);
else if (上一個)
prevMonth();
其他
下個月();
}
}
休息;
案例 13: // KEY Enter
if (act)
Calendar.cellClick(cal.currentDateEl, ev);
休息;
預設:
回傳 false;
}
return Calendar.stopEvent(ev);
};
/**
* (RE)將日曆初始化為給定日期和firstDayOfWeek
*/
Calendar.prototype._init = function (firstDayOfWeek, date) {
var Today = new Date(),
TY = Today. getFullYear(),
TM = Today.getMonth(),
TD = Today.getDate();
this.table.style.visibility = "隱藏";
var 年 = date.getFullYear();
if (year year = this.minYear;
date.setFullYear(年);
} else if (year > this.maxYear) {
year = this.maxYear;
date.setFullYear(年);
}
this.firstDayOfWeek = firstDayOfWeek;
this.date = new Date(日期);
var 月份 = date.getMonth();
var mday = date.getDate();
var no_days = date.getMonthDays();
// 日曆魔法,用於實際計算
// 顯示在日曆中的第一天,即使是上個月的。 date.setDate(1);
var day1 = (date.getDay() - this.firstDayOfWeek) % 7;
如果 (第 1 天 第 1 天 += 7;
date.setDate(-day1);
date.setDate(date.getDate() + 1);
var row = this.tbody.firstChild;
var MN = 日曆._SMN[月];
var ar_days = this.ar_days = new Array();
var 週末 = Calendar._TT["WEEKEND"];
var 日期 = this.multiple ? (this.datesCells = {}) : null;
for (var i = 0; i var cell = row.firstChild;
if (this.weekNumbers) {
cell.className = "day wn";
cell.innerHTML = date.getWeekNumber();
cell = cell.nextSibling;
}
row.className = "daysrow";
var hasdays = false, iday, dpos = ar_days[i] = [];
for (var j = 0; j iday = date.getDate();
var wday = date.getDay();
cell.className = "day";
cell.pos = i dpos[j] = 儲存格;
var current_month = (date.getMonth() == 月份);
if (!current_month) {
if (this.showsOtherMonths) {
cell.className += " othermonth";
cell.otherMonth = true;
} else {
cell.className = "emptycell";
cell.innerHTML = " ";
cell.disabled = true;
續;
}
} else {
cell.otherMonth = false;
hasdays = true;
}
cell.disabled = false;
cell.innerHTML = this.getDateText ?
if (日期)
dates[date.print("%Y%m%d")] = cell;
if (this.getDateStatus) {
var status = this.getDateStatus(日期、年、月、日);
if (this.getDateToolTip) {
var toolTip = this.getDateToolTip(日期、年、月、日);
if (工具提示)
cell.title = 工具提示;
}
if (status === true) {
cell.className += "disabled";
cell.disabled = true;
} else {
if (/disabled/i.test(status))
cell.disabled = true;
cell.className += " " + status;
}
}
if (!cell.disabled) {
cell.caldate = new Date(date);
cell.ttip = "_";
if (!this.multiple && current_month
&& iday == mday && this.hiliteToday) {
cell.className += " selected";
this.currentDateEl = 單元格;
}
if (date.getFullYear() == TY &&
date.getMonth() == TM &&
iday == TD) {
cell.className += " 今天" ;
cell.ttip += Calendar._TT["PART_TODAY"];
}
if (weekend.indexOf(wday.toString()) != -1)
cell.className += cell.otherMonth ? " oweekend" : " 週末";
}
}
if (!(hasdays || this.showsOtherMonths))
row.className = "emptyrow";
}
this.title.innerHTML = Calendar._MN[月] + ", " + 年;
this.onSetTime();
this.table.style.visibility = "可見";
this._initMultipleDates();
// 設定檔
// this.tooltips.innerHTML = "產生於 " + ((new Date()) - 今天) + " ms";
};
Calendar.prototype._initMultipleDates = function() {
if (this.multiple) {
for (var i in this.multiple) {
var cell = this.datesCells [我];
var d = this.multiple[i];
if (!d)
繼續;
if (cell)
cell.className += " selected";
}
}
};
Calendar.prototype._toggleMultipleDate = function(date) {
if (this.multiple) {
var ds = d🎜>if (this.multiple) {
var ds = date.print("%Yate.print("%Y %m%d");
var cell = this.datesCells[ds];
if (cell) {
var d = this.multiple[ds];
if (!d) {
Calendar.addClass(cell, "selected");
this.multiple[ds] = 日期;
} else {
Calendar.removeClass(cell, "selected");
刪除 this.multiple[ds];
}
}
}
};
Calendar.prototype.setDateToolTipHandler = function (unaryFunction) {
this.getDateToolTip = unaryFunction;
};
/**
* 呼叫上面的 _init 函數前往特定日期(但前提是
* 日期與目前選取的日期不同)。
*/
Calendar.prototype.setDate = function (date) {
if (!date.equalsTo(this.date)) {
this ._init(this.第一天週,日期);
}
};
/**
* 刷新日曆。如果「disabledHandler」函數是動態的,這表示停用日期清單可以在執行時更改,則很有用。
* 如果您認為停用日期清單
* 應該 * 更改,請呼叫此函數。
*/
Calendar.prototype.refresh = function () {
this ._init(this.firstDayOfWeek, this.date);
/**修改「firstDayOfWeek」參數(為週日傳遞 0,為週一傳遞 1 等)。*/
Calendar.prototype.setFirstDayOfWeek = function (firstDayOfWeek) {
this._inthis(firstateOfirst );
this._displayWeekdays();
/**
* 允許自訂啟用的日期。 「unaryFunction」
* 參數必須是接收日期的函數物件(作為 JS Date
* 物件)並傳回布林值。如果傳回值為 true,則
* 傳遞的日期將被標記為停用。
*/
Calendar.prototype.setDateStatusHandler = Calendar.prototype.setDisabledHandler = function (unaryFunction) {this Stat. 🎜>};
/**自訂日曆允許的年份範圍。*/
Calendar.prototype.setRange = function (a, z) {
this.minYear = a ;
this.maxYear = z
this.minYear = a ;
this.maxYear = z
this.minYear = a ;
this.maxYear = z
this.minYear = a ;
this.maxYear = z
this.minYear = a ;
this.maxYear = z
this.minYear = a ;
this.maxYear = z
this.minYear = a ;
this.maxYear = z
this.minYear = a ;
this.maxYear = z
this.minYear = a ;
this.max中>};
/**呼叫第一個使用者處理程序 (selectedHandler)。*/
Calendar.prototype.callHandler = function () { if (this.onSelected) { this.onSelected(this, this.date. print(this) .dateFormat)); } }; /**呼叫第二個使用者處理程序 (closeHandler)。*/ Calendar.prototype.callCloseHandler = function () { if (this.onClose) { this.onClose(this); } this.hideShowCovered(); };
/**從 DOM 樹中刪除日曆物件並銷毀它。*/
Calendar.prototype.destroy = function () {
var el = this.element.parentNode;
el.removeChild(this.element)
日曆._C = null;
window._dynarch_popupCalendar = null;
};
/**
* 將日曆元素移到 DOM 樹中的不同部分(更改
* 其父級)。
*/
Calendar.prototype.reparent = function (new_parent) { var el = this.element;
el.parentNode.removeChild(el);
new_parent.appendChild(el);
};
// 當使用者在
// 文件中的任意位置按下滑鼠按鈕(如果顯示日曆)時,將呼叫此函數。如果按一下位於開啟的
// 日曆之外,則此函數會將其關閉。
Calendar._checkCalendar = function(ev) {
var calendar = window._dynarch_popupCalendar;
if (!calendar) {
回傳false;
}
回傳false;
}
返回. ? Calendar.getElement(ev) : Calendar.getTargetElement(ev);
for (; el != null && el != calendar.element; el = el.parentNode);
if (el == null) {
// 呼叫closeHandler 來隱藏日曆。
window._dynarch_popupCalendar.callCloseHandler();
return Calendar.stopEvent(ev);
}
};
/**顯示日曆。*/
Calendar.prototype. = function () {
var rows = this.table.getElementsByTagName("tr");
for (var i = rows.length; i > 0;) {
var row = rows[-- i];
Calendar.removeClass(row, "rowhilite");
var cells = row.getElementsByTagName("td");
for (var j = cells.length; j > 0;) {
var cell = cells[--j];
Calendar.removeClass(cell, "hilite");
Calendar.removeClass(cell, "active");
}
}
this.element.style.display = "block";
this.hidden = false;
if (this.isPopup) {
window._dynarch_popupCalendar = this;
Calendar.addEvent(documentar. , "keydown", Calendar._keyEvent);
Calendar.addEvent(document, "keypress", Calendar._keyEvent);
Calendar.addEvent(document, "mousedown", Calendar._checkCalendar);
}
this.hideShowCovered();
};
/**
* 隱藏日曆。也從任何 TD
* 元素的類別中刪除任何「hilite」。
*/
Calendar.prototype.hide = function () {
if (this.isPopup) {
Calendar.removeEvent(document, "keydown", Calendar._keyEvent );
Calendar.removeEvent(document, "keypress", Calendar._keyEvent);
Calendar.removeEvent(useument, "modowndown", Calendar. );
}
this.element.style.display = "none";
this.hidden = true;
this.hideShowCovered();
};
/****
* 在給定的絕對位置顯示日曆(請注意,根據
* 日曆元素樣式 -- 位置屬性 -- 這可能是相對於
* 父級的包含矩形)。
*/
Calendar.prototype.showAt = function (x, y) {
var s = this.element.style;
s.left = x + "px";
s .top = y + "px";
this.show();
};
/**顯示給定元素附近的日曆。*/
Calendar.prototype.showAtElement = function (el, opts) {
var self = this;
var p = Calendar.getAbsolutePos(el);
if (!opts || typeof opts != "string") {
this.showAt(p.x, p.y +!= "string") {
this.showAt(p.x, p.y +!= "string") {
this.showAt(p.x, p.y +!= "string") {
this.showAt(p.x, p.y +!= "string") {
this.showAt(p.x, p.y +!= "string") {
this.showAt(p.x, p.y +!= "string") {
this.showAt(p.x, p.y +! = el.offsetHeight);
回傳真;
}
函數fixPosition(box) {
if (box.x box.x = 0;
if (box .y box.y = 0;
var cp = document.createElement("div");
var s = cp.style;
s.position = "絕對";
s.right = s.bottom = s.width = s.height = "0px";
document.body.appendChild(cp);
var br = Calendar.getAbsolutePos(cp);
document.body.removeChild(cp);
if (Calendar.is_ie) {
br.y += document.body.scrollTop;
br.x += document.body.scrollLeft;
} else {
br.y += window.scrollY;
br.x += window.scrollX;
}
var tmp = box.x + box.width - br.x;
if (tmp > 0) box.x -= tmp;
tmp = box.y + box.height - br.y;
if (tmp > 0) box.y -= tmp;
};
this.element.style.display = "塊";
Calendar.continuation_for_the_fucking_khtml_browser = function() {
var w = self.elselement.offsetWidthvar. element.offsetHeight;
self.element.style.display = "none";
var valign = opts.substr(0, 1);
var halign = "l";
if (opts .length > 1) {
halign = opts.substr(1, 1);
}
// 垂直對齊
switch (valign) {
case "T": p.y -= h;休息;
情況「B」:p.y += el.offsetHeight;休息;
情況「C」:p.y += (el.offsetHeight - h) / 2;休息;
case "t ": p.y += el.offsetHeight - h;休息;
情況「b」:中斷; // 已經存在
}
// 水平對齊
switch (halign) {
case "L": p.x -= w;休息;
case "R": p.x += el.offsetWidth;休息;
情況「C」:p.x += (el.offsetWidth - w) / 2;休息;
case "l": p.x += el.offsetWidth - w;休息;
case "r": 中斷; // 已經存在
} p.width = w; p.height = h + 40; self.monthsCombo.style.display = "none"; 修復位置(p); self.showAt(p.x, p.y); };
if (Calendar.is_khtml)
setTimeout("Calendar.continuation_for_the_fucking_khtml_browser()", 10);
其他
Calendar.continuation_for_the_fucking_khtml_browser();
};
/**自訂日期格式。*/
Calendar.prototype.setDateFormat = function (str) {
this.dateFormat = str;
};
/**自訂工具提示日期格式。*/
Calendar.prototype.setTtDateFormat = function (str) {
this.ttDateFormat = str;
};
/**
* 嘗試辨識字串中表示的日期。如果成功,它也會
* 呼叫 this.setDate 將日曆移至給定日期。
*/
Calendar.prototype.parseDate = function(str, fmt) {
if (!fmt)
fmt = this.dateFormat;
this.setDate(Date.parseDate(str, fmt));
};
Calendar.prototype.hideShowCovered = function () {
if (!Calendar.is_ie && !Calendar.is_opera)
return;
function getVisib(obj){
var value = obj.style.visibility;
if (!value) {
if (document.defaultView && typeof (document.defaultView.getCompulatedStyle) == "function") { // Gecko,W3C
if (!Calendar.is_khtml)
值= document.defaultView.
getCompulatedStyle(obj, "").getPropertyValue("可見性");
其他
值='';
} else if (obj.currentStyle) { // IE
value = obj.currentStyle.visibility;
} else
值 = '';
}
傳回值;
};
var Tags = new Array("applet", "iframe", "select");
var el = this.element;
var p = Calendar.getAbsolutePos(el);
var EX1 = p.x;
var EX2 = el.offsetWidth + EX1;
var EY1 = p.y;
var EY2 = el.offsetHeight + EY1;
for (var k = Tags.length; k > 0; ) {
var ar = document.getElementsByTagName(tags[--k]);
var cc = null;
for (var i = ar.length; i > 0;) {
cc = ar[--i];
p = Calendar.getAbsolutePos(cc);
var CX1 = p.x;
var CX2 = cc.offsetWidth + CX1;
var CY1 = p.y;
var CY2 = cc.offsetHeight + CY1;
if (this.hidden || (CX1 > EX2) || (CX2 EY2) || (CY2 if (!cc.__msh_save_visibility) {
cc.__msh_save_visibility = getVisib(cc);
}
cc.style.visibility = cc.__msh_save_visibility;
} else {
if (!cc.__msh_save_visibility) {
cc.__msh_save_visibility = getVisib(cc);
}
cc.style.visibility = "隱藏";
}
}
}
};
/**內部功能;它顯示一個帶有工作日名稱的欄位。*/
Calendar.prototype._displayWeekdays = function () {
var fdow = this.firstDayOfWeek;
var cell = this.firstdayname;
var 週末 = Calendar._TT["WEEKEND"];
for (var i = 0; i cell.className = "日期名稱";
var realday = (i + fdow) % 7;
if (i) {
cell.ttip = Calendar._TT["DAY_FIRST"].replace("%s", Calendar._DN[realday]);
cell.navtype = 100;
cell.calendar = this;
cell.fdow = realday;
日曆._add_evs(儲存格);
}
if (weekend.indexOf(realday.toString()) != -1) {
Calendar.addClass(cell, "weekend");
}
cell.innerHTML = Calendar._SDN[(i + fdow) % 7];
cell = cell.nextSibling;
}
};
/**內部功能。隱藏所有可能顯示的組合方塊。*/
Calendar.prototype._hideCombos = function () {
this.monthsCombo.style.display = "none";
this.yearsCombo.style.display = "none";
};
/**內部功能。開始拖曳元素。*/
Calendar.prototype._dragStart = function (ev) {
if (this.dragging) {
return;
}
this.dragging = true;
var posX;
var posY;
if (Calendar.is_ie) {
posY = window.event.clientY + document.body.scrollTop;
posX = window.event.clientX + document.body.scrollLeft;
} else {
posY = ev.clientY + window.scrollY;
posX = ev.clientX + window.scrollX;
}
var st = this.element.style;
this.xOffs = posX - parseInt(st.left);
this.yOffs = posY - parseInt(st.top);
with (Calendar) {
addEvent(document, "mousemove", calDragIt);
addEvent(document, "mouseup", calDragEnd);
}
};
// 開始:日期物件補丁
/**將天數數組加入 Date 物件。*/
Date._MD = new Array(31,28,31,30,31,30,31,31,30, 31 ,30,31);
/**用於時間計算的常數*/
Date.SECOND = 1000 /* 毫秒*/;
日期.分鐘= 60 * 日期.秒;
日期.小時= 60 * 日期.分鐘;
日期.DAY = 24 * 日期.HOUR;
日期.WEEK = 7 * 日期.DAY;
Date.parseDate = function(str, fmt) {
var Today = new Date();
var y = 0;
var m = -1;
var d = 0;
var a = str.split(/W+/);
var b = fmt.match(/%./g);
var i = 0, j = 0;
var hr = 0;
var min = 0;
for (i = 0; i if (!a[i])
繼續;
switch (b[i]) {
case "%d":
case "%e":
d = parseInt(a[i], 10);
休息;
case "%m":
m = parseInt(a[i], 10) - 1;
休息;
case "%Y":
case "%y":
y = parseInt(a[i], 10);
(y 29) ? 1900 : 2000);
休息;
case "%b":
case "%B":
for (j = 0; j if (Calendar._MN[j].substr (0, a[i].length).toLowerCase() == a[i].toLowerCase()) { m = j ;休息; }
}
休息;
案例“%H”:
案例“%I”:
案例“%k”:
案例“%l”:
hr = parseInt(a[i], 10) ;
休息;
case "%P":
case "%p":
if (/pm/i.test(a [i]) && hr hr += 12;
else if (/am/i.test(a[i]) && hr >= 12)
hr -= 12;
休息;
case "%M":
min = parseInt(a[i], 10);
休息;
}
}
if (isNaN(y) ) y = Today.getFullYear();
if (isNaN(m)) m = Today.getMonth();
if (isNaN(d)) d = Today.getDate();
if ( isNaN(hr)) hr = Today.getHours();
if (isNaN(min)) min = Today.getMinutes();
if (y != 0 && m != -1 && d != 0)
回傳新日期(y, m, d, hr, min, 0);
y = 0;米=-1; d = 0;
for (i = 0; i if (a[i].search(/[a-zA-Z]+/) != -1) {
var t = -1;
for (j = 0; j if (Calendar._MN[j].substr(0, a[i].length).toLowerCase() == a[ i].toLowerCase( )) { t = j;休息; }
}
if (t != -1) {
if (m != -1) {
d = m+1;
}
m = t;
}
} else if (parseInt(a[i], 10) m = a[i]-1 ;
} else if (parseInt(a[i], 10) > 31 && y == 0) {
y = parseInt(a[i], 10);
(y 29) ? 1900 : 2000);
} else if (d == 0) {
d = a[i];
}
}
if (y == 0)
y = Today.getFullYear();
if (m != -1 && d != 0)
傳回新日期(y, m, d, hr, min, 0);
今天回來;
};
/**傳回目前月份的天數*/
Date.prototype.getMonthDays = function(month) {
varyear = this.getFullYear();
if (typeof Month == "undefined") {
month = this.getMonth();
}
if (((0 == (year%4)) && ( (0 ! = (year%100)) || (0 == (year%400)))) && 月份== 1) {
回傳29;
} else {
回傳日期._MD[月] ;
}
};
/**傳回一年中的天數。*/
Date.prototype.getDayOfYear = function() {
var now = new Date(this.getFullYear(), this .getMonth(), this.getDate() , 0, 0, 0);
var then = new Date(this.getFullYear(), 0, 0, 0, 0, 0);
var time =現在- 然後;
return Math.floor(time / Date.DAY);
};
/**傳回一年中的周數,如 ISO 8601 所定義。*/
Date.prototype.getWeekNumber = function() {
var d = new Date(this.getFullYear(), this.getMonth(), this.getDate() , 0, 0, 0);
var DoW = d.getDay();
d.setDate (d.getDate() - (DoW + 6) % 7 + 3); // 最近的星期四
var ms = d.valueOf(); // GMT
d.setMonth(0);
d.setDate(4); // 第1 週的星期四
return Math.round((ms - d.valueOf()) / (7 * 864e5)) + 1;
};
/**檢查日期和時間是否相等*/
Date.prototype.equalsTo = function(date) {
return ((this.getFullYear() == date.getFullYear()) &&
(this .getMonth () == date.getMonth()) &&
(this.getDate() == date.getDate()) &&
(this.getHours() == date.getHours()) &&
(this.getMinutes() == date.getMinutes()));
};
/**僅設定年、月、日部分(保留現有時間)*/
Date.prototype.setDateOnly = function(date) {
var tmp = new Date(date);
this.setDate(1);
this.setFullYear(tmp.getFullYear());
this.setMonth(tmp.getMonth());
this .setDate(tmp.getDate());
};
/**根據給定的格式列印字串中的日期。*/
Date.prototype.print = function (str) {
var m = this.getMonth( );
var d = this.getDate();
var y = this.getFullYear();
var wn = this.getWeekNumber();
var w = this.getDay();
var s = {};
var hr = this.getHours();
var pm = (hr >= 12);
var ir = (pm) ?(小時- 12):小時;
var dy = this.getDayOfYear();
如果(ir == 0)
ir = 12;
var min = this.getMinutes();
var sec = this.getSeconds();
s["%a"] = 日曆._SDN[w]; // 工作日縮寫名稱[FIXME: I18N]
s["%A"] = Calendar._DN[w]; // 完整工作日名稱
s["%b"] = Calendar._SMN[m]; // 月份名稱縮寫[FIXME: I18N]
s["%B"] = Calendar._MN[m]; // 完整的月份名稱
// FIXME: %c : 當前語言環境的首選日期和時間表示
s["%C"] = 1 + Math.floor(y / 100); // 世紀數
s["%d"] = (d s["%e"] = d ; // 一個月中的某一天(範圍1 到31)
// FIXME: %D : 美國日期樣式: %m/%d/%y
// FIXME: %E, %F, %G , %g, %h (man strftime)
s["%H"] = (hr s["%I"] = (ir s["%j" ] = (dy s["%k"] = hr; // 小時,範圍0 到23(24 小時格式)
s["%l"] = ir; // 小時,範圍1 到12(12h 格式)
s["%m"] = (m s["%M "] = (min s["%n"] = "n"; // 換行符
s ["%p"] = pm ? 「下午」:「上午」;
s["%P"] = pm ? 「下午」:「上午」;
// FIXME: %r : am/ pm 格式的時間%I:%M:%S %p
// FIXME: %R : 24 小時格式的時間%H:%M
s["%s"] = Math.floor(this .getTime() / 1000);
s["%S"] = (秒s["% t"] = "t"; // 製表符
// FIXME: %T : 24 小時制時間(%H:%M:%S)
s["%U"] = s[ "%W"] = s["%V"] = (wn s["%u"] = w + 1; // 一週中的某一天(範圍1 到7,1 = MON)
s["%w"] = w; // 一週中的某一天(範圍0 到6,0 = SUN)
// FIXME: % x : 當前語言環境的首選日期表示形式,不含時間
// FIXME: %X : 首選時間表示形式對於沒有日期的當前語言環境
s["%y"] = ('' + y).substr(2, 2); // 沒有世紀的年份(範圍00 到99)
s["%Y"] = y; // 年份與世紀
s["%%"] = "%"; // 一個文字'%' 字元
var re = /%./g;
if (!Calendar.is_ie5 && !Calendar.is_khtml)
return str.replace(re, function (par) { return s[par] || par; });
var a = str.match(re);
for (var i = 0; i var tmp = s[a[i]];
if (tmp) {
re = new RegExp(a[i], 'g');
str = str.replace(re, tmp);
}
}
return str;
};
Date.prototype.__msh_oldSetFullYear = Date.prototype.setFullYear;
Date.prototype.Fate.prototype. {
var d = new Date(this);
d.__msh_oldSetFullYear(y);
if (d.getMonth() != this.getMonth())
this.setDate(28) ;
this.__msh_oldSetFullYear(y);
};
// END: DATE OBJECT PATCHES
// 記住日曆的全域物件
window._dynarch_popupCalendar = null;
//******** calendar.js 結束********************
/* 版權所有Mihai Bazon,2002、2003 | http://dynarch. com/mishoo/
* ------------------------------------ ------ ---------------------------------
*
* DHTML 日曆
*
* 詳細資訊和最新版本位於:
* http://dynarch.com/mishoo/calendar.epl
*
* 該腳本根據GNU Lesser General Public License 分發。
* 在此閱讀完整的授權文字:http://www.gnu.org/licenses/lgpl.html
*
* 該檔案定義了用於設定日曆的輔助函數。它們
*旨在幫助非程式設計師在其網站上
*快速取得工作日曆。該腳本不應被視為日曆的一部分。它只是
* 向您展示可以對日曆執行哪些操作,同時
* 提供一種快速而簡單的設定方法。如果您需要
*對日曆創建過程進行詳盡的自定義,請隨意
*修改此程式碼以滿足您的需求(這是推薦的,並且
*比修改calendar.js本身要好得多)。
*/
// $Id : calendar-setup.js,v 1.25 2005/03/07 09:51:33 mishoo Exp $
/**
* 此函數「修補」輸入欄位(或其他元素)以使用日曆
* 小工具進行日期選擇。
*
* 「params」是一個可以具有下列屬性的單一物件:
*
* prop。名稱|描述
* ------------------------------------------- -------------- ------------------------------------ -------------- --
* 輸入欄位|用於儲存日期的輸入欄位的ID
* displayArea |顯示日期的DIV 或其他元素的ID
* 按鈕|將觸發日曆的按鈕或其他元素的ID
* eventName |將觸發日曆的事件,沒有「on」前綴(預設:「click」)
* ifFormat |將儲存在輸入欄位中的日期格式
* daFormat |用於在displayArea 中顯示日期的日期格式
* singleClick | (true/false) 日曆是否處於單擊模式(預設值:true)
*firstDay |數字:0到6。 「0」表示先顯示星期日,「1」表示先顯示星期一,依此類推。
*align |對齊(預設值:「Br」);如果您不知道這是什麼,請參閱日曆文件
* range |有 2 個元素的陣列。預設值:[1900, 2999] -- 可用年份範圍
* weekNumbers | (真/假)如果為真(預設),日曆將顯示週數
* flat | null 或元素ID;如果不為空,日曆將是一個平面日曆,其父日曆具有給定的ID
* flatCallback |接收JS Date 物件並傳回URL 以將瀏覽器指向的函數(對於平面日曆)
*disableFunc |接收JS Date 物件的函數,如果必須在日曆中停用該日期,則應傳回true
* onSelect |選取日期時呼叫的函數。你不需要_have_提供這個(預設值通常就可以)
* onClose |日曆關閉時呼叫的函數。 [預設]
* onUpdate |輸入欄位中的日期更新後呼叫的函數。接收日曆的引用。
* 日期|日曆最初顯示到
*showsTime|的日期預設值:假;如果true 日曆將包含一個時間選擇器
* timeFormat |時間格式;可以是“12”或“24” ,預設為“12”
* 電動|如果為true(預設),則每次移動都會更新給定的欄位/日期區域;否則它們僅在關閉
* 步驟| 時更新在下拉框中配置年份的步長;預設值:2
* 位置|配置日曆絕對位置;預設值:null
* 快取|如果為「true」(但預設值:「false」),它將在可能的情況下重複使用相同的日曆物件
* showOthers |如果為「true」(但預設值:「false」),它也會顯示其他月份的日期
*
* 它們都不是必需的,它們都有預設值。但是,如果您
* 未傳遞「inputField」、「displayArea」或「按鈕」中的任何一個,您將收到警告
* 說「無需設定」。
*/
Calendar.setup = function (params) {
function (pname, def) { if (typeof params[pname] == "undefined") { params[pname] = def; } } };
param_default("inputField", null);
param_default("displayArea", null);
param_default("按鈕", null);
param_default("事件名稱", "點選" );
param_default("ifFormat", "%Y/%m/%d");
param_default("daFormat", "%Y/%m/%d");
param_default(" singleClick", true);
param_default("disableFunc", null);
param_default("dateStatusFunc", params["disableFunc"]); // 如果兩者都定義了則優先
param_default( "dateText", null);
param_default("firstDay", null);
param_default("align", "Br");
param_default("範圍", [1900, 2999]);
param_default("weekNumbers", true);
param_default("flat", null);
param_default("flatCallback", null);
param_default("onSelect", null); param_default("onClose", null);
param_default("onUpdate", null);
param_default("日期", null);
param_default("showsTime", false); param_ "timeFormat", "24");
param_default("電", true);
param_default("step", 2);
param_default("位置", null);
param_default( "快取", false);
param_default("showOthers", false);
param_default("多個", null);
var tmp = ["inputField", "displayArea", "button" ];
for (var i in tmp) {
if (typeof params[tmp[i]] == "string") {
params[tmp[i]] = document.getElementById(params[ tmp[我]]);
}
}
if (!(params.flat || params.multiple || params.inputField || params.displayArea || params.button)) { alert("Calendar.setup :n 無需設定(未找到欄位),請檢查您的程式碼」);
傳回錯誤;
}
function onSelect(cal) {
var p = cal.params;
var update = (cal.dateClicked || p.electric);
if (update && p.inputField) {
p.inputField.value = cal.date.print(p. ifFormat);
if (typeof p.inputField.onchange == "function")
p.inputField.onchange();
}
if (update && p.displayArea)
}
if (update && p.displayArea)
} .displayArea.innerHTML = cal.date.print(p.daFormat);
if (update && typeof p.onUpdate == "function")
p.onUpdate(cal);
if (update &&if p.flat) {
if (typeof p.flatCallback == "function")
p.flatCallback(cal);
}
if (update && p.singleClick && cal.dateClicked) cal.callCloseHandler();
};
if (params.flat != null) {
if (typeof params.flat == "string")
params.flat = document. getElementById(params.flat);
if (!params.flat) {
alert("Calendar.setup:n 指定單位但找不到父單位。 ");
回傳錯誤;
}
var cal = new Calendar(params.firstDay, params.date, params.onSelect || onSelect);
cal.showsOtherMonths = params.showOthers; 🎜>cal.showsTime = params.showsTime;
cal.time24 = (params.timeFormat == "24");
cal.params = params;
cal.weekNumbers = params.weekNumbers; >cal.setRange(params.range[0], params.range[1]);
cal.setDateStatusHandler(params.dateStatusFunc);
cal.getDateText = params.dateText;
if (params. ifFormat) {
cal.setDateFormat(params.ifFormat);
}
if (params.inputField && typeof params.inputField.value == "string") {
cal.parseDate(params. inputField.value);
}
cal.create(params.flat);
cal.show();
回傳錯誤;
}
var triggerEl = params.button | | params.displayArea || params.inputField;
triggerEl["on" + params.eventName] = function() {
var dateEl = params.inputField || params.displayArean
var MustCreate = false;
var cal = window.calendar;
if (dateEl)
params.date = Date.Date. || dateEl.innerHTML, dateFmt);
if (!(cal && params.cache)) {
window.calendar = cal = new Calendar(params.firstDay,
params.date,
params.onSelect || onSelect,
params.onClose || 函數(cal) { cal.hide() });
cal.showsTime = params.showsTime;
cal.time24 = (params.timeFormatat == "24");
cal.weekNumbers = params.weekNumbers;
mustCreate = true;
} else {
if (params.date)
cal.setDate(params.date );
cal.hide();
}
if (params.multiple) {
cal.multiple = {};
for (var i = params.multiple.length; - -i >= 0;) {
var d = params.multiple[i];
var ds = d.print("%Y%m%d");
cal.multiple[ds] = d;
}
}
cal.showsOtherMonths = params.showOthers;
cal.yearStep = params.step;
cal.setRange(params.range[0], paramsrangerange. [1]);
cal.params = params;
cal.setDateStatusHandler(params.dateStatusFunc);
cal.getDateText = params.dateText;
cal.setDateFormat(dateFmt); if (mustCreate)
cal.create();
cal.refresh();
if (!params.position)
cal.showAtElement(params.button || params.displayArea || params .inputField, params.align);
else
cal.showAt(params.position[0], params.position[1]);
回傳錯誤;
};
返回校準;
};
//************ calendar-setup.js END *********************
// * * I18N
// 日曆big5-utf8 語言
// 作者:Gary Fu,
// 編碼:utf8
/// 依照與日曆本身相同的條款分發。
// 翻譯人員:請盡可能使用 UTF-8。我們堅信
// Unicode 是真正國際化世界的答案。另請
// 在標題中包含您的聯絡訊息,如上所示。
// 全天名稱
Calendar._DN = new Array
("星期日",
"星期一",
"星期二",
"星期三",
"星期四",
"星期五",
"星期六",
"星期日");
// 請注意,以下短日名稱數組(對於短月份名稱,_SMN 也是如此
//)並不是絕對必要的。我們在這裡給出
// 作為如何自訂短日名稱的範例,但如果
// 它們只是全名的前N 個字母,您可以簡單地說:
//
// 日曆._SDN_len = N; // 短日名稱長度
// Calendar._SMN_len = N; // 短月份名稱長度
//
// 如果N = 3,則不需要,因為如果不存在
// 則假設值為3,以便與先前的翻譯文件相容寫在
// 此功能之前。
// 短日名稱
Calendar._SDN = new Array
("日",
"一",
"二",
"三",
"四」、
「五」、
「六」、
「日」);
// 一週的第一天。 「0」表示先顯示星期日,「1」表示先顯示
//先顯示星期一,以此類推
Calendar._FD = 0;
// 完整的月份名稱
Calendar. _MN = new Array
("一月",
"二月",
"三月",
"四月",
「五月」、
「六月」、
「七月」、
「八月」、
「九月」、
「十月」、
"十一月",
"十二月");
// 短月份名稱
Calendar._SMN = new Array
("一月",
"二月",
"三月",
"四月",
「五月」、
「六月」、
「七月」、
「八月」、
「九月」、
「十月」、
"十一月",
"十二月");
// 工具提示
Calendar._TT = {};
Calendar._TT["INFO"] = "關於";
Calendar._TT["ABOUT"] =
"DHTML 日期/時間選擇" +
"(c) dynarch.com 2002-2005 / 作者:Mihai Bazonn" + // 不要翻譯此內容這個;-)
「最新版本請上:http://www.dynarch.com/projects/calendar/n」 +
「根據GNU LGPL 分發。請參閱http://gnu. org/licenses/ lgpl.html 了解詳細資訊。使用" + String.fromCharCode(0x2039) + ", " + String.fromCharCode(0x203a) + " 按鈕選擇月份n" +
"-按住上面的按鈕可以加快一些";
Calendar._TT[ "ABOUT_TIME"] = "nn" +
"時間選擇方法:n" +
"- 點擊任何的時間適當可增加其值n" +
"-同時按Shift鍵再點擊可減少其值n"+
"-點選拖曳並可加速改變的值";
Calendar._TT["PREV_YEAR"] = "上一年(持有選單)";
Calendar._TT[ "PREV_MONTH"] = "上一月(按住選單)";
Calendar._TT["GO_TODAY"] = "到今日";
Calendar._TT["NEXT_MONTH"] = " 下個月(按住選單)";
Calendar._TT["NEXT_YEAR"] = "下一年(持有選單)";
Calendar._TT["SEL_DATE"] = "選擇日期";
Calendar ._TT["DRAG_TO_MOVE"] = "拖曳";
Calendar._TT["PART_TODAY"] = "(今日)";
// 以下是通知「%s」為一週的第一天
// %s 將被替換為日期名稱。
Calendar._TT["DAY_FIRST"] = "將 %s 顯示在前面";
// 這可能取決於區域設定。它指定週末,作為逗號分隔數字的陣列
//。數字從 0 到 6:0 表示星期日,1
// 表示星期一,依此類推
Cal
相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板