Online Documentation Server
 ПОИСК
ods.com.ua Web
 КАТЕГОРИИ
Home
Programming
Net technology
Unixes
Security
RFC, HOWTO
Web technology
Data bases
Other docs

 


 ПОДПИСКА

 О КОПИРАЙТАХ
Вся предоставленная на этом сервере информация собрана нами из разных источников. Если Вам кажется, что публикация каких-то документов нарушает чьи-либо авторские права, сообщите нам об этом.




Previous Table of Contents Next

The setCal() function creates the calendar. The calendar is created by the same functions as those in Example 14-3 (Chapter 14, Time and Date in JavaScript). The only difference is the following:

if (digit == date) { // current cell represents today's date
text += '<TD HEIGHT=' + cellHeight + '>'
text += '<FONT COLOR="' + todayColor + '">'
text += '<A HREF="javascript:getInput(' + digit + ', \'' + monthName +
  '\')" onMouseOver="window.status = \'Store or retrieve
  data for ' + monthName + ' ' + digit + '\'; return true">
  <FONT COLOR="' + todayColor + '">' + digit + '</FONT></A>'
text += '<BR>'
text += '<FONT COLOR="' + timeColor + '" SIZE=2>'
text += '<CENTER>' + getTime() + '</CENTER>'
text += '</FONT>'
text += '</TD>'
} else
text += '<TD HEIGHT=' + cellHeight + '><A HREF="javascript:getInput('
  + digit + ', \'' + monthName + '\')" onMouseOver="window
  .status = \'Store or retrieve data for ' + monthName + ' '
  + digit + '\'; return true">' + digit + '</A></TD>'

This statement differs from its corresponding one in Example 14-3 in that, instead of writing the date as a plain number, it makes each number a link that invokes the getInput() function, using the javascript:getInput() URL. The exact syntax of the URL is as follows:

javascript:getInput(digit, monthName)

The first argument is the digit that serves as a link (an integer from 1 to 28, 29, 30, or 31). The second argument is a string—the full name of the current month reflected by the calendar. Figure 24-1 outlines the links that trigger the getInput() function, when clicked:


Figure 24-1.  A reminder calendar where each date is a link to the getInput() function.

Note that when the user places the mouse pointer over a link, a related message is assigned to the status bar. We will only discuss the functions that are responsible for the cookie handling and storage because the functions that create the calendar are discussed in Chapter 14, Time and Date in JavaScript.

getInput(num, monthName)

function getInput(num, monthName) {
if (!getCookie(monthName + "Calendar"))
initCookie(monthName)
var newValue = prompt("Enter reminder for current date:",
   getSpecificReminder(num, monthName))
if (newValue) // user did not cancel
setSpecificReminder(num, monthName, newValue)
}

The getInput() function, in general, reads the reminder from the cookie, asks the user to modify it or enter it for the first time, and then saves the reminder back to the cookie. First, it gets the reminder text from the cookie, the name of which is composed of the name of the current month and the “Calendar” string. The name selection algorithm prevents mixing cookies between different months or different applications. If the cookie is not found, the function initCookie() is called to create a cookie with empty reminders, one for each day of the month. The script then prompts the user for a reminder, displaying the old one in the form’s input field. Notice that the reminder is displayed in the field of a prompt dialog box by specifying the value returned by getSpecificReminder(), as the second argument for the prompt() method. If the user did not press Cancel as a response to the request form, the new information is saved in the cookie by the setSpecificReminder() function. Figure 24-2 outlines the method used to display a reminder and enable modification.


Figure 24-2.  The date ‘January 3rd’ already consisted of a reminder so when clicking on it, the text is displayed in the box, giving an option to modify it.

initCookie(monthName)

function initCookie(monthName) {
 // initializes cookie with the following format:
 // ^1^^2^^3^^4^...^30^^31^
 // initialize accumulative variable
 var text = ""
 for (var i = 1; i <= 31; ++i) {
text += "^" + i + "^"
 }
 var now = new Date()
 fixDate(now)

 // set time to one month (31 days) in the future
 now.setTime(now.getTime() + 1000 * 60 * 60 * 24 * 31)

 setCookie(monthName + "Calendar", text, now)
}

The initCookie() function creates a cookie with empty reminders, one for every day of the month. The cookie’s text is a string concatenation of all 31 reminders, delimited by “^” from each other. The function first builds the empty string, fixes the date for Mac computers, computes the time, and finally sets the cookie, saving the empty reminders, date, and time in it.

Previous Table of Contents Next


With any suggestions or questions please feel free to contact us