Introducing Scriptlets

A bitmapped anchor that behaves as shown above is conceptually quite a new object. From HTML's point of view, however, it could also be considered as an extended tag. Whatever you think, however, such a component is something that plugs into your pages and makes them richer.

If you think it over, it's easy to enumerate feasible properties and methods for it. For example, we can surely have some picture attributes, and a Boolean flag to let us know whether the anchor is enabled or disabled. In addition, we could endow it with the capability of changing state programmatically, passing from normal to highlighted and pressed. Finally, we can require it to fire specific events (say, at every state change) or reflect the DHTML standard events like

onmousedown
,
onmouseup
, and the like.

Believe it or not, what we've just outlined is exactly the public interface of a scriptlet component.

What does "Scriptlet" mean?

What is a scriptlet? A scriptlet is what the word itself suggests. That is, it's a small software component made up of script code, written in a variety of languages. It exploits the facilities of the DHTML object model (as our bitmapped anchor does) in order to set up meaningful behavior. They are not like Windows DLLs or more generic libraries, which are collections of exported and reusable functions. Scriptlets, however, are a collection of

<SCRIPT>
tags hosted in the same HTML page.

In our bitmapped anchor example, to specify such a behavior we added an

<IMG>
tag and a bunch of related
<SCRIPT>
tags. If we want to move that component elsewhere, then we need to export just the images and scripts. So what about writing a new HTML page with this content only and attempting to host it elsewhere?

Reusability the Scriptlets way

Scriptlets reusability is obtained in the same way as the reusability of ActiveX controls. That is, you write a component with a specific behavior and host it wherever such a behavior is needed. A component has properties and methods to be driven and events to notify changes in its state. To write a scriptlet, you write a traditional HTML page and add all the script code that is required. To embed, and actually reuse, a scriptlet component, you simply refer to that HTML page in almost the same way as you refer to an ActiveX control. The scriptlet's source code is hidden in the page. So you don't need to rewrite it and can now reuse that functionality in a comfortable object-based fashion.

Scriptlets are mostly Web solutions, authored with HTML and script, that content providers can use as a component in their Web applications. It's an innovative technology that also enables Web authors to use the languages they already know to create powerful cross-platform Web components.

Scriptlets are all this, but with the introduction of Active Desktop and with the upcoming Windows 98, they can also be employed to arrange small desktop and Intranet-based goodies and utilities, as we demonstrate in Chapter 8. For example, you can customize a shared folder writing a DHTML layer that hides the underlying data.

© 1997 by Wrox Press. All rights reserved.