WdatePicker.js
上传用户:tjxpgg
上传日期:2017-05-14
资源大小:2244k
文件大小:8k
源码类别:

SilverLight

开发平台:

ASP/ASPX

  1. /*****************************************************
  2.  * My97 DatePicker Ver 3.0.1
  3.  * BLOG: http://blog.csdn.net/my97/
  4.  * MAIL: smallcarrot@163.com
  5.  ****************************************************/
  6. $position=0;
  7. $dpPath='';
  8. var $dp=null;if(!window.$){$ = function(){var elements = new Array();for (var i=0;i<arguments.length;i++){var element=arguments[i];
  9. if (typeof element=='string'){element=document.getElementById(element);}if (arguments.length==1){return element;}elements.push(element);}return elements;}}
  10. function $getClientWidthHeight(w){var win=w||window;if(win.document.documentElement&&win.document.documentElement.scrollTop){return{'width':win.document.documentElement.clientWidth,'height':win.document.documentElement.clientHeight};}
  11. else if(win.document.body){return{'width':win.document.body.clientWidth,'height':win.document.body.clientHeight};}}
  12. function $getScroll(w){var win=w||window;
  13. if(win.document.documentElement&&win.document.documentElement.scrollTop){return{'top':win.document.documentElement.scrollTop,'left':win.document.documentElement.scrollLeft};}
  14. else if(win.document.body){return{'top':win.document.body.scrollTop,'left':win.document.body.scrollLeft};}}
  15. function $getAbsM(topWin)
  16. {if(topWin==null){topWin=top;}
  17. var leftM=0;var topM=0;
  18. var tempWin=window;
  19. while(tempWin!=topWin){var ifs=tempWin.parent.document.getElementsByTagName('iframe');
  20. for(var i=0;i<ifs.length;i++){try{if(ifs[i].contentWindow==tempWin.window){var rc=$getBoundingClientRect(ifs[i]);
  21. leftM+=rc.left;
  22. topM+=rc.top;
  23. break;}}
  24. catch(e){continue;}}
  25. tempWin=tempWin.parent;}
  26. return{'leftM':leftM,'topM':topM};}
  27. function $getBoundingClientRect(obj){if(navigator.product=='Gecko'){var objWin=null;
  28. var top=obj.offsetTop;
  29. var left=obj.offsetLeft;
  30. var right=obj.offsetWidth;
  31. var bottom=obj.offsetHeight;
  32. while(obj=obj.offsetParent){
  33. top+=obj.offsetTop;left+=obj.offsetLeft;
  34. if(obj.tagName.toLowerCase()=="body"){objWin=obj.ownerDocument.defaultView;}}
  35. var theScroll=$getScroll(objWin);
  36. left-=theScroll.left;
  37. top-=theScroll.top;
  38. right+=left;
  39. bottom+=top;
  40. return{'left':left,'top':top,'right':right,'bottom':bottom};}
  41. else{return obj.getBoundingClientRect();}}
  42. if(navigator.product=='Gecko')
  43. {Window.prototype.attachEvent = function(sType,fHandler){var shortTypeName=sType.replace(/on/,"");
  44. fHandler._ieEmuEventHandler=function(e){window.event=e; return fHandler(); };
  45. this.addEventListener(shortTypeName,fHandler._ieEmuEventHandler,false);};Document.prototype.attachEvent=function(sType,fHandler){var shortTypeName=sType.replace(/on/,"");fHandler._ieEmuEventHandler=function(e){window.event=e;return fHandler();};
  46. this.addEventListener(shortTypeName,fHandler._ieEmuEventHandler,false);};
  47. Document.prototype.createStyleSheet=function(cssPath){var head=document.getElementsByTagName('HEAD').item(0);
  48. var style=document.createElement('link');
  49. style.href=cssPath;
  50. style.rel='stylesheet';
  51. style.type='text/css';
  52. head.appendChild(style);};
  53. HTMLElement.prototype.insertAdjacentElement=function(where,parsedNode){switch(where){case"beforeBegin":
  54. this.parentNode.insertBefore(parsedNode,this);
  55. break;
  56. case"afterBegin":
  57. this.insertBefore(parsedNode,this.firstChild);
  58. break;
  59. case"beforeEnd":
  60. this.appendChild(parsedNode);
  61. break;
  62. case"afterEnd":
  63. if(this.nextSibling){this.parentNode.insertBefore(parsedNode,this.nextSibling);}
  64. else{this.parentNode.appendChild(parsedNode);}
  65. break;}};
  66. HTMLIFrameElement.prototype.__defineGetter__("Document",function(){return this.contentDocument});}
  67. function WdatePicker(el,dateFmt,showTime,skin,onPicked){this.win=window;
  68. this.top=window;
  69. while(this.top.parent.document!=this.top.document&&this.top.parent.document.getElementsByTagName("frameset").length==0){this.top=this.top.parent;}
  70. if(navigator.product=='Gecko'){if(!this.top.HTMLElement.prototype.insertAdjacentElement){this.top.HTMLElement.prototype.insertAdjacentElement=HTMLElement.prototype.insertAdjacentElement;}
  71. if(!this.top.Document.prototype.attachEvent){this.top.Document.prototype.attachEvent=Document.prototype.attachEvent;}if(!this.top.Window.prototype.attachEvent){this.top.Window.prototype.attachEvent=Window.prototype.attachEvent;}}
  72. this.eCont=(typeof el=='string')?document.getElementById(el):el;
  73. this.dateFmt=dateFmt;
  74. this.showTime=showTime;
  75. this.skin=skin;
  76. if(this.top.document.dateDiv==null){if($dpPath==''){$dpPath=this._createDpPath();}
  77. this.dd=this.top.document.createElement("DIV");
  78. this.dd.style.cssText='position:absolute;z-index:19700;';
  79. this.dd.obj=this;
  80. this.dd.className="WdateDiv";
  81. this.dd.innerHTML='<iframe src="'+$dpPath+'My97DatePicker.htm#97" frameborder="0" border="0" width="1px" height="1px" scrolling="no" ></iframe>';
  82. this.top.document.body.insertAdjacentElement('afterBegin',this.dd);
  83. this.top.document.dateDiv=this.dd;}
  84. else{var td=this.top.document.dateDiv;
  85. td.obj.win=this.win;
  86. td.obj.eCont=this.eCont;
  87. td.obj.dateFmt=this.dateFmt;
  88. td.obj.showTime=this.showTime;
  89. td.obj.skin=this.skin;
  90. var dwin=td.childNodes[0].contentWindow;
  91. var d=dwin.$d;
  92. this.dd=this.top.document.dateDiv;
  93. d.obj.init();
  94. d.yDiv.style.display=d.mDiv.style.display='none';
  95. d.navLeftImg.src='skin/'+d.obj.skin+"/navLeft.gif";
  96. d.leftImg.src='skin/'+d.obj.skin+"/left.gif";
  97. d.rightImg.src='skin/'+d.obj.skin+"/right.gif";
  98. d.navRightImg.src='skin/'+d.obj.skin+"/navRight.gif";
  99. d.mInput.setAttribute('realValue',d.obj.month);
  100. d.mInput.value=dwin.dpcfg.aMonStr[d.obj.month-1];
  101. d.yInput.value=d.obj.year;
  102. if(this.showTime){d.tDiv.style.display='block';
  103. d.hhInput.value=d.obj.hour;
  104. d.mmInput.value=d.obj.minute;
  105. d.ssInput.value=d.obj.sec;}
  106. else{d.tDiv.style.display='none';}
  107. this.dd.style.display='block';
  108. d.obj._setOkInput();
  109. d.obj._setShowAndHide();
  110. d.obj.redraw();}
  111. $dp=this.top.$dp=this.top.document.dateDiv;
  112. var objxy=$getBoundingClientRect(this.eCont);
  113. var mm=$getAbsM(this.top);
  114. var currWinSize=$getClientWidthHeight(this.top);
  115. var theScroll=$getScroll(this.top);
  116. var ddTop=mm.topM+objxy.bottom;
  117. var ddLeft=mm.leftM+objxy.left;
  118. var ddHeight=Math.max(parseInt(this.dd.offsetHeight),(this.dateFmt&&this.dateFmt.indexOf('%D')>0)?180:30);
  119. var ddWidth=Math.max(parseInt(this.dd.offsetWidth),180);
  120. if(($position==2)||(($position==0)&&((ddTop+ddHeight<currWinSize.height)||(ddTop-ddHeight<ddHeight*0.8))))
  121. {this.dd.style.top=(theScroll.top+ddTop+1)+'px';}
  122. else{this.dd.style.top=(theScroll.top+ddTop-ddHeight-this.eCont.offsetHeight-3)+'px';}
  123. this.dd.style.left=-1+theScroll.left+Math.min(ddLeft,currWinSize.width-ddWidth-5)+'px';
  124. if(!this.win.document.hasDispose){this.win.document.attachEvent('onmousedown',disposeDatePicker);
  125. this.win.document.hasDispose=true;}
  126. if(!this.top.document.hasDispose){this.top.document.attachEvent('onmousedown',disposeDatePicker);
  127. this.top.document.hasDispose=true;}
  128. if(!this.win.document.hasUnload){this.win.attachEvent('onbeforeunload',function(){$dp.style.display='none';});
  129. this.win.document.hasUnload=true;}}
  130. WdatePicker.prototype._createDpPath=function(){var path='';
  131. var i;
  132. path=$dpjspath
  133. if(path.substring(0,1)!="/"&&path.indexOf('://')==-1){var a=this.top.location.href;
  134. var b=location.href;
  135. var al='',bl='',bls='';
  136. var j,s='';
  137. for(i=0;i<Math.max(a.length,b.length);i++){if(a.charAt(i).toLowerCase()!=b.charAt(i).toLowerCase()){j=i;
  138. while(a.charAt(j)!='/'){if(j==0){break;}j-=1;}
  139. al=a.substring(j+1,a.length);
  140. al=al.substring(0,al.lastIndexOf('/'));
  141. bl=b.substring(j+1,b.length);
  142. bl=bl.substring(0,bl.lastIndexOf('/'));
  143. break;}}
  144. if(al!=''){for(i=0;i<al.split('/').length;i++){s+="../";}}
  145. if(bl!=''){s+=bl+'/';}
  146. path=s+path;}
  147. return path;};
  148. function disposeDatePicker(){var src=null;
  149. if(window.event){src=event.srcElement||event.target;}
  150. if($dp!=undefined&&$dp.obj!=undefined&&$dp.style.display!='none'&&src!=$dp.obj.eCont)
  151. {var d=$dp.childNodes[0].contentWindow.$d;
  152. if(d.obj.eCont.value==''||d.obj._judgeCorrectDateTime(d.obj.eCont.value)){d.obj._markValue(true);
  153. if(d.obj.eCont.value!=''){d.obj._initDate(d.obj.eCont.value,d.obj.dateFmt);
  154. d.obj._setRealValue();}
  155. else{d.obj.eCont.setAttribute("REALVALUE","");}}
  156. else{d.obj._markValue(false);}
  157. $dp.style.display='none';}}
  158. var $dpjspath;
  159. var scripts=document.getElementsByTagName("script");
  160. for(i=0;i<scripts.length;i++){if(scripts[i].src.substring(scripts[i].src.length-14).toLowerCase()=='wdatepicker.js'){$dpjspath=scripts[i].src.substring(0,scripts[i].src.length-14);
  161. break;}}
  162. document.createStyleSheet($dpjspath+'skin/WdatePicker.css');