Calendar and events : Events Calendar « GUI Components « JavaScript DHTML

JavaScript DHTML
1. Ajax Layer
2. Data Type
3. Date Time
4. Development
5. Document
6. Event
7. Event onMethod
8. Form Control
9. GUI Components
10. HTML
11. Javascript Collections
12. Javascript Objects
13. Language Basics
14. Node Operation
15. Object Oriented
16. Page Components
17. Security
18. Style Layout
19. Table
20. Utilities
21. Window Browser
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
JavaScript DHTML » GUI Components » Events Calendar 
Calendar and events


<!--
The Object-Oriented Events Calender
        Version 3.0

 Copyright (c1999 -- Edward Narkiewicz -- ednark@wm.edu

Questions, comments, or bugs.. just email me...

----------
*Liscence
----------
I have opened this software up under the GNU Public Liscence. Basically, you can do anything you want to it, change it, even sell it, as long as you offer it for free also. I have incliuded the Liscence text file for all who really care.


---------
*Purpose
---------
To produce a minimal javascript solution for a Small Organization's Events Calendar. User's knowledge of this script needs only be restricted to HTML and javascript useage, not programming. 

This is Intended as an alternative to CGI programming (perl php javaby those who either do not access to a a cgi-enabled server or by those who do not have the knowledge to program for one.

This non-DTML Javascript Calender is comparatively equivalent to a cgi-version but is a much simpler solution which requires no special configuration from the server end of things.


-------------
*Description
-------------
This package consists of two files both ".js". One library of Calendar calls and one Database of events. More than one Databse of events may be included.

There is one big array 'EVENTS' which holds all events under the index.

You can make as many calendars as you want on the page. 

The Calendar has view. 
1compact monthly view with links to a day's events.
2a full monthly view listing all events for all days.
3a view of all events for a single week.
4a view of all events for a single day.

-------
*USAGE
-------
QUICK - make and display the december 2000... and add an event for singing christmas carols on christmas day

-------------------------------->
-HTML CODE:
-------------------------------->
<HTML>
<HEAD>
        <SCRIPT LANGUAGE="JAVASCRIPT" SRC="calendar.js"></SCRIPT>
        <SCRIPT LANGUAGE="JAVASCRIPT" SRC="events.js"></SCRIPT>
</HEAD>
<BODY>

<SCRIPT LANGUAGE="javascript">
  var Dec2000 = new CalendarMonth(2000,12)// no parameters means you want the current month
  Dec2000.displayMonth();
</SCRIPT>

</BODY>
</HTML>
-------------------------------->


-------------------------------->
-EVENTS.JS CODE:
-------------------------------->
var evnt1 = new CalendarEvent(2000,12,25);
evnt1.name = "Christmas Day";
evnt1.time = "All Day";
evnt1.location = "Everywhere";
evnt1.description = "Christmas Carols and Presents";
evnt1.addEvent();
-------------------------------->

-------------------
*Events Explained
-------------------
You must make an event. Then manipulate it's attributes directly. Any .js file may contain event entries. Each event must end with a <name>.addEvent(); call to put it into a list for the calendar to use.
  
The originial idea was to put all events in a single file...

You may do something like this if you wish... but you will have to go in a manually change the include calls whenever you want... where each .js file lives in the same diretory as the page calling it... 

   
        <SCRIPT LANGUAGE="JAVASCRIPT" SRC="calendar.js"></SCRIPT>
   <SCRIPT LANGUAGE="JAVASCRIPT" SRC="DECEMBERevents.js"></SCRIPT>
        <SCRIPT LANGUAGE="JAVASCRIPT" SRC="JANUARYevents.js"></SCRIPT>
        <SCRIPT LANGUAGE="JAVASCRIPT" SRC="FEBUARYevents.js"></SCRIPT>
        <SCRIPT LANGUAGE="JAVASCRIPT" SRC="MARCHevents.js"></SCRIPT>



-------------------
*Library Explained
-------------------
from top of file to bottom:: better off to read through the documented calendar file itself

-- You have the option of hard coding a colorscheme into the calender. Defined in the top of the file and implemented in CSS. This should be self-explanitory when you look at the top of the file.

-- General Date Knowledge: the names of the months, days of the week, etc... so that you may easily adapt to a different language...

-- An Event: you make an event by (1declaring it (2setting its values (3adding it to a list of events...

(1)
    var event1 = new CalenderEvent(2000,1,01)//--> 4 digit year, 1-2 digit month, 1-2 digit day
(2)
    event1.name = 'name of event string';
    event1.time = 'time the event is going to happen';
    event1.location = 'location event is happening';
    event1.description = 'description of event';
(3)
    event1.addEvent()

The file 'events.js' or any file you choose must contain code in the above form for as many events as you wish. They must all be entered by hand. Any event files must be loaded -after- calendar.js has been loaded.

-- The CalendarMonth itself: months are numbered from 1->12
  three ways to make a calendar.

(1the most useful way... gets current month and year from viewer's computer (as does all javascript)

  var newCal = new CaledarMonth();
  newCal.displayMonth();

(2you may specify a year:
   
  var newCal = new CaledarMonth(2001);
  newCal.displayMonth();

(3you may specify both year and month: december 2001
  
  var newCal = new CaledarMonth(2001,12);
  newCal.displayMonth();

-- You may manipulate the months as so...
  
  var newCal = new CaledarMonth();

  newCal.lastYear();     // moves the calender one year back
  newCal.changeYear(-1)// moves the calender one year back
  newCal.changeYear(-2)// moves the calender two years back
  
  newCal.nextYear();     // moves the calender one year ahead
  newCal.changeYear(1);  // moves the calender one year ahead
  newCal.changeYear(2);  // moves the calender two years ahead

  newCal.lastMonth();     // moves the calender one month back
  newCal.changeMonth(-1)// moves the calender one month back
  newCal.changeMonth(-2)// moves the calender two months back
  
  newCal.nextMonth();     // moves the calender one month ahead
  newCal.changeMonth(1);  // moves the calender one month ahead
  newCal.changeMonth(2);  // moves the calender two months ahead

  newCal.yesterday();     // moves the calender one day back
  newCal.changeDay(-1);   // moves the calender one day back
  newCal.changeDay(-2);   // moves the calender two days back
  
  newCal.tomorrow();      // moves the calender one day ahead
  newCal.changeDay(1);    // moves the calender one months ahead
  newCal.changeDay(2);    // moves the calender two months ahead

  newCal.displayMonth();  // writes calendar to the screen

-- popupDay -- only called by calendar itself, but you may if you wish
  opens a new window and diplays a single day's events
  popupDayYYYYMMDD );

-- popupWeek -- only called by calendar itself, but you may if you wish

  opens a new window and diplays a single week's events
  popupDayyear, month, day of week the month starts on sun->sat, first legal day of week 1->31, last legal day of week 1->31 );

-- popupMonth -- only called by calendar itself, but you may if you wish

  opens a new window and diplays all of a month's events
  popupDayyear, month, day of the week the month starts on sun->sat );

-DONE!!



  




-->
<HTML>
<HEAD>

<SCRIPT LANGUAGE="JAVASCRIPT">
/**********************************************************
The Object-Oriented Events Calendar
        Version 3.0

 Copyright (c) 1999 --  Edward Narkiewicz
                ednark@wm.edu

Created for The Gay Student Union
@ The College of William and Mary

This should include calendar.js, events.js, and the GPL

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
**********************************************************/

  /**********************************************************
          set Colors for Calendar
                                Empty is transparent or page deafult
  **********************************************************/
     var titleBackgroundColor = '#8080FF';
     var titleFontColor = '#FFFFFF';

     var daysofweekBackgroundColor = '#8080FF';
     var daysofweekFontColor = '#FFFFFF';

  var blankBackgroundColor = '';
  var blankFontColor = ''
  var blankString = '&nbsp;';

  var pastBackgroundColor = '#C0C0FF';
  var pastFontColor = '#FFFFFF';

  var presentBackgroundColor = '#0000FF';
  var presentFontColor = '#FFFFFF';

  var futureBackgroundColor = '#A0A0FF';
  var futureFontColor = '#FFFFFF';

  var eventLinkColor = '#FF0000';

  /**********************************************************
          set Colors for PopupWindow
                                Empty is transparent or page deafult
  **********************************************************/
  var monthBackgroundColor = '#0000FF';
  var monthFontColor = '#FFFFFF';

  var nameBackgroundColor = '#8080FF';
  var nameFontColor = '#000000';

  var timeBackgroundColor = '#A0A0FF';
  var timeFontColor = '#000000';

  var locationBackgroundColor = '#A0A0FF';
  var locationFontColor = '#000000';

  var descriptionBackgroundColor = '#C0C0FF';
  var descriptionFontColor = '#000000';


  /**********************************************************
    Create StyleSheet for Color Scheme
  **********************************************************/
  var css = '';
  css += '<STYLE type="text/css"><!-- \n';
  css += '.Title {background-color:' + titleBackgroundColor + '; color:' + titleFontColor + '} \n';
  css += '.DayOfWeek {background-color:' + daysofweekBackgroundColor + '; color:' + daysofweekFontColor + '} \n';
  css += '.Blank {background-color:' + blankBackgroundColor + '; color:' + blankFontColor + '} \n';
  css += '.Past {background-color:' + pastBackgroundColor + '; color:' + pastFontColor + '} \n';
  css += '.Present {background-color:' + presentBackgroundColor + '; color:' + presentFontColor + '} \n';
  css += '.Future {background-color:' + futureBackgroundColor + '; color:' + futureFontColor + '} \n';
  css += '.Event color:' + eventLinkColor + '} \n';
  css += '.Month {background-color:' + monthBackgroundColor + '; color:' + monthFontColor + '} \n';
  css += '.Name {background-color:' + nameBackgroundColor + '; color:' + nameFontColor + '} \n';
  css += '.Time {background-color:' + timeBackgroundColor + '; color:' + timeFontColor + '} \n';
  css += '.Location {background-color:' + locationBackgroundColor + '; color:' + locationFontColor + '} \n';
  css += '.Description {background-color:' + descriptionBackgroundColor + '; color:' + descriptionFontColor + '} \n';
  css += '--></STYLE> \n';
  document.writeln(css);

/**********************************************************
 A bit of global knowledge our program should have
**********************************************************/
var fullNameOfMonth = new Array'January', 'February', 'March',
            'April', 'May', 'June', 'July',
            'August', 'September', 'October',
            'November', 'December' );

var shortNameOfMonth = new Array'Jan', 'Feb', 'Mar',
                    'Apr', 'May', 'Jun', 'Jul',
                  'Aug', 'Sep', 'Oct',
                  'Nov', 'Dec' );

var daysInMonth = new Array(  312831303130,
          313130313031 );

var fullDayOfWeek = new Array'Sunday', 'Monday', 'Tuesday',
                               'Wednesday', 'Thursday',
                               'Friday', 'Saturday');

var shortDayOfWeek = new Array'Sun', 'Mon', 'Tue', 'Wed',
            'Thr', 'Fri', 'Sat');


/**********************************************************
 EVENT LIST DEFINITION
        In concept this is an EventList Object but...
        There is no need to make this it's own object
        since there will only ever be one list in this version.
        You only get the array and the addition function...
**********************************************************/
var Events = new Array();

/**********************************************************
 EVENT CONSTRUCTOR DEFINITION
        var <event> = new CalendarEvent(YYYY,MM,DD);
        <event>.name = <name string>;
        <event>.time = <time string>;
        <event>.location = <location string>;
        <event>.description = <description string>;
        <event>.addEvent();
**********************************************************/
function CalendarEvent(year,month,day)
{
  /**********************************************************
                        Date defaults will be given to the current day to save
                         us from any possible errors later on...
       **********************************************************/
        var now = new Date();     ///  format :: Wed Dec 13 06:49:08 GMT-0800 (Pacific Standard Time) 2000

        this.year = now.getYear();     /// # years from 1900
        ifthis.year < 1000 /// if it gives less than 4 digits
        {
          if(this.year > 90/// if it's somewhere in the 1990's
          {
            this.year += 1900
          }
          else /// it's after 2000
          {
            this.year += 2000
          }
        }
        ifyear)
        {
                this.year = year;
        }

        this.month = now.getMonth()+1// 1->12
        ifmonth )
        {
                this.month = month;
        }

        this.day = now.getDate();
        ifday )
        {
                this.day = day;
        }

  /**********************************************************
    Specific information will be entered by directly
    accessing these variables... no need to hassle
    over method calls to do this.. but for clarity they
    will have to be called spereately
       **********************************************************/
        this.name = '';
        this.time = '';
        this.location = '';
        this.description = '';
}


