JAVASCRIPT 6
Dateselect.js Guest on 8th April 2021 04:11:55 AM
  1. //****************************************************************************
  2. // jsDateSelect 1.1
  3. //****************************************************************************
  4. //      Author: Maxx 1,5k  <maxx@e-taller.net>
  5. //         WWW: http://www.e-taller.net/dateselect/
  6. //    Category: Date/Time
  7. // Description: A GUI control to select date in an HTML form.
  8. //              Has been tested in MSIE4+, NN4, NN6, Mozilla.
  9. //****************************************************************************
  10. // The lib is FREEWARE. This means you can use it anywhere you want, you can
  11. // do anything with it. Author is NOT responsible for any consequences of
  12. // using this library.
  13. // If you don't agree with this, you SHOULD NOT use the lib.
  14. //****************************************************************************
  15. // All improvings, feature requests, bug reports, etc. are gladly accepted.
  16. //****************************************************************************
  17. // Note: For best viewing of the code Tab size 3 is recommended
  18. //****************************************************************************
  19.  
  20. var NS = (document.all) ? false : true; // MSIE vs. Others
  21. var LAYERS = (document.layers) ? true : false; // NN4 vs. Others
  22. var calWinSize = [160,111];
  23. var calMonths = ['Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'];
  24. var calWeek = ['Lu','Ma','Mi','Ju','Vi','S&aacute;','Do'];
  25. var calMonthDays = [31,28,31,30,31,30,31,31,30,31,30,31];
  26. var curInput = null;
  27.  
  28. var yearFrom      = 2009;
  29. var yearTo        = yearFrom+10;
  30. var calUseTransit = false;    // Whether to use transition alpha effects in MSIE
  31. var calOpacity = 100;         // Final opacity of the control in MSIE
  32. var calOpacitySteps = 10;     // Number of steps when changing opacity in MSIE
  33.  
  34. if(LAYERS)
  35.       document.write("<layer id=calMain visibility=hide bgcolor=#dddddd><br></layer>");
  36. else
  37.       document.write("<div id=calMain class=cl_out style='position:absolute; display:none; background-color:#dddddd;'><br></div>");
  38.  
  39.  
  40. //****************************************************************************
  41. function calGetDate(dateBtn, dateField) {
  42.       calPosX = (LAYERS) ? dateBtn.x : dateBtn.offsetLeft;
  43.       calPosY = (LAYERS) ? dateBtn.y : dateBtn.offsetTop + dateBtn.offsetHeight;
  44.       for(el=dateBtn.offsetParent; el!=null; el=el.offsetParent) {
  45.             calPosX += el.offsetLeft; calPosY += el.offsetTop;
  46.       }
  47.       if(!LAYERS) {
  48.             bodyWidth = (NS) ? document.body.offsetWidth : document.body.clientWidth-5;
  49.             while((calPosX > 0) && ((calPosX+calWinSize[0]) > bodyWidth)) calPosX--;
  50.       }
  51.  
  52.       curInput = (NS) ? dateField : dateField.name;
  53.       curDate = dateField.value.split("/"); nowDate = new Date();
  54.       curDate[1] = parseInt(curDate[1]); curDate[2] = parseInt(curDate[2]);
  55.       if(curDate[1]); // WTF? I get a bug without this line
  56.       calFillInside((((curDate[1]>=1)&&(curDate[1]<=12)) ? (curDate[1]-1) : nowDate.getMonth()), ((curDate[2]>=1900) ? curDate[2] : nowDate.getFullYear()));
  57.  
  58.       main = (LAYERS) ? document.layers.calMain : (NS) ? document.getElementById('calMain') : document.all.calMain;
  59.       if(LAYERS) {
  60.             main.left = calPosX; main.top = calPosY;
  61.             main.visibility = "show";
  62.       } else {
  63.             main.style.left = calPosX; main.style.top = calPosY;
  64.             if(NS||((!NS)&&(!calUseTransit))) main.style.display = ''; else calTransitShow(true, 0);
  65.       }
  66.       return false;
  67.  
  68. }
  69.  
  70. //****************************************************************************
  71. function calTransitShow(isShow, step) {
  72.       obj = document.all.calMain;
  73.       opStart = (isShow) ? 0 : calOpacity;
  74.       opEnd = (isShow) ? calOpacity : 0;
  75.       if(!step) {
  76.             obj.style.filter = "alpha(opacity="+opStart+")";
  77.             obj.style.display = "";
  78.             setTimeout("calTransitShow("+isShow+","+(step+1)+")", 1);
  79.       } else if(step <= (calOpacitySteps+1)) {
  80.             opacity = parseInt( (opStart-opEnd) * (step-1) / calOpacitySteps );
  81.             if(opacity < 0) opacity = -opacity;
  82.             if(!isShow) opacity = 100 - opacity;
  83.             obj.style.filter = "alpha(opacity="+opacity+")";
  84.             setTimeout("calTransitShow("+isShow+","+(step+1)+")", 1);
  85.       } else {
  86.             obj.style.display = (isShow) ? "" : "none";
  87.       }
  88. }
  89.  
  90. //****************************************************************************
  91. function calExit(day, mon, yea) {
  92.       if(LAYERS) {
  93.             with(document.layers.calMain.document) {
  94.                   open("text/html"); write("<br>"); close();
  95.             }
  96.             document.layers.calMain.visibility = "hide";
  97.       } else {
  98.             obj = (NS) ? document.getElementById('calMain') : document.all.calMain;
  99.             if(NS||((!NS)&&(!calUseTransit))) obj.style.display = "none"; else calTransitShow(false, 0);
  100.             obj.innerHTML = "<br>";
  101.       }
  102.       if(curInput && day && (++mon) && yea) {
  103.             curInputObj = (NS) ? curInput : document.all[curInput];
  104.             curInputObj.value = ((day < 10)?"0":"")+day + "/" + ((mon < 10)?"0":"")+mon + "/" + yea;
  105.       }
  106.       return false;
  107. }
  108.  
  109. //****************************************************************************
  110. function calFillInside(mon, yea) {
  111.       date1 = new Date(yea, mon, 0);
  112.       wek1 = date1.getDay(); monthdays = calMonthDays[mon] + (((mon == 1) && (!(yea % 4))) ? 1 : 0);
  113.       main = (LAYERS) ? document.layers.calMain : (NS) ? document.getElementById('calMain') : document.all.calMain;
  114.       if(LAYERS) {
  115.             main.width = calWinSize[0];
  116.             main.height = calWinSize[1] + (((monthdays + wek1) > 35) ? 16 : 0);
  117.       } else {
  118.             main.style.width = calWinSize[0];
  119.             main.style.height = calWinSize[1] + (((monthdays + wek1) > 35) ? 16 : 0);
  120.       }
  121.  
  122.       out="";
  123.       if(LAYERS) {
  124.             out += "<table border=1 width="+(4+calWinSize[0])+" cellspacing=1 cellpadding=0><tr><th>";
  125.                   out += "<div class=cl_dayns4>";
  126.                   out += "<a class=cl_dayns4 href='javascript:' onclick='return calFillInside("+((mon>0)?mon-1:11)+","+yea+");'>&lt;&lt;&nbsp;</a>";
  127.                   out += calMonths[mon];
  128.                   out += "<a class=cl_dayns4 href='javascript:' onclick='return calFillInside("+((mon<11)?mon+1:0)+","+yea+");'>&nbsp;&gt;&gt;</a>";
  129.                   out += "</div>";
  130.             out += "</th><th>";
  131.                   out += "<div class=cl_dayns4>";
  132.                   out += "<a class=cl_dayns4 href='javascript:' onclick='return calFillInside("+mon+","+(yea-1)+");'>&lt;&lt;&nbsp;</a>";
  133.                   out += yea;
  134.                   out += "<a class=cl_dayns4 href='javascript:' onclick='return calFillInside("+mon+","+(yea+1)+");'>&nbsp;&gt;&gt;</a>";
  135.                   out += "</div>";
  136.             out += "</th><th>";
  137.                   out += "<a class=cl_dayns4 href='javascript:' onclick='return calExit(0,0,0);'>&nbsp;X&nbsp;</a>";
  138.             out += "</th></tr></table>";
  139.       } else {
  140.             out += "<table border=0 width=100% cellspacing=0 cellpadding=0><tr><th width=10% class=cl_out>";
  141.                   out += "<select name=calMon class=cl_sel onchange='calFillInside(this.value,"+yea+")'>";
  142.                   for(i=0; i<12; i++) out += "<option value="+i+((i==mon)?" selected":"")+">"+calMonths[i]+"</option>";
  143.                   out += "</select>";
  144.             out += "</th><th width=10% class=cl_out>";
  145.                   out += "<select name=calYea class=cl_sel onchange='calFillInside("+mon+",this.value)'>";
  146.                   for(i=yearFrom; i<=yearTo; i++) out += "<option value="+i+((i==yea)?" selected":"")+">"+i+"</option>";
  147.                   out += "</select>";
  148.             out += "</th><th class=cl_out>";
  149.                   out += "<a "+((NS)?"href='javascript:' ":"")+"style='cursor:hand; font:bold xx-small Verdana; color:black; width:100%; text-decoration:none;' onclick='return calExit(0,0,0);' title='Cerrar'>X</a><br>";
  150.             out += "</th></tr></table>";
  151.       }
  152.  
  153.       out += "<table width="+((LAYERS)?4+calWinSize[0]:"100%")+" border="+((LAYERS)?1:0)+" cellspacing=1 cellpadding=0 cols=7><tr>";
  154.             for(i=0; i<7; i++) out += ((LAYERS) ? "<th class=cl_wek>"+calWeek[i]+"</th>" : "<th class=cl_out><div class=cl_wek>"+calWeek[i]+"</div></th>");
  155.             out += "</tr>";
  156.  
  157.             if(wek1 > 0) {
  158.                   out += "<tr>";
  159.                   for(daycnt=0; daycnt<wek1; daycnt++) out += "<th></th>";
  160.             } else daycnt = 0;
  161.             for(i=0; i<31; i++) {
  162.                   if(i >= monthdays) break;
  163.                   if(!(daycnt % 7)) {
  164.                         if(daycnt > 0) out += "</tr>";
  165.                         out += "<tr>";
  166.                   }
  167.                   out += "<th class=cl_in onmouseover='this.className=\"cl_out\";' onmouseout='this.className=\"cl_in\";'>";
  168.                   out += "<a class=cl_day"+((LAYERS)?"ns4 ":" ")+((NS|LAYERS)?"href='javascript:' ":"")+"onclick='return calExit("+(i+1)+","+mon+","+yea+");'>"+(i+1)+"</a></th>";
  169.                   daycnt++;
  170.             }
  171.       out += "</tr></table>";
  172.  
  173.       if(LAYERS) {
  174.             with(document.layers.calMain.document) {
  175.                   open("text/html"); write(out); close();
  176.             }
  177.       } else {
  178.             obj = (NS) ? document.getElementById('calMain') : document.all.calMain;
  179.             obj.innerHTML = out;
  180.       }
  181.       return false;
  182. }

Paste-bin is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.