spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column64


HTML Components

Developer News
Mandrake Linux Founder Back, Virtually
Amazon: We're a Technology Company
Sun Expands MySQL With Closed Source

The ANYDAY and TODAY HTCs

The ANYDAY Component is defined in day.htc. This component is an encapsulation of the calendar cells. The component name is determined by the XML namespace definition on the first line:

<HTML XMLNS:ANYDAY>

As oppose to calendar.htc, you have only one namespace definition. The reason is that we don't call any HTCs from this page. This is a "leaf" HTC. The custom tag we define here is DAY. We define its behavior as well now. HTML Component definition is actually a custom tag's behavior definition. The behavior includes one property and one event:

<PUBLIC:COMPONENT tagName="DAY">
  <PROPERTY NAME="value"></PROPERTY>
  <ATTACH EVENT="oncontentready" ONEVENT="fnInit()"<>/ATTACH>
</PUBLIC:COMPONENT>

Notice the event oncontentready. It occurs when the file day.htc completes its loading when imported by its caller, calendar.htc. The event handler is fnInit(). Let's look at it:

function fnInit() {
  document.body.innerHTML = element.value;
  document.body.className = "clsDay";
  defaults.viewLink = document;
  element.appointments = "";
  element.date = element.value;
}

The fnInit() demonstrates some very important HTC's concepts. The first line assign element.value to the innerHTML property of the cell. An HTML Component is always encapsulated in an object named element. The property value is defined above in the PROPERTY tag. As a reminder, the actual value is passed in the caller, calendar.htc:

text += '<TD><ANYDAY:DAY value=' + dayOfMonth + '></ANYDAY:DAY></TD>'

The style of the cell is assigned on the second line:

document.body.className = "clsDay";

Style class clsDay is defined elsewhere on the page:

<STYLE>
  .clsDay {
    width:50;
    height:50;
    background-color:lightyellow;
    align:center;
    text-align:right;
  }
</STYLE>

Notice that days are colored light yellow in the calendar. It proves that the HTC dominates any format assignments made by the caller, calendar.htc.

The third line of fnInit() sets the viewLink property of the defaults object. The viewLink property is the cornerstone of HTML Components. It allows an HTC's document (day.htc) to be viewed in another HTML document (calendar.htc). Here is the assignment of viewLink:

defaults.viewLink = document;

Notice that what you need to link is the whole document object. The last two lines of fnInit() initializes two internal properties that we'll explain later:

element.appointments = "";
element.date = element.value;

Besides displaying itself, the DAY HTML Component reacts to mouse clicks:

<BODY onclick="fnShowAppts()">

When a day is clicked, the user is prompted to add his or her appointments for the day, or to modify the existing ones:


function fnShowAppts() {
  newAppointments = prompt("Add your appointment:",
    element.appointments);
  if (newAppointments != null) element.appointments = newAppointments;
  document.body.innerHTML = '<FONT COLOR="red">' + element.date +
    '</FONT>'  + "<BR>" + '<FONT SIZE="1">' + element.appointments +
    '</FONT>';
}

The input mechanism here is quite primitive. The user needs to put newline tags (<BR>) between appointments, or else they will all be in a single line. The final innerHTML is a concatenation between the day's date (element.date) and the appointments (element.appointments).

The TODAY HTML Component (today.htc) is very similar to the ANYDAY Component (day.htc). The only difference is that background-color in the STYLE block is pink instead of ligthyellow, and the font color is blue instead of red. Observe in the calendar that the current day is colored pink with blue font.

Next: Listings of Calendar's top page

http://www.internet.com

Produced by Yehuda Shiran and Tomer Shiran

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Whitepapers and eBooks

Intel Whitepaper: Comparing Two- and Four-Socket Platforms for Server Virtualization
IBM Solutions Brief: Go Green With IBM System xTM And Intel
HP eBook: Simplifying SQL Server Management
IBM Contest: Are You the Next Superstar? Join the "Search for the XML Superstar" Contest to Find Out
Microsoft PDF: Top 10 Reasons to Move to Server Virtualization with Hyper-V
Microsoft PDF: Six Reasons Why Microsoft's Hyper-V Will Overtake Vmware
Microsoft Step-by-Step Guide: Hyper-V and Failover Clustering
Intel PDF: Quad-Core Impacts More Than the Data Center
Intel PDF: Virtualization Delivers Data Center Efficiency
Go Parallel Article: PDC 2008 in Review
Microsoft PDF: Top 11 Reasons to Upgrade to Windows Server 2008
Avaya Article: Communication-Enabled Mashups: Empowering Both Business Owners and IT
Intel Whitepaper: Building a Real-World Model to Assess Virtualization Platforms
  PDF: Intel Centrino Duo Processor Technology with Intel Core2 Duo Processor
Microsoft Article: Build and Run Virtual Machines with Hyper-V Server 2008
Go Parallel Article: Q&A with a TBB Junkie
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
IBM eBook: The Pros and Cons of Outsourcing
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
HP eBook: Guide to Storage Networking
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Crucial Triples Up With New Three-Channel DDR3 Kits · Meet the Finalists: Excellence in Technology Awards · Tealeaf Offers Insight to Mobile Customer Behavior


Created: July 3, 2000
Revised: July 3, 2000

URL: http://www.webreference.com/js/column64/8.html