|
Comments
Did you read today's front page stories & breaking news?
SYS-CON.TV
|
Features Developing Intelligent Web Applications With AJAX (Part 2)
A peek into modern technologies for browser-based applications
Nov. 25, 2005 01:00 PM
Custom Tag Definition To define a custom CHECKBOX tag, we create a file checkbox.htc as in the following snippet where the first line sets the tag name of the component:
<PUBLIC:COMPONENT NAME="cbx" tagName="CHECKBOX">
Custom Tag Use Case
<HTML xmlns:myns> Please notice how custom CHECKBOX has been mapped to a nondefault namespace "myns" in the opening HTML tag. The IMPORT instruction performs a synchronous load of the HTC into the browser's memory and also instructs the browser how to perform name resolution for the appropriate namespace (HTC to namespace association can be many-to-one).
Constructor of the Custom Tag <ATTACH EVENT="oncontentready" HANDLER="constructor" /> The logic of constructor() is simple: concatenate a regular HTML checkbox and HTML label in the order dependent on the value of property labelonleft (see property definition below):
function constructor() {
Defining Custom Tag Properties <PROPERTY NAME="labelonleft" VALUE="true"/> Please note that this property does not contain getter and/or setter methods. Properties onValue and offValue that provide the mapping of the checkbox status into a business value domain also don't need getters and setters:
<PROPERTY NAME="onValue" VALUE="true"/> However, property checked is defined with both getter and setter: <PROPERTY NAME="checked" GET="getChecked" PUT="putChecked" /> Accordingly, we have definitions for both methods in the <SCRIPT> section. As you can see, setter putChecked(), which is triggered every time checked is modified, sets the value property to one of two variants: onValue or OffValue. Please note that putChecked() will get triggered not only by the script on the checkbox-hosting page, but also by any assignment to checked done inside this very checkbox.htc.
var _value;
Defining Events for the Custom Tag Method putValue() has a couple of points of interest. First, it can be called during the parsing on the CHECKBOX tag, as long as the HTML value attribute is specified. That's why we have a separate logic branch for not constructed objects, to differentiate the process of construction from a reaction to a user click. Second, we illustrate here the creation and processing of the custom event onItemChanging, which allows the application to cancel (block) the action. Please note that both clicking as well as programmatic assignment to the value can get cancelled this way.
Event Canceling
cbx_1::onItemChanging() { If the event is not cancelled, putValue() sets the internal, plain HTML checkbox's checked property as per the current value: if that is equal to onValue, the internal checkbox will get checked; if it is equal to offValue (there is no third option), unchecked (the full listing is presented in Listing 2).
HTML Internals of the CHECKBOX
<LABEL for=cb_{uniqueID}>Show Details:</LABEL> where uniqueID is a unique (within a page) string literal generated by IE, which identifies the instance of the HTC. Reader Feedback: Page 1 of 1
Your Feedback
Latest Cloud Developer Stories
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week
Breaking Cloud Computing News
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||