您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php+javascript的日历控件_PHP教程

2025/8/16 5:15:41发布29次查看
复制代码 代码如下:
js calendar
;
return cell;
};
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];
this.title.style.cursor = move;
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 = calendar._tt[prev_year];
this._nav_pm = hh(‹, 1, -1);
this._nav_pm.ttip = calendar._tt[prev_month];
this._nav_now = hh(calendar._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 = calendar._tt[next_month];
this._nav_ny = hh(», 1, 2);
this._nav_ny.ttip = calendar._tt[next_year];
// day names
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;
calendar._add_evs(cell);
}
}
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;
calendar._add_evs(cell);
}
}
if (this.showstime) {
row = calendar.createelement(tr, tbody);
row.classname = time;
cell = calendar.createelement(td, row);
cell.classname = time;
cell.colspan = 2;
cell.innerhtml = calendar._tt[time] ||  ;
cell = calendar.createelement(td, row);
cell.classname = time;
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.calendar = cal;
part.ttip = calendar._tt[time_part];
part.navtype = 50;
part._range = [];
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;
}
}
calendar._add_evs(part);
return 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(hour, hrs, t12 ? 1 : 0, t12 ? 12 : 23);
var span = calendar.createelement(span, cell);
span.innerhtml = :;
span.classname = colon;
var m = maketimepart(minute, mins, 0, 59);
var ap = null;
cell = calendar.createelement(td, row);
cell.classname = time;
cell.colspan = 2;
if (t12)
ap = maketimepart(ampm, pm ? pm : am, [am, pm]);
else
cell.innerhtml =  ;
cal.onsettime = function() {
var pm, hrs = this.date.gethours(),
mins = this.date.getminutes();
if (t12) {
pm = (hrs >= 12);
if (pm) hrs -= 12;
if (hrs == 0) hrs = 12;
ap.innerhtml = pm ? pm : am;
}
h.innerhtml = (hrs m.innerhtml = (mins };
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 = move;
}
this.tooltips = cell;
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 : label;
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 : label;
div.appendchild(yr);
}
this._init(this.firstdayofweek, this.date);
parent.appendchild(this.element);
};
/** keyboard navigation, only for popup calendars */
calendar._keyevent = function(ev) {
var cal = window._dynarch_popupcalendar;
if (!cal || cal.multiple)
return 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);
break;
case 38: // key up
act && calendar.cellclick(cal._nav_py);
break;
case 39: // key right
act && calendar.cellclick(cal._nav_nm);
break;
case 40: // key down
act && calendar.cellclick(cal._nav_ny);
break;
default:
return false;
}
} else switch (k) {
case 32: // key space (now)
calendar.cellclick(cal._nav_now);
break;
case 27: // key esc
act && cal.callclosehandler();
break;
case 37: // key left
case 38: // key up
case 39: // key right
case 40: // key down
if (act) {
var prev, x, y, ne, el, step;
prev = k == 37 || k == 38;
step = (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() - step);
cal.setdate(date);
};
function nextmonth() {
var date = new date(cal.date);
date.setdate(date.getdate() + step);
cal.setdate(date);
};
while (1) {
switch (k) {
case 37: // key left
if (--x >= 0)
ne = cal.ar_days[y][x];
else {
x = 6;
k = 38;
continue;
}
break;
case 38: // key up
if (--y >= 0)
ne = cal.ar_days[y][x];
else {
prevmonth();
setvars();
}
break;
case 39: // key right
if (++x ne = cal.ar_days[y][x];
else {
x = 0;
k = 40;
continue;
}
break;
case 40: // key down
if (++y ne = cal.ar_days[y][x];
else {
nextmonth();
setvars();
}
break;
}
break;
}
if (ne) {
if (!ne.disabled)
calendar.cellclick(ne);
else if (prev)
prevmonth();
else
nextmonth();
}
}
break;
case 13: // key enter
if (act)
calendar.cellclick(cal.currentdateel, ev);
break;
default:
return false;
}
return calendar.stopevent(ev);
};
/**
* (re)initializes the calendar to the given date and firstdayofweek
*/
calendar.prototype._init = function (firstdayofweek, date) {
var today = new date(),
ty = today.getfullyear(),
tm = today.getmonth(),
td = today.getdate();
this.table.style.visibility = hidden;
var year = date.getfullyear();
if (year year = this.minyear;
date.setfullyear(year);
} else if (year > this.maxyear) {
year = this.maxyear;
date.setfullyear(year);
}
this.firstdayofweek = firstdayofweek;
this.date = new date(date);
var month = date.getmonth();
var mday = date.getdate();
var no_days = date.getmonthdays();
// calendar voodoo for computing the first day that would actually be
// displayed in the calendar, even if it's from the previous month.
// warning: this is magic. ;-)
date.setdate(1);
var day1 = (date.getday() - this.firstdayofweek) % 7;
if (day1 day1 += 7;
date.setdate(-day1);
date.setdate(date.getdate() + 1);
var row = this.tbody.firstchild;
var mn = calendar._smn[month];
var ar_days = this.ar_days = new array();
var weekend = calendar._tt[weekend];
var dates = 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] = cell;
var current_month = (date.getmonth() == month);
if (!current_month) {
if (this.showsothermonths) {
cell.classname += othermonth;
cell.othermonth = true;
} else {
cell.classname = emptycell;
cell.innerhtml =  ;
cell.disabled = true;
continue;
}
} else {
cell.othermonth = false;
hasdays = true;
}
cell.disabled = false;
cell.innerhtml = this.getdatetext ? this.getdatetext(date, iday) : iday;
if (dates)
dates[date.print(%y%m%d)] = cell;
if (this.getdatestatus) {
var status = this.getdatestatus(date, year, month, iday);
if (this.getdatetooltip) {
var tooltip = this.getdatetooltip(date, year, month, iday);
if (tooltip)
cell.title = tooltip;
}
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 = cell;
}
if (date.getfullyear() == ty &&
date.getmonth() == tm &&
iday == td) {
cell.classname += today;
cell.ttip += calendar._tt[part_today];
}
if (weekend.indexof(wday.tostring()) != -1)
cell.classname += cell.othermonth ? oweekend : weekend;
}
}
if (!(hasdays || this.showsothermonths))
row.classname = emptyrow;
}
this.title.innerhtml = calendar._mn[month] + , + year;
this.onsettime();
this.table.style.visibility = visible;
this._initmultipledates();
// profile
// this.tooltips.innerhtml = generated in + ((new date()) - today) + ms;
};
calendar.prototype._initmultipledates = function() {
if (this.multiple) {
for (var i in this.multiple) {
var cell = this.datescells[i];
var d = this.multiple[i];
if (!d)
continue;
if (cell)
cell.classname += selected;
}
}
};
calendar.prototype._togglemultipledate = function(date) {
if (this.multiple) {
var ds = date.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] = date;
} else {
calendar.removeclass(cell, selected);
delete this.multiple[ds];
}
}
}
};
calendar.prototype.setdatetooltiphandler = function (unaryfunction) {
this.getdatetooltip = unaryfunction;
};
/**
* calls _init function above for going to a certain date (but only if the
* date is different than the currently selected one).
*/
calendar.prototype.setdate = function (date) {
if (!date.equalsto(this.date)) {
this._init(this.firstdayofweek, date);
}
};
/**
* refreshes the calendar. useful if the disabledhandler function is
* dynamic, meaning that the list of disabled date can change at runtime.
* just * call this function if you think that the list of disabled dates
* should * change.
*/
calendar.prototype.refresh = function () {
this._init(this.firstdayofweek, this.date);
};
/** modifies the firstdayofweek parameter (pass 0 for synday, 1 for monday, etc.). */
calendar.prototype.setfirstdayofweek = function (firstdayofweek) {
this._init(firstdayofweek, this.date);
this._displayweekdays();
};
/**
* allows customization of what dates are enabled. the unaryfunction
* parameter must be a function object that receives the date (as a js date
* object) and returns a boolean value. if the returned value is true then
* the passed date will be marked as disabled.
*/
calendar.prototype.setdatestatushandler = calendar.prototype.setdisabledhandler = function (unaryfunction) {
this.getdatestatus = unaryfunction;
};
/** customization of allowed year range for the calendar. */
calendar.prototype.setrange = function (a, z) {
this.minyear = a;
this.maxyear = z;
};
/** calls the first user handler (selectedhandler). */
calendar.prototype.callhandler = function () {
if (this.onselected) {
this.onselected(this, this.date.print(this.dateformat));
}
};
/** calls the second user handler (closehandler). */
calendar.prototype.callclosehandler = function () {
if (this.onclose) {
this.onclose(this);
}
this.hideshowcovered();
};
/** removes the calendar object from the dom tree and destroys it. */
calendar.prototype.destroy = function () {
var el = this.element.parentnode;
el.removechild(this.element);
calendar._c = null;
window._dynarch_popupcalendar = null;
};
/**
* moves the calendar element to a different section in the dom tree (changes
* its parent).
*/
calendar.prototype.reparent = function (new_parent) {
var el = this.element;
el.parentnode.removechild(el);
new_parent.appendchild(el);
};
// this gets called when the user presses a mouse button anywhere in the
// document, if the calendar is shown. if the click was outside the open
// calendar this function closes it.
calendar._checkcalendar = function(ev) {
var calendar = window._dynarch_popupcalendar;
if (!calendar) {
return false;
}
var el = calendar.is_ie ? calendar.getelement(ev) : calendar.gettargetelement(ev);
for (; el != null && el != calendar.element; el = el.parentnode);
if (el == null) {
// calls closehandler which should hide the calendar.
window._dynarch_popupcalendar.callclosehandler();
return calendar.stopevent(ev);
}
};
/** shows the calendar. */
calendar.prototype.show = 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(document, keydown, calendar._keyevent);
calendar.addevent(document, keypress, calendar._keyevent);
calendar.addevent(document, mousedown, calendar._checkcalendar);
}
this.hideshowcovered();
};
/**
* hides the calendar. also removes any hilite from the class of any td
* element.
*/
calendar.prototype.hide = function () {
if (this.ispopup) {
calendar.removeevent(document, keydown, calendar._keyevent);
calendar.removeevent(document, keypress, calendar._keyevent);
calendar.removeevent(document, mousedown, calendar._checkcalendar);
}
this.element.style.display = none;
this.hidden = true;
this.hideshowcovered();
};
/**
* shows the calendar at a given absolute position (beware that, depending on
* the calendar element style -- position property -- this might be relative
* to the parent's containing rectangle).
*/
calendar.prototype.showat = function (x, y) {
var s = this.element.style;
s.left = x + px;
s.top = y + px;
this.show();
};
/** shows the calendar near a given element. */
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 + el.offsetheight);
return true;
}
function 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 = absolute;
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 = block;
calendar.continuation_for_the_fucking_khtml_browser = function() {
var w = self.element.offsetwidth;
var h = self.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);
}
// vertical alignment
switch (valign) {
case t: p.y -= h; break;
case b: p.y += el.offsetheight; break;
case c: p.y += (el.offsetheight - h) / 2; break;
case t: p.y += el.offsetheight - h; break;
case b: break; // already there
}
// horizontal alignment
switch (halign) {
case l: p.x -= w; break;
case r: p.x += el.offsetwidth; break;
case c: p.x += (el.offsetwidth - w) / 2; break;
case l: p.x += el.offsetwidth - w; break;
case r: break; // already there
}
p.width = w;
p.height = h + 40;
self.monthscombo.style.display = none;
fixposition(p);
self.showat(p.x, p.y);
};
if (calendar.is_khtml)
settimeout(calendar.continuation_for_the_fucking_khtml_browser(), 10);
else
calendar.continuation_for_the_fucking_khtml_browser();
};
/** customizes the date format. */
calendar.prototype.setdateformat = function (str) {
this.dateformat = str;
};
/** customizes the tooltip date format. */
calendar.prototype.setttdateformat = function (str) {
this.ttdateformat = str;
};
/**
* tries to identify the date represented in a string. if successful it also
* calls this.setdate which moves the calendar to the given date.
*/
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.getcomputedstyle) == function) { // gecko, w3c
if (!calendar.is_khtml)
value = document.defaultview.
getcomputedstyle(obj, ).getpropertyvalue(visibility);
else
value = '';
} else if (obj.currentstyle) { // ie
value = obj.currentstyle.visibility;
} else
value = '';
}
return value;
};
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 = hidden;
}
}
}
};
/** internal function; it displays the bar with the names of the weekday. */
calendar.prototype._displayweekdays = function () {
var fdow = this.firstdayofweek;
var cell = this.firstdayname;
var weekend = calendar._tt[weekend];
for (var i = 0; i cell.classname = day name;
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;
calendar._add_evs(cell);
}
if (weekend.indexof(realday.tostring()) != -1) {
calendar.addclass(cell, weekend);
}
cell.innerhtml = calendar._sdn[(i + fdow) % 7];
cell = cell.nextsibling;
}
};
/** internal function. hides all combo boxes that might be displayed. */
calendar.prototype._hidecombos = function () {
this.monthscombo.style.display = none;
this.yearscombo.style.display = none;
};
/** internal function. starts dragging the element. */
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);
}
};
// begin: date object patches
/** adds the number of days array to the date object. */
date._md = new array(31,28,31,30,31,30,31,31,30,31,30,31);
/** constants used for time computations */
date.second = 1000 /* milliseconds */;
date.minute = 60 * date.second;
date.hour = 60 * date.minute;
date.day = 24 * date.hour;
date.week = 7 * date.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])
continue;
switch (b[i]) {
case %d:
case %e:
d = parseint(a[i], 10);
break;
case %m:
m = parseint(a[i], 10) - 1;
break;
case %y:
case %y:
y = parseint(a[i], 10);
(y 29) ? 1900 : 2000);
break;
case %b:
case %b:
for (j = 0; j if (calendar._mn[j].substr(0, a[i].length).tolowercase() == a[i].tolowercase()) { m = j; break; }
}
break;
case %h:
case %i:
case %k:
case %l:
hr = parseint(a[i], 10);
break;
case %p:
case %p:
if (/pm/i.test(a[i]) && hr hr += 12;
else if (/am/i.test(a[i]) && hr >= 12)
hr -= 12;
break;
case %m:
min = parseint(a[i], 10);
break;
}
}
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)
return new date(y, m, d, hr, min, 0);
y = 0; m = -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; break; }
}
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)
return new date(y, m, d, hr, min, 0);
return today;
};
/** returns the number of days in the current month */
date.prototype.getmonthdays = function(month) {
var year = this.getfullyear();
if (typeof month == undefined) {
month = this.getmonth();
}
if (((0 == (year%4)) && ( (0 != (year%100)) || (0 == (year%400)))) && month == 1) {
return 29;
} else {
return date._md[month];
}
};
/** returns the number of day in the year. */
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 = now - then;
return math.floor(time / date.day);
};
/** returns the number of the week in year, as defined in 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); // nearest thu
var ms = d.valueof(); // gmt
d.setmonth(0);
d.setdate(4); // thu in week 1
return math.round((ms - d.valueof()) / (7 * 864e5)) + 1;
};
/** checks date and time equality */
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()));
};
/** set only the year, month, date parts (keep existing time) */
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());
};
/** prints the date in a string according to the given format. */
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) ? (hr - 12) : hr;
var dy = this.getdayofyear();
if (ir == 0)
ir = 12;
var min = this.getminutes();
var sec = this.getseconds();
s[%a] = calendar._sdn[w]; // abbreviated weekday name [fixme: i18n]
s[%a] = calendar._dn[w]; // full weekday name
s[%b] = calendar._smn[m]; // abbreviated month name [fixme: i18n]
s[%b] = calendar._mn[m]; // full month name
// fixme: %c : preferred date and time representation for the current locale
s[%c] = 1 + math.floor(y / 100); // the century number
s[%d] = (d s[%e] = d; // the day of the month (range 1 to 31)
// fixme: %d : american date style: %m/%d/%y
// fixme: %e, %f, %g, %g, %h (man strftime)
s[%h] = (hr s[%i] = (ir s[%j] = (dy s[%k] = hr; // hour, range 0 to 23 (24h format)
s[%l] = ir; // hour, range 1 to 12 (12h format)
s[%m] = (m s[%m] = (min s[%n] = \n; // a newline character
s[%p] = pm ? pm : am;
s[%p] = pm ? pm : am;
// fixme: %r : the time in am/pm notation %i:%m:%s %p
// fixme: %r : the time in 24-hour notation %h:%m
s[%s] = math.floor(this.gettime() / 1000);
s[%s] = (sec s[%t] = \t; // a tab character
// fixme: %t : the time in 24-hour notation (%h:%m:%s)
s[%u] = s[%w] = s[%v] = (wn s[%u] = w + 1; // the day of the week (range 1 to 7, 1 = mon)
s[%w] = w; // the day of the week (range 0 to 6, 0 = sun)
// fixme: %x : preferred date representation for the current locale without the time
// fixme: %x : preferred time representation for the current locale without the date
s[%y] = ('' + y).substr(2, 2); // year without the century (range 00 to 99)
s[%y] = y; // year with the century
s[%%] = %; // a literal '%' character
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.setfullyear = function(y) {
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
// global object that remembers the calendar
window._dynarch_popupcalendar = null;
//********* calendar.js end ********************
/* copyright mihai bazon, 2002, 2003 | http://dynarch.com/mishoo/
* ---------------------------------------------------------------------------
*
* the dhtml calendar
*
* details and latest version at:
* http://dynarch.com/mishoo/calendar.epl
*
* this script is distributed under the gnu lesser general public license.
* read the entire license text here: http://www.gnu.org/licenses/lgpl.html
*
* this file defines helper functions for setting up the calendar. they are
* intended to help non-programmers get a working calendar on their site
* quickly. this script should not be seen as part of the calendar. it just
* shows you what one can do with the calendar, while in the same time
* providing a quick and simple method for setting it up. if you need
* exhaustive customization of the calendar creation process feel free to
* modify this code to suit your needs (this is recommended and much better
* than modifying calendar.js itself).
*/
// $id: calendar-setup.js,v 1.25 2005/03/07 09:51:33 mishoo exp $
/**
* this function patches an input field (or other element) to use a calendar
* widget for date selection.
*
* the params is a single object that can have the following properties:
*
* prop. name | description
* -------------------------------------------------------------------------------------------------
* inputfield | the id of an input field to store the date
* displayarea | the id of a div or other element to show the date
* button | id of a button or other element that will trigger the calendar
* eventname | event that will trigger the calendar, without the on prefix (default: click)
* ifformat | date format that will be stored in the input field
* daformat | the date format that will be used to display the date in displayarea
* singleclick | (true/false) wether the calendar is in single click mode or not (default: true)
* firstday | numeric: 0 to 6. 0 means display sunday first, 1 means display monday first, etc.
* align | alignment (default: br); if you don't know what's this see the calendar documentation
* range | array with 2 elements. default: [1900, 2999] -- the range of years available
* weeknumbers | (true/false) if it's true (default) the calendar will display week numbers
* flat | null or element id; if not null the calendar will be a flat calendar having the parent with the given id
* flatcallback | function that receives a js date object and returns an url to point the browser to (for flat calendar)
* disablefunc | function that receives a js date object and should return true if that date has to be disabled in the calendar
* onselect | function that gets called when a date is selected. you don't _have_ to supply this (the default is generally okay)
* onclose | function that gets called when the calendar is closed. [default]
* onupdate | function that gets called after the date is updated in the input field. receives a reference to the calendar.
* date | the date that the calendar will be initially displayed to
* showstime | default: false; if true the calendar will include a time selector
* timeformat | the time format; can be 12 or 24, default is 12
* electric | if true (default) then given fields/date areas are updated for each move; otherwise they're updated only on close
* step | configures the step of the years in drop-down boxes; default: 2
* position | configures the calendar absolute position; default: null
* cache | if true (but default: false) it will reuse the same calendar object, where possible
* showothers | if true (but default: false) it will show days from other months too
*
* none of them is required, they all have default values. however, if you
* pass none of inputfield, displayarea or button you'll get a warning
* saying nothing to setup.
*/
calendar.setup = function (params) {
function param_default(pname, def) { if (typeof params[pname] == undefined) { params[pname] = def; } };
param_default(inputfield, null);
param_default(displayarea, null);
param_default(button, null);
param_default(eventname, click);
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]); // takes precedence if both are defined
param_default(datetext, null);
param_default(firstday, null);
param_default(align, br);
param_default(range, [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(date, null);
param_default(showstime, false);
param_default(timeformat, 24);
param_default(electric, true);
param_default(step, 2);
param_default(position, null);
param_default(cache, false);
param_default(showothers, false);
param_default(multiple, null);
var tmp = [inputfield, displayarea, button];
for (var i in tmp) {
if (typeof params[tmp[i]] == string) {
params[tmp[i]] = document.getelementbyid(params[tmp[i]]);
}
}
if (!(params.flat || params.multiple || params.inputfield || params.displayarea || params.button)) {
alert(calendar.setup:\n nothing to setup (no fields found). please check your code);
return false;
}
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)
p.displayarea.innerhtml = cal.date.print(p.daformat);
if (update && typeof p.onupdate == function)
p.onupdate(cal);
if (update && 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 flat specified but can't find parent.);
return false;
}
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();
return false;
}
var triggerel = params.button || params.displayarea || params.inputfield;
triggerel[on + params.eventname] = function() {
var dateel = params.inputfield || params.displayarea;
var datefmt = params.inputfield ? params.ifformat : params.daformat;
var mustcreate = false;
var cal = window.calendar;
if (dateel)
params.date = date.parsedate(dateel.value || dateel.innerhtml, datefmt);
if (!(cal && params.cache)) {
window.calendar = cal = new calendar(params.firstday,
params.date,
params.onselect || onselect,
params.onclose || function(cal) { cal.hide(); });
cal.showstime = params.showstime;
cal.time24 = (params.timeformat == 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], params.range[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]);
return false;
};
return cal;
};
//************ calendar-setup.js end *********************
// ** i18n
// calendar big5-utf8 language
// author: gary fu,
// encoding: utf8
// distributed under the same terms as the calendar itself.
// for translators: please use utf-8 if possible. we strongly believe that
// unicode is the answer to a real internationalized world. also please
// include your contact information in the header, as can be seen above.
// full day names
calendar._dn = new array
(星期日,
星期一,
星期二,
星期三,
星期四,
星期五,
星期六,
星期日);
// please note that the following array of short day names (and the same goes
// for short month names, _smn) isn't absolutely necessary. we give it here
// for exemplification on how one can customize the short day names, but if
// they are simply the first n letters of the full name you can simply say:
//
// calendar._sdn_len = n; // short day name length
// calendar._smn_len = n; // short month name length
//
// if n = 3 then this is not needed either since we assume a value of 3 if not
// present, to be compatible with translation files that were written before
// this feature.
// short day names
calendar._sdn = new array
(日,
一,
二,
三,
四,
五,
六,
日);
// first day of the week. 0 means display sunday first, 1 means display
// monday first, etc.
calendar._fd = 0;
// full month names
calendar._mn = new array
(一月,
二月,
三月,
四月,
五月,
六月,
七月,
八月,
九月,
十月,
十一月,
十二月);
// short month names
calendar._smn = new array
(一月,
二月,
三月,
四月,
五月,
六月,
七月,
八月,
九月,
十月,
十一月,
十二月);
// tooltips
calendar._tt = {};
calendar._tt[info] = 關於;
calendar._tt[about] =
dhtml date/time selector\n +
(c) dynarch.com 2002-2005 / author: mihai bazon\n + // don't translate this this ;-)
for latest version visit: http://www.dynarch.com/projects/calendar/\n +
distributed under gnu lgpl. see http://gnu.org/licenses/lgpl.html for details. +
\n\n +
日期選擇方法:\n +
- 使用 \xab, \xbb 按鈕可選擇年份\n +
- 使用 + string.fromcharcode(0x2039) + , + string.fromcharcode(0x203a) + 按鈕可選擇月份\n +
- 按住上面的按鈕可以加快選取;
calendar._tt[about_time] = \n\n +
時間選擇方法:\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] = (今日);
// the following is to inform that %s is to be the first day of week
// %s will be replaced with the day name.
calendar._tt[day_first] = 將 %s 顯示在前;
// this may be locale-dependent. it specifies the week-end days, as an array
// of co
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product