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

📄 date.js

📁 ShopEx网店系统是一款免费的独立网店系统
💻 JS
字号:
Object.extend (Date.prototype, {	i18nMonthNames: [      __("January"),__("February"),__("March"),__("April"),__("May"),__("June"),      __("July"),__("August"),__("September"),__("October"),__("November"),__("December")  ],  i18nDayNames: [__("Sunday"),__("Monday"),__("Tuesday"),__("Wednesday"),__("Thursday"),__("Friday"),__("Saturday")],  i18nShortDayNames: [__("Sun"),__("Mon"),__("Tue"),__("Wed"),__("Thu"),__("Fri"),__("Sat")],   i18nPreviousMonth: __("Previous month"),  i18nNextMonth: __("Next month"),  i18nToday: __("Today"),  i18nClose: __("Close"),  isLeap: function(){    return 1 == new Date(this.getFullYear(),1,29).getMonth();  },  isSameDateAs: function(date){    return (this.getFullYear()  == date.getFullYear()          && this.getMonth()     == date.getMonth()         && this.getDate()      == date.getDate () )  },  	stripDate: function(){		this.setHours(0);		this.setMinutes(0);		this.setSeconds(0);		this.setMilliseconds(0);		return this;	},  isWeekEnd: function(){    return this.getDay() == 0 || this.getDay() == 6;  },    getDaysInMonth: function(){    return [31,(this.isLeap()?29:28),31,30,31,30,31,31,30,31,30,31][this.getMonth()]  },    getMySqlDate: function(){    return [this.getFullYear(),           (this.getMonth() <= 8 ? '0'+(this.getMonth()+1)	: this.getMonth()+1),            (this.getDate()	< 10 ? '0'+this.getDate()				: this.getDate())    ].join('-')  },  parseMySqlDate: function(str){    var tokens = str.split('-');    if (tokens.length == 3){      this.setYear(tokens[0]);      this.setMonth(Number(tokens[1]) - 1);      this.setDate(tokens[2]);    }	else if ($(str).value && $(str).value.split('-').length == 3){				return this.parseMySqlDate( $(str).value );		}else if ($(str).value && $(str).innerHTML.split('-').length == 3){			return this.parseMySqlDate( $(str).innerHTML );		}    return this  },  	backOneMonth: function(){		if (this.getMonth() == 0){			this.setYear(this.getFullYear() - 1);			this.setMonth(11);		}else{			this.setMonth(this.getMonth()-1)		}		return this;	},	  getMonthStartDay: function(){    var date = this;     date.setDate(1);    return date.getDay();  },  getYearStartDay: function(){     var date = this;    date.setDate(1);    date.setMonth(0);    return date.getMonthStartDay ();  },  onClick: function(event, date){    this.setDate(date.getDate());    this.setMonth(date.getMonth());    this.setYear(date.getFullYear());    if (this.element.innerHTML){			this.element.innerHTML = date.getMySqlDate();		} else {			this.element.value = date.getMySqlDate();		}	Validation.runtime.checkNow = true;	this.close();  },  onClickDisabled: function(event){		Effect.Shake(this.container, {duration:0.15})  },  onClickArrows: function(event, date){    this.setDate(date.getDate());    this.setMonth(date.getMonth());    this.setYear(date.getFullYear());    this.getMonthHTML();  },      close: function(event){    if (typeof this.options.onComplete == 'function') {      this.options.onComplete(this.element, this.options);	}	X.menus.runtime.m.push(this.container);	X.menus.close();//		Effect.SlideUp(this.container, {duration:0.15});  },    	open: function(event){		if(!this.container.style.position || this.container.style.position=='absolute') {     	this.container.style.position = 'absolute';     	this.container.style.zIndex = 100;		this.container.onmouseover = function(){Validation.runtime.checkNow = false;}		this.container.onmouseout = function(){Validation.runtime.checkNow = true;}     	Position.clone(this.element, this.container, {setHeight: false,offsetTop: this.element.offsetHeight});		}		X.menus.bind(this.container,{noPop:true});  },      getMonthHTML: function(){		var table = document.createElement('table');		table.className = 'calendar_table';				var thead = document.createElement('thead');		thead.className = 'calendar_table_thead';		var tr		= document.createElement('tr');		var th		= document.createElement('th');		th.colSpan = '7';				var headerTable = document.createElement('table');		headerTable.style.width = '100%';		var headerThead = document.createElement('thead');		var headerTr		= document.createElement('tr');				// previous, today and next month controls		var headerCol1	= document.createElement('th');		headerCol1.style.textAlign = 'left'		headerCol1.className = 'calendar_table_header_th';		// previous month		var prevLink		= document.createElement('a');//		prevLink.setAttribute('href', 'javascript:void(null)');		prevLink.setAttribute('title', this.i18nPreviousMonth);		prevLink.appendChild(document.createTextNode('\u2190')) // larr		prevLink.className = 'calendar_table_header_navLink';		Event.observe(prevLink, "click",			this.onClickArrows.bindAsEventListener(				this, 				new Date(this.getFullYear(), this.getMonth(), this.getDate()).backOneMonth()			)		);		headerCol1.appendChild(prevLink);		// today		var todayLink 	= document.createElement('a');//		todayLink.setAttribute('href', 'javascript:void(null)');		todayLink.setAttribute('title', this.i18nToday);		todayLink.appendChild(document.createTextNode('today'));		todayLink.className = 'calendar_table_header_navLink';		Event.observe(todayLink, "click",			this.onClickArrows.bindAsEventListener(this,new Date())		);		headerCol1.appendChild(todayLink);		// next month		var nextLink = document.createElement('a');//		nextLink.setAttribute('href', 'javascript:void(null)');		nextLink.setAttribute('title', this.i18nNextMonth);		nextLink.appendChild(document.createTextNode('\u2192')) // rarr		nextLink.className = 'calendar_table_header_navLink';		Event.observe(nextLink, "click",			this.onClickArrows.bindAsEventListener(this, 				new Date(this.getFullYear(), this.getMonth()+1, this.getDate())			)		);		headerCol1.appendChild(nextLink);		headerTr.appendChild(headerCol1);		// this will hold the month and year		var headerCol2	= document.createElement('th');		headerCol2.className = 'calendar_table_header_th';		headerCol2.appendChild(document.createTextNode(this.i18nMonthNames[this.getMonth()]));		headerCol2.appendChild(document.createTextNode('\u00a0' + this.getFullYear()));		// close link 		var headerCol3	= document.createElement('th');		headerCol3.className = 'calendar_table_header_th';		var closeLink = document.createElement('a');		closeLink.setAttribute('href', 'javascript:void(null)');		closeLink.setAttribute('title', this.i18nClose);		closeLink.appendChild(document.createTextNode( (document.all ? '\u2191' : '\u2297') ))//		closeLink.className = 'calendar_table_header_navLink';		Event.observe(closeLink, "click",	this.close.bindAsEventListener(this) );		headerCol3.appendChild(closeLink);				headerTr.appendChild(headerCol1);		headerTr.appendChild(headerCol2);		headerTr.appendChild(headerCol3);				headerThead.appendChild(headerTr);		headerTable.appendChild(headerThead);		th.appendChild(headerTable);		tr.appendChild(th);		thead.appendChild(tr);				// days of the week		var daysTr = document.createElement('tr');		for (var i = 0; i < 7; i++){			var dayTh = document.createElement('th');			dayTh.className = 'calendar_table_header_dayName';			dayTh.appendChild(document.createTextNode(this.i18nShortDayNames[i]))			dayTh.setAttribute('title', this.i18nDayNames[i]);			daysTr.appendChild(dayTh);		}		thead.appendChild(daysTr);				// days of the month		var tbody = document.createElement('tbody');		var cellDate = 0 - this.getMonthStartDay();		var maxDate = this.getDaysInMonth();		var maxDays = Math.ceil((this.getDaysInMonth() + this.getMonthStartDay()) / 7);		for (var i = 0; i < maxDays; i++){			var tr = document.createElement('tr');			for (var j = 0; j < 7; j++){				cellDate++;				var cellDateObject = new Date(this.getFullYear(), this.getMonth(), cellDate);				cellDateObject.stripDate();				var td = document.createElement('td');				td.style.width = '14%';								if (cellDate >= 1 && cellDate <= maxDate){					td.appendChild(document.createTextNode(cellDate));					td.className = 'calendar_cell_curr_month';				}else{					td.appendChild(document.createTextNode(cellDateObject.getDate()));					td.className = 'calendar_cell_not_curr_month';				}				if (	(this.options.weekends	== false && (cellDateObject.isWeekEnd()))					||	(this.options.disabled	&& this.options.disabled.indexOf(cellDateObject.getMySqlDate()) > -1) 					||  (this.options.before 	&& cellDateObject >= this.options.before.stripDate())					||	(this.options.after		&& cellDateObject <= this.options.after.stripDate())				) 				{					td.className += ' calendar_cell_disabled';					Event.observe(td, "click", this.onClickDisabled.bindAsEventListener (this));				} else {					Event.observe(td, "click", this.onClick.bindAsEventListener(this,cellDateObject));				}								if ( cellDateObject.isSameDateAs(new Date()) ){					td.className += ' calendar_cell_today';				}								tr.appendChild(td);			}			tbody.appendChild(tr);		}				table.appendChild(thead);		table.appendChild(tbody);				if (this.container.hasChildNodes()){			this.container.replaceChild(table, this.container.firstChild)		}else{			this.container.appendChild(table);		}  },  datePicker: function(element, options){		this.stripDate();  		this.element = $(element);		if (!$(this.element.id + "_calendar_container")){			var container = document.createElement('div');			container.setAttribute('id',this.element.id + "_calendar_container");			document.body.appendChild(container)		}		this.container = $(this.element.id + "_calendar_container");    this.options = options || {};     this.parseMySqlDate(this.element.id);    if (typeof this.options.after == 'string'){			this.options.after = new Date().parseMySqlDate(this.options.after);			if (new Date() < this.options.after){				this.setYear(this.options.after.getFullYear());				this.setMonth(this.options.after.getMonth());				this.setDate(this.options.after.getDate()+1);			}		} else this.options.after = false;				if (typeof this.options.before == 'string'){			this.options.before = new Date().parseMySqlDate(this.options.before)			if (new Date() > this.options.before){				this.setYear(this.options.before.getFullYear());				this.setMonth(this.options.before.getMonth());				this.setDate(this.options.before.getDate()-1);			}		} else this.options.before = false;		    this.getMonthHTML();    this.open();  }});

⌨️ 快捷键说明

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