HTML Component (HTML components) VII

Source: Internet
Author: User
Tags date array constant current time header variables return string

===calendar htc===


<HEAD>
? IMPORT namespace= "anyday" implementation= "DAY.HTC"/>
? IMPORT namespace= "Today" implementation= "TODAY.HTC"/>

<public:component tagname= "CALENDAR" >
<attach event= "Oncontentready" onevent= "Fninit ()"/>
</PUBLIC:COMPONENT>

<script language= "JavaScript" >
<!--
function Fninit () {
Defaults.viewlink = document;
}
-->
</SCRIPT>

<STYLE>
TD {
Background-color:tan;
width:50;
height:50;
}
</STYLE>
</HEAD>

<BODY>
<script language= "JavaScript" >
<!--

Copyright 1997--Tomer Shiran

Setcal ();

function Leapyear (year) {
if (year% 4 = 0) {//Basic rule
return true; is leap year
}
* Else//else not needed when statement are "return"
return false; Is isn't leap year
}

function getdays (month, year) {
Create array to hold number of on each month
var ar = new Array (12);
Ar[0] = 31; January
AR[1] = (leapyear (year))? 29:28; February
Ar[2] = 31; March
AR[3] = 30; April
Ar[4] = 31; May
AR[5] = 30; June
Ar[6] = 31; July
AR[7] = 31; August
AR[8] = 30; September
AR[9] = 31; October
AR[10] = 30; November
AR[11] = 31; December

Return number is in the specified month (parameter)
return Ar[month];
}

function Getmonthname (month) {
Create array to hold name of each month
var ar = new Array (12);
Ar[0] = "January";
AR[1] = "February";
AR[2] = "March";
AR[3] = "April";
AR[4] = "may";
AR[5] = "June";
AR[6] = "July";
AR[7] = "August";
AR[8] = "September";
AR[9] = "October";
AR[10] = "November";
AR[11] = "December";

Return name of Specified month (parameter)
return Ar[month];
}

function setcal () {
Standard Time Attributes
var now = new Date ();
var year = Now.getfullyear ();
var month = Now.getmonth ();
var monthname = getmonthname (month);
var date = Now.getdate ();
now = null;

Create instance of month, and extract on which it occurs
var firstdayinstance = new Date (year, month, 1);
var firstday = Firstdayinstance.getday ();
Firstdayinstance = null;

Number of days in current month
var days = getdays (month, year);

Call function to draw calendar
Drawcal (FirstDay + 1, days, date, monthname, year);
}

Function drawcal (FirstDay, lastdate, date, MonthName, year) {
//constant table settings
file://var headerheight = m/height of the table ' header cell
var border = 2;//3D Height of table ' s border
var cellspacing = 4;//width of table ' s border
var headercolor = "Midnightblue";//color of table ' s HEA Der
var headersize = "+3";/size of tables header font
var colwidth =//width of columns in table
Var d Aycellheight = 25; Height of cells containing days of the week
var daycolor = "Darkblue";//color of font representing week days
var cellheight = 40; Height of cells representing dates in the calendar
var todaycolor = "Red";//color specifying today's date in the Calendar
var timecolor = "Purple";//color of font representing current time

Create basic table structure
var text = ""; Initialize accumulative variable to empty string
Text + + ' <table border= ' + BORDER + ' cellspacing= ' + cellspacing + ' > '; Table settings
Text + ' <th colspan=7 height= ' + + ' > '; CREATE TABLE header cell
Text + + ' <font color= ' + headercolor + ' "size= ' + headersize + ' > '; Set font for table header
Text + MonthName + ' + year;
Text + ' </FONT> '; Close table header ' s font settings
Text + ' </TH> '; Close Header Cell

Variables to hold constant settings
var opencol = ' <td width= ' + colwidth + ' height= ' + daycellheight + ' > ';
Opencol + = ' <font color= ' + daycolor + ' > ';
var closecol = ' </FONT></TD> ';

Create array of abbreviated day names
var weekday = new Array (7);
Weekday[0] = "Sun";
WEEKDAY[1] = "Mon";
WEEKDAY[2] = "Tues";
WEEKDAY[3] = "Wed";
WEEKDAY[4] = "Thu";
WEEKDAY[5] = "Fri";
WEEKDAY[6] = "Sat";

Create a row of table to set column width and specify week day
Text + "<tr align=" center "valign=" Center ">";
for (var daynum = 0; daynum < 7; ++daynum) {
Text + Opencol + weekday[daynum] + closecol;
}
Text + ' </TR> ';

Declaration and initialization of two variables to help with tables
var dayofmonth = 1;
var Curcell = 1;

for (var row = 1; row <= Math.ceil (lastdate + firstDay-1)/7); ++row) {
Text + ' <tr align= ' right ' valign= ' top ' > ';
for (var col = 1; Col <= 7; ++col) {
if ((Curcell < firstday) | | (DayOfMonth > Lastdate)) {
Text + ' <TD></TD> ';
curcell++
} else {
if (DayOfMonth = date) {//Current cell represents today ' s date
Text + ' <td><today:day value= ' + dayofmonth + ' ></TODAY:DAY></TD> ';
} else {
Text + ' <td><anyday:day value= ' + dayofmonth + ' ></ANYDAY:DAY></TD> ';
}
dayofmonth++;
}
}
Text + ' </TR> ';
}

Close all basic Table tags
Text + ' </TABLE> ';
Text + ' </CENTER> ';

Print accumulative HTML string
document.write (text);
}

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



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.