/**********************************************************
<event>.addEvent();
        this just adds the event to a list so we
        know where to look for it when we are
        writing the calendar
**********************************************************/
CalendarEvent.prototype.addEvent = function()
{
        /**********************************************************
        Regular Expression Check.. we want to enter items into the
        array in a very specific yyyyMMdd format... so we can access
        them easily... to do this we need to make sure the month
        and day are in two digit format...
        im going to assume the year is in 4 digit format... i don't
        know how to fix it if it isn't... so i'll just pretend it will never
        happen                 :)

                if the month or day is not in Digit Digit format...
                assume it is [0...9] and add a prefix of 0... i would
                just check ( < 10 ) but i don't know if 09 is equivelant
                to 9 in this situation and we don't want two leaeding 0's.
                the  <digit> + '' + <digit>
                is to make sure javascript concatenates as the string
                as opposed to adding the two as a number.
        **********************************************************/
        if!/^\d\d$/.test(this.month) ) )
        {
                this.month = '' this.month;
        }

        if!/^\d\d$/.test(this.day) ) )
        {
                this.day = '' this.day;
        }

        var arrayLocation = this.year + '' this.month + '' this.day;

        ifEvents[arrayLocation] )
        {
                var size = Events[arrayLocation].length;
                Events[arrayLocation][sizethis;
        else {
                Events[arrayLocationnew Array();
                Events[arrayLocation][0this;
        }
}


/**********************************************************
 CALENDER CONSTRUCTOR DEFINITION
  var <name1> = new CalendarMonth()        //--> grabs current month in current year
  var <name2> = new CalendarMonth(2004)    //--> grabs current month in year 2004
  var <name3> = new CalendarMonth(2001,01) //--> grabs january in 2001

  <name1>.changeDay(-1)      //--> moves the date to yesterday
  <name2>.changeDay(1)        //--> moves the date to tomorrow 2004

  <name1>.changeMonth(-1)      //--> moves month back one, to last month
  <name2>.changeMonth(1)      //--> moves to next month in the year 2004

  <name3>.changeYear(-1)      //--> moves to january 2000
  <name1>.changeYear(1)      //--> moves to this month next year

   <name1>.displaymonth();      //--> displays themonth
**********************************************************/
function CalendarMonth(year,month)
{
  /**********************************************************
   Get Calendar's Date (with corrections for Leap year and Y2k)
   Defaults to current month and day...
       **********************************************************/
  var now = new Date();        /// format :: Wed Dec 13 06:49:08 GMT-0800 (Pacific Standard Time) 2000
  this.month = now.getMonth()/// 0->11
  this.year = now.getYear();   /// # years from 1900
  this.isLeapYear = 0;       /// boolean set by program

  ifthis.year < 1000 /// if it gives less than 4 digits
  {
    if(this.year > 90/// if it's somewhere in the 1990's
    {
      this.year += 1900
    }
    else /// it's after 2000
    {
      this.year += 2000
    }
  }

  this.dayOfWeek = now.getDay();
  this.dayOfMonth = now.getDate();

  /**********************************************************
   From the current day of the week, we can determine what
   day of the week the 1st of the month is on (sun->sat).
   Not very straight-forward.
       **********************************************************/

  this.firstOfMonth = this.dayOfWeek - this.dayOfMonth % ) ) 1;
    ifthis.firstOfMonth < )
    {
      this.firstOfMonth += 7;
    }

  this.lastOfMonth = this.firstOfMonth + daysInMonth[this.month) ) 1;
    ifthis.lastOfMonth > )
    {
      this.lastOfMonth -= 7;
    }


  /**********************************************************
    if the user has specified a year or month or day
                   in the parameters, change to that date
       **********************************************************/
                ifyear)
                {
                        this.changeYearyear - this.year );
                        ifmonth )
                        {
                                this.changeMonth( (month-1this.month );
                        }
                }

}
/**********************************************************
 CALENDER METHOD DEFINITIONS
**********************************************************/

/**********************************************************
 <calendar>.debugInfo()
  Shows all basic object info for debug purposes
**********************************************************/
CalendarMonth.prototype.debugInfo = function()
{
        var debug = ' \';

        debug += '<br>\nYear = ' + this.year;
        debug += '<br>\n Month = ' + this.month;
        debug += '<br>\n Day of Month= ' + this.dayOfMonth;
        debug += '<br>\n Leap Year? ' + this.isLeapYear;
        debug += '<br>\n Today\'s Day of Week = ' + this.dayOfWeek;
        debug += '<br>\n First of Month = ' + this.firstOfMonth;
        debug += '<br>\n Last Of Month = ' + this.lastOfMonth;

        document.writeln(debug);

}

/**********************************************************
 <calendar>.correctForLeapYear()
  Sets the number of days in february correctly
**********************************************************/
CalendarMonth.prototype.correctForLeapYear = function()
{
  /**********************************************************
    Just some stupid rules I found somewhere.
    I think/hope they are right.
  **********************************************************/
  if(this.year%!= 0)
  {
    daysInMonth[128;
    this.isLeapYear = 0;
  }
  else if(this.year%400 == 0)
  {
    daysInMonth[129;
    this.isLeapYear = 1;
  }
  else if(this.year%100 == 0)
  {
    daysInMonth[128;
    this.isLeapYear = 0;
  }
  else
  {
    daysInMonth[129;
    this.isLeapYear = 1;
  }
}


/**********************************************************
 <calendar>.lastYear()
  Changes Year back by one.
  just calls changeMonth(-12)
**********************************************************/
CalendarMonth.prototype.lastYear = function()
{
  this.changeMonth(-12);
}

/**********************************************************
 <calendar>.nextYear()
  Changes Year forward by one.
  just calls changeMonth(12)
**********************************************************/
CalendarMonth.prototype.nextYear = function()
{
  this.changeMonth(12);
}

/**********************************************************
 <calendar>.changeYear(x)
  Changes current month by x months.
  Foreward for positive x.
  Backwards for negative X.
**********************************************************/
CalendarMonth.prototype.changeYear = function(x)
{
  /**********************************************************
   Just checkin for a correct function call
  **********************************************************/
  if)
  {
    /**********************************************************
            Call a movement function x times (regardless of sign)
    **********************************************************/
    for(var i=0; i < Math.abs(x); i++)
    {
      if(x<0)
      {
        this.lastYear();
      }
      else
      {
        this.nextYear();
      }
    }// for
  }// if
}



/**********************************************************
 <calendar>.lastMonth()
  Changes Month's info back by one.
  New info determined from current month's info.
**********************************************************/
CalendarMonth.prototype.lastMonth = function()
{
  this.month--;
  /**********************************************************
          We must take into account a possible year change
  **********************************************************/
  ifthis.month < )
  {
    this.month += 12;
    this.year--;
    this.correctForLeapYear();
  }

  /**********************************************************
    Again a kinda wierd determination of the first/last
    of the month. But it works
  **********************************************************/
  this.lastOfMonth = this.firstOfMonth-1;
    ifthis.lastOfMonth < )
    {
        this.lastOfMonth += 7;
    }

  this.firstOfMonth = this.lastOfMonth - daysInMonth[this.month) ) 1;
    ifthis.firstOfMonth > )
    {
      this.firstOfMonth -= 7;
    }

                this.dayOfWeek =  this.firstOfMonth + this.dayOfMonth % ) ) 1;
    ifthis.dayOfWeek < )
    {
      this.dayOfWeek += 7;
    }
                                  ifthis.dayOfWeek > )
    {
      this.dayOfWeek -= 7