📄 calendar.js
字号:
/*****************************************************
* My97 DatePicker Ver 3.0.1
* BLOG: http://blog.csdn.net/my97/
* MAIL: smallcarrot@163.com
****************************************************/
if(navigator.product=='Gecko')
{Document.prototype.attachEvent=function(sType,fHandler){var shortTypeName=sType.replace(/on/,"");
fHandler._ieEmuEventHandler=function(e){window.event=e;return fHandler();};
this.addEventListener(shortTypeName,fHandler._ieEmuEventHandler,false);};
Event.prototype.__defineSetter__("returnValue",function(value){if(!value){this.preventDefault();}return value;});
Event.prototype.__defineGetter__("srcElement",function(){var node=this.target;
while(node.nodeType!=1){node=node.parentNode;}
return node;});
HTMLElement.prototype.attachEvent=function(sType,fHandler)
{var shortTypeName=sType.replace(/on/,"");
fHandler._ieEmuEventHandler=function(e){window.event=e;return fHandler();};
this.addEventListener(shortTypeName,fHandler._ieEmuEventHandler,false);};
HTMLElement.prototype.insertAdjacentElement=function(where,parsedNode){switch(where){case"beforeBegin":
this.parentNode.insertBefore(parsedNode,this);
break;
case"afterBegin":
this.insertBefore(parsedNode,this.firstChild);
break;
case"beforeEnd":
this.appendChild(parsedNode);
break;
case"afterEnd":
if(this.nextSibling){this.parentNode.insertBefore(parsedNode,this.nextSibling);}
else{this.parentNode.appendChild(parsedNode);}
break;}};}
$BindAsEventListener=function(sender,listener){var __method=sender;
return function(event){return __method.call(listener,event||window.event);}}
function __sb()
{this.s=new Array();
this.i=0;
this.a=function(t){this.s[this.i++]=t;};
this.j=function(){return this.s.join('');};}
if(!window.$){$ = function(){var elements = new Array();for (var i=0;i<arguments.length;i++){var element=arguments[i];
if (typeof element=='string'){element=document.getElementById(element);}if (arguments.length==1){return element;}elements.push(element);}return elements;}}
var $d=null;
function My97DatePicker(){if(parent==window)return;
if(navigator.product!='Gecko'){
if(location.href.substring(location.href.length-3).toLowerCase()=='#97'){location.replace(location.href.substring(0,location.href.length-3));
return;}
else{location.replace(location.href+"#97");}
history.go(-1);}
this.init();
this.dd=document.createElement("DIV");
this.dd.style.cssText='position:absolute;z-index:197;display:block;';
this.dd.obj=this;
this.dd.className="WdateDiv";
this.dd.innerHTML=this._createPickerHTML();
var tmpImgs=this.dd.getElementsByTagName('img');
this.dd.navLeftImg=tmpImgs[0];
this.dd.leftImg=tmpImgs[1];
this.dd.rightImg=tmpImgs[2];
this.dd.navRightImg=tmpImgs[3];
this.dd.navLeftImg.onclick=function(){$d.yInput.value=parseInt($d.yInput.value)-1;
$d.obj.redraw();}
this.dd.leftImg.onclick=function(){if(parseInt($d.mInput.getAttribute("realValue"))>1){$d.mInput.setAttribute("realValue",parseInt($d.mInput.getAttribute("realValue"))-1);}
else{$d.mInput.setAttribute("realValue",12);
$d.yInput.value=parseInt($d.yInput.value)-1;}
$d.mInput.value=dpcfg.aMonStr[parseInt($d.mInput.getAttribute("realValue"))-1];
$d.obj.redraw();}
this.dd.rightImg.onclick=function(){if(parseInt($d.mInput.getAttribute("realValue"))<12){$d.mInput.setAttribute("realValue",parseInt($d.mInput.getAttribute("realValue"))+1);}
else{$d.mInput.setAttribute("realValue",1);
$d.yInput.value=parseInt($d.yInput.value)+1;}
$d.mInput.value=dpcfg.aMonStr[parseInt($d.mInput.getAttribute("realValue"))-1];
$d.obj.redraw();}
this.dd.navRightImg.onclick=function(){$d.yInput.value=parseInt($d.yInput.value)+1;
$d.obj.redraw();}
var tmpInputs=this.dd.getElementsByTagName('input');
this.dd.mInput=tmpInputs[0];
this.dd.yInput=tmpInputs[1];
this.dd.mInput.setAttribute('realValue',this.month);
this.dd.mInput.value=dpcfg.aMonStr[this.month-1];
this.dd.yInput.value=this.year;
var tmpDivs=this.dd.getElementsByTagName('div');
this.dd.titleDiv=tmpDivs[0];
this.dd.mDiv=tmpDivs[3];
this.dd.yDiv=tmpDivs[5];
this.dd.dDiv=tmpDivs[7];
this.dd.tDiv=tmpDivs[8].firstChild;
this.dd.bDiv=tmpDivs[10];
this.dd.dDiv.innerHTML=this._createDateTable();
this._inputKeydown=function(){var evt=event;
var k=(evt.which==undefined)?evt.keyCode:evt.which;
if(!((k>=48&&k<=57)||(k>=96&&k<=105)||k==8||k==46||k==37||k==39||k==9)){evt.returnValue=false;}};
this.dd.mInput.attachEvent('onkeydown',function(){var evt=event;
var k=(evt.which==undefined)?evt.keyCode:evt.which;
if(k==9){$d.mDiv.style.display='none';}
if(event.srcElement.value.length-document.selection.createRange().text.length==2){event.returnValue=false;};});
this.dd.yInput.attachEvent('onkeydown',function(){var evt=event;
var k=(evt.which==undefined)?evt.keyCode:evt.which;
if(k==9){$d.yDiv.style.display='none';}});
this.dd.mInput.attachEvent('onkeydown',this._inputKeydown);
this.dd.yInput.attachEvent('onkeydown',this._inputKeydown);
this.dd.yInput.onblur=function(){var v=parseInt(this.value);
if(v<$d.obj.minDate.year){this.value=$d.obj.minDate.year;}
else if(v>$d.obj.maxDate.year){this.value=$d.obj.maxDate.year;}
if(v!=$d.obj.year){$d.obj.redraw();}
this.className='yminput';};
this.dd.mInput.onblur=function(){if(parseInt(this.value)>12){this.value='12';}
else if(v<1){this.value='1';}
var tmpYM=$d.obj.year*100+parseInt(this.value)*1;
if(tmpYM<($d.obj.minDate.year*100+$d.obj.minDate.month*1)){this.value=$d.obj.minDate.month;}
else if(tmpYM>($d.obj.maxDate.year*100+$d.obj.maxDate.month*1)){this.value=$d.obj.maxDate.month;}
var v=parseInt(this.value);
this.setAttribute('realValue',v);
this.value=dpcfg.aMonStr[v-1]
if(v!=$d.obj.month){$d.obj.redraw();}
this.className='yminput';};
this.dd.mInput.onfocus=function(){this.className='yminputfocus';
this.value=this.getAttribute("realValue");
this.select();
if($d.obj.hasDate){$d.obj._fillmonth();
$d.mDiv.style.display='block';}};
this.dd.yInput.onfocus=function(){this.className='yminputfocus';
this.select();
if($d.obj.hasDate){$d.obj._fillyear();
$d.yDiv.style.display='block';}};
this.dd.hhInput=tmpInputs[2];
this.dd.hmSplitInput=tmpInputs[3];
this.dd.mmInput=tmpInputs[4];
this.dd.msSplitInput=tmpInputs[5];
this.dd.ssInput=tmpInputs[6];
this.dd.clearInput=tmpInputs[7];
this.dd.todayInput=tmpInputs[8];
this.dd.okInput=tmpInputs[9];
this.dd.hhInput.onfocus=this.dd.mmInput.onfocus=this.dd.ssInput.onfocus=function(){this.select();$d.obj.currFocus=this;};
this.dd.hhInput.onblur=function(){if(parseInt(this.value)>23){this.value='23';}
else if(parseInt(this.value)<0){this.value='0';}};
this.dd.mmInput.onblur=this.dd.ssInput.onblur=function(){if(parseInt(this.value)>59){this.value='59';}
else if(parseInt(this.value)<0){this.value='0';}};
this.dd.hmSplitInput.attachEvent('onfocus',function(){$d.mmInput.focus();});
this.dd.msSplitInput.attachEvent('onfocus',function(){$d.ssInput.focus();});
this.dd.ssInput.attachEvent('onkeydown',function(){var evt=event;
var k=(evt.which==undefined)?evt.keyCode:evt.which;
if(k==9){$d.downButton.focus();}});
this.dd.hhInput.attachEvent('onkeydown',this._inputKeydown);
this.dd.mmInput.attachEvent('onkeydown',this._inputKeydown);
this.dd.ssInput.attachEvent('onkeydown',this._inputKeydown);
var tmpBtn=this.dd.getElementsByTagName('button');
this.dd.upButton=tmpBtn[0];
this.dd.downButton=tmpBtn[1];
this.dd.upButton.onclick=function(){if($d.obj.currFocus==undefined){$d.obj.currFocus=$d.mmInput;}
if(($d.obj.currFocus==$d.hhInput&&parseInt($d.obj.currFocus.value)<23)||($d.obj.currFocus!=$d.hhInput&&parseInt($d.obj.currFocus.value)<59)){$d.obj.currFocus.value=parseInt($d.obj.currFocus.value)+1;}
else{$d.obj.currFocus.value='0';}
$d.obj.currFocus.focus();};
this.dd.downButton.onclick=function(){if($d.obj.currFocus==undefined){$d.obj.currFocus=$d.mmInput;}
if(parseInt($d.obj.currFocus.value)>0){$d.obj.currFocus.value=parseInt($d.obj.currFocus.value)-1;}
else{if($d.obj.currFocus==$d.hhInput){$d.obj.currFocus.value='23';}
else{$d.obj.currFocus.value='59';}}
$d.obj.currFocus.focus();};
$d=this.dd;
document.body.insertAdjacentElement('beforeEnd',this.dd);
this._setOkInput();
this._setShowAndHide();}
My97DatePicker.prototype.init=function(){this._todayDate=new Date();
this.t_year=this._todayDate.getFullYear();
this.t_month=this._todayDate.getMonth()+1;
this.t_date=this._todayDate.getDate();
this.t_hour=this._todayDate.getHours();
this.t_minute=this._todayDate.getMinutes();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -