|
|
|
<html> <title>Calendario con recordatorios</title> <head> <SCRIPT LANGUAGE="JavaScript">
<!-- to hide script contents from old browsers // Cookie Functions // Written by: Bill Dortch, hIdaho Design // The following functions are released to the public domain. // "Internal" function to encode cookie value. This permits cookies to // contain whitespace, comma and semicolon characters.
function encode (str) { var dest = ""; var len = str.length; var index = 0; var code = null; for (var i = 0; i < len; i++) { var ch = str.charAt(i); if (ch == " ") code = "%20"; else if (ch == "%") code = "%25"; else if (ch == ",") code = "%2C"; else if (ch == ";") code = "%3B"; else if (ch == "") code = "%08"; else if (ch == " ") code = "%09"; else if (ch == " ") code = "%0A"; else if (ch == "f") code = "%0C"; else if (ch == " ") code = "%0D"; if (code != null) { dest += str.substring(index,i) + code; index = i + 1; code = null; } }
if (index < len) dest += str.substring(index, len); return dest; }
//
// "Internal" function to decode cookie values. //
function decode (str) {
var dest = ""; var len = str.length; var index = 0; var code = null; var i = 0; while (i < len) { i = str.indexOf ("%", i); if (i == -1) break; if (index < i) dest += str.substring(index, i); code = str.substring (i+1,i+3); i += 3; index = i; if (code == "20") dest += " "; else if (code == "25") dest += "%"; else if (code == "2C") dest += ","; else if (code == "3B") dest += ";"; else if (code == "08") dest += ""; else if (code == "09") dest += " "; else if (code == "0A") dest += " "; else if (code == "0C") dest += "f"; else if (code == "0D") dest += " "; else { i -= 2; index -= 3; } }
if (index < len) dest += str.substring(index, len); return dest; }
//
// "Internal" function to return the decoded value of a cookie //
function getCookieVal (offset) { var endstr = document.cookie.indexOf (";", offset); if (endstr == -1) endstr = document.cookie.length; return decode(document.cookie.substring(offset, endstr)); }
//
// Function to return the value of the cookie specified by "name". // name - String object containing the cookie name. //
function GetCookie (name) { var arg = name + "="; var alen = arg.length; var clen = document.cookie.length; var i = 0; while (i < clen) { var j = i + alen; if (document.cookie.substring(i, j) == arg) return getCookieVal (j); i = document.cookie.indexOf(" ", i) + 1; if (i == 0) break; }
return null; }
//
// Function to create or update a cookie. // name - String object object containing the cookie name // value - String object containing the cookie value. May contain // any valid sting characters, including whitespace, commas and quotes. // expires - Date object containing the expiration data of the cookie, // or null to expire the cookie at the end of the current session. //
function SetCookie (name, value, expires) {
document.cookie = name + "=" + encode(value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString()));
}
// Function to delete a cookie. (Sets expiration date to current date/time)
// name - String object containing the cookie name
//
function DeleteCookie (name) { var exp = new Date(); var cval = GetCookie (name); document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
// // Example //
function intro()
{ document.write ("<CENTER>"); document.writeln("<BR>");
document.write ("<h3>"); document.write ("Calendario con recordatorios"); document.writeln("</h3>"); document.writeln("</CENTER>"); document.writeln("<h4>Cómo usar este calendario:</h4>"); document.writeln("<ul><li>Pulsa en una fecha para añadir un recordatorio"); document.writeln(" <li>Pulsa en esa fecha para ver el recordatorio"); document.writeln(" <li>Refresca la pantalla para ver las fechas con sus recordatorios"); document.writeln("</ul>"); document.writeln("<h4>Notas:</h4>"); document.writeln("<ul><li>Interfaz de usuario sencillo"); document.writeln(" <li>No se puede borrar un recordatorio"); document.writeln(" <li>Los recordatorios desaparecen en 24 horas"); document.writeln("</ul>"); document.writeln("<h4>Este programa es un buen ejemplo de...</h4>"); document.writeln("<ul><li>Cómo usar cookies en javascript"); document.writeln(" <li>Usar enlaces de texto para llamar a una función, sin llamar a una URL"); document.writeln("</ul>"); document.writeln("<h4>Créditos:</h4>"); document.writeln("<ul><li>Funciones relativas a cookies escritas por: <A href=´mailto:bdortch@netw.com´>Bill Dortch</A>, hIdaho Design"); document.writeln("<ul>Las funciones están en:"); document.writeln(" <li>Code: <A href=´http://www.hidaho.com/cookies/cookie.txt´>http://www.hidaho.com/cookies/cookie.txt</A>"); document.writeln(" <li>Demo: <A href=´http://www.hidaho.com/cookies/cookie.html´>http://www.hidaho.com/cookies/cookie.html</A>"); document.writeln("</ul>"); document.writeln(" <li>´Reminder Calendar´ por James Thiele, que puede ser contactado en:"); document.writeln(" <UL><LI>su página web:"); document.writeln(" <A href=´http://www.eskimo.com/~jet´>http://www.eskimo.com/~jet</A>"); document.writeln(" <LI> o por email: "); document.writeln(" <address><A href=´mailto:jet@eskimo.com´>jet@eskimo.com</a></address></p>"); document.writeln("</ul>");
}
function arrayOfDaysInMonths(isLeapYear) {
this[0] = 31; this[1] = 28; if (isLeapYear)
this[1] = 29;
this[2] = 31; this[3] = 30; this[4] = 31; this[5] = 30; this[6] = 31; this[7] = 31; this[8] = 30; this[9] = 31; this[10] = 30; this[11] = 31;
}
function daysInMonth(month, year) {
// do the classic leap year calculation
var isLeapYear = (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)); var monthDays = new arrayOfDaysInMonths(isLeapYear); return monthDays[month];
}
function calendar()
{
var monthNames = "JanFebMarAprMayJunJulAugSepOctNovDec"; var today = new Date(); var day = today.getDate(); var month = today.getMonth(); var year = today.getYear();
// figure out how many days this month will have...
var numDays = daysInMonth(month, year);
// and go back to the first day of the month...
var firstDay = today; firstDay.setDate(1);
// and figure out which day of the week it hits...
var startDay = firstDay.getDay();
var column = 0;
// Start the calendar table
document.write("<CENTER>"); document.write("<TABLE BORDER>"); document.write("<TR><TH COLSPAN=7>"); document.write(monthNames.substring(3*month, 3*(month + 1)) + " " + year); document.write("<TR><TH>Dom<TH>Lun<TH>Mar<TH>Mié<TH>Jue<TH>Vie<TH>Sáb");
// put blank table entries for days of week before beginning of the month
document.write("<TR>");
for (i=1; i < startDay; i++)
{
document.write("<TD>"); column++; }
for (i=1; i <= numDays; i++) { // Write the day
var s = "" + i; if ((GetCookie("d"+i) != null))
// s = s.fontcolor(document.vlinkColor); s = s.fontcolor("#FF0000"); s = s.link("javascript:dayClick(" + i + ")") document.write("<TD>" + s);
// Check for end of week/row
if (++column == 7) { document.write("<TR>"); // start a new row column = 0; }
}
document.write("</TABLE>"); document.writeln("</CENTER>"); }
//////////////////////////// //////// dayClick ////////// ////////////////////////////
function dayClick(day) {
var expdate = new Date (); expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000)); // 24 hrs from now var prefix = "d"; var theCookieName = prefix + day; var theDayclickedReminder = GetCookie(theCookieName);
if (theDayclickedReminder != null) { alert("El recordatorio para el día " + day + " es:" + theDayclickedReminder);
} // end if if (confirm("¿Quieres entrar un recordatorio para el día " + day + " de este mes?"))
{ x = prompt("Entra un recordatorio para el día "+ day + " de este mes", theDayclickedReminder);
SetCookie (theCookieName, x, expdate);
} // end if
}
// --> <!-- end hiding contents from old browsers -->
</SCRIPT> <BODY> <font face="arial" size="1"> Pulsa en un día del calendario para guardar un recordatorio o cita.<br> La próxima vez que hagas click en ese día, te mostrará ese recordatorio. <br> La información sólo se guarda durante 24 horas. </font>
<SCRIPT LANGUAGE="JavaScript">
<!-- to hide script contents from old browsers // Write the intro // Write the calendar
calendar(); document.write("<HR>"); intro();
// --> <!-- end hiding contents from old browsers -->
</SCRIPT> </BODY> </HTML>
|
